位置: IT常识 - 正文

yolov5使用知识蒸馏(yolov5l)

编辑:rootadmin
yolov5使用知识蒸馏

推荐整理分享yolov5使用知识蒸馏(yolov5l),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:yolov5讲解,yolov5作用,yolo 使用,yolov5m,yolov5l,yolov5m,yolov5的使用,yolov5的使用,内容如对您有帮助,希望把文章链接给更多的朋友!

提示:本文采用的蒸馏方式为 Distilling Object Detectors with Fine-grained Feature Imitation 这篇文章

文章目录前言一、Distilling Object Detectors with Fine-grained Feature Imitation 论文介绍1.创新点2.内容介绍1. Fine-Gained区域提取2. loss 损失值二、yolov5 添加知识蒸馏1.部分代码展示总结前言

提示:这里可以添加本文要记录的大概内容:

本文介绍的论文《Distilling Object Detectors with Fine-grained Feature Imitation》即是基于 Fine-grained Feature Imitation 技术的目标检测知识蒸馏方法。该方法将 Fine-grained Feature Imitation 应用于学生模型的中间层,以捕捉更丰富的特征信息。通过在训练过程中引入目标检测任务的监督信号,Fine-grained Feature Imitation 技术可以更好地保留复杂模型中的细节特征,从而提高了轻量级模型的性能。

提示:以下是本篇文章正文内容,下面案例可供参考

一、Distilling Object Detectors with Fine-grained Feature Imitation 论文介绍

示例:pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的。

1.创新点

Fine-grained Feature Imitation 技术可以概括为以下三个步骤:

yolov5使用知识蒸馏(yolov5l)

利用复杂模型的中间层作为特征提取器,并用它提取学生模型的中间层的特征。

利用 Fine-grained Feature Imitation 技术对特征进行蒸馏,使学生模型能够学习到更丰富的特征信息。

在训练过程中引入目标检测任务的监督信号,以更好地保留复杂模型中的细节特征。

其核心思想是 teacher 网络中需要传递给 student 网络的应该是有效信息,而非无效的 background 信息。

2.内容介绍1. Fine-Gained区域提取

上图中的红色和绿色边界框是在相应位置上的锚框。红色 anchor 表示与 gt 的边界框重叠最大,绿色 anchor 表示附近的物体样本。蒸馏时并不是对所有的anchor蒸馏,而是对gt框附近的anchor进行蒸馏,对于backbone输出的特征图,假设尺度为H X W, 网络中使用的anchor数量为K, 具体执行步骤如下:

对于给定的特征图,生成H X W X K 个anchor, 并计算与gt anchor的IOU值m,计算最大的IOU值 M = max(m), 引入参数阈值因子Ψ, 计算过滤阈值F = M x Ψ, 利用F进行IOU过滤,这里只保留大于F的部分,计算之后得到一个mask, 尺度为H X W.2. loss 损失值

损失函数部分由两块组成,一块为Fine-grained Feature Imitation 损失,另一块为目标检测的分类和回归损失,

论文中展示了实验的对比结果,原论文是基于Faster Rcnn算法进行蒸馏,因此本文选择基于yolov5算法进行蒸馏。

二、yolov5 添加知识蒸馏1.部分代码展示

调整gt anchors转换为相对于原图的位置

def make_gt_boxes(gt_boxes, max_num_box, batch, img_size): new_gt_boxes = [] for i in range(batch): # 获取第i个batch的所有真实框 boxes = gt_boxes[gt_boxes[:, 0] == i] # 真实框的个数 num_boxes = boxes.size(0) if num_boxes < max_num_box: gt_boxes_padding = torch.zeros([max_num_box, gt_boxes.size(1)], dtype=torch.float) gt_boxes_padding[:num_boxes, :] = boxes else: gt_boxes_padding = boxes[:max_num_box] new_gt_boxes.append(gt_boxes_padding.unsqueeze(0)) new_gt_boxes = torch.cat(new_gt_boxes) # transfer [x, y, w, h] to [x1, y1, x2, y2] new_gt_boxes_aim = torch.zeros(size=new_gt_boxes.size()) new_gt_boxes_aim[:, :, 2] = (new_gt_boxes[:, :, 2] - 0.5 * new_gt_boxes[:, :, 4]) * img_size[1] new_gt_boxes_aim[:, :, 3] = (new_gt_boxes[:, :, 3] - 0.5 * new_gt_boxes[:, :, 5]) * img_size[0] new_gt_boxes_aim[:, :, 4] = (new_gt_boxes[:, :, 2] + 0.5 * new_gt_boxes[:, :, 4]) * img_size[1] new_gt_boxes_aim[:, :, 5] = (new_gt_boxes[:, :, 3] + 0.5 * new_gt_boxes[:, :, 5]) * img_size[0] return new_gt_boxes_aim

计算掩码 mask

def getMask(batch_size, gt_boxes, img_size, feat, anchors, max_num_box, device): # [b, K, 4] gt_boxes = make_gt_boxes(gt_boxes, max_num_box, batch_size, img_size) # 原图相对于当前特征图的步长 feat_stride = img_size[0] / feat.size(2) anchors = torch.from_numpy(generate_anchors(feat_stride, anchors)) feat = feat.cpu() height, width = feat.size(2), feat.size(3) feat_height, feat_width = feat.size(2), feat.size(3) shift_x = np.arange(0, feat_width) * feat_stride shift_y = np.arange(0, feat_height) * feat_stride shift_x, shift_y = np.meshgrid(shift_x, shift_y) shifts = torch.from_numpy(np.vstack((shift_x.ravel(), shift_y.ravel(), shift_x.ravel(), shift_y.ravel())).transpose()) shifts = shifts.contiguous().type_as(feat).float() # num of anchors [3] A = anchors.size(0) K = shifts.size(0) anchors = anchors.type_as(gt_boxes) # all_anchors [K, A, 4] all_anchors = anchors.view(1, A, 4) + shifts.view(K, 1, 4) all_anchors = all_anchors.view(K * A, 4) # compute iou [all_anchors, gt_boxes] IOU_map = bbox_overlaps_batch(all_anchors, gt_boxes, img_size).view(batch_size, height, width, A, gt_boxes.shape[1]) mask_batch = [] for i in range(batch_size): max_iou, _ = torch.max(IOU_map[i].view(height * width * A, gt_boxes.shape[1]), dim=0) mask_per_im = torch.zeros([height, width], dtype=torch.int64).to(device) for k in range(gt_boxes.shape[1]): if torch.sum(gt_boxes[i][k]) == 0: break max_iou_per_gt = max_iou[k] * 0.5 mask_per_gt = torch.sum(IOU_map[i][:, :, :, k] > max_iou_per_gt, dim=2) mask_per_im += mask_per_gt.to(device) mask_batch.append(mask_per_im) return mask_batch

计算imitation损失

def compute_mask_loss(mask_batch, student_feature, teacher_feature, imitation_loss_weight): mask_list = [] for mask in mask_batch: mask = (mask > 0).float().unsqueeze(0) mask_list.append(mask) # [batch, height, widt mask_batch = torch.stack(mask_list, dim=0) norms = mask_batch.sum() * 2 mask_batch_s = mask_batch.unsqueeze(4) no = student_feature.size(-1) bs, na, height, width, _ = mask_batch_s.shape mask_batch_no = mask_batch_s.expand((bs, na, height, width, no)) sup_loss = (torch.pow(teacher_feature - student_feature, 2) * mask_batch_no).sum() / norms sup_loss = sup_loss * imitation_loss_weight return sup_loss总结

完整代码请查看GitHub,麻烦动动小手点亮一下star https://github.com/xing-bing

本文链接地址:https://www.jiuchutong.com/zhishi/298957.html 转载请保留说明!

上一篇:CSS实现文字颜色渐变(css实现文字颜色渐变)

下一篇:解决云服务器远程登录SSH显示-bash-4.2问题和解决方法(云服务器远程端口)

  • 增值税发票网上勾选平台
  • 会计利润和应纳税所得额的区别和联系
  • 进口关税计算公式 案例
  • 主管税务机关是否参与清算
  • 劳务外包合同需要交税吗
  • 将自产产品用于在建工程要交增值税
  • 开发支出在资产负债表是怎
  • 库存商品暂估后怎么结转
  • 预算基数是什么
  • 食堂买菜未取得消费凭证
  • 加盖发票专用章的是
  • 哪些项目容易漏缴个人所得税
  • 暂估出库是什么意思
  • 健身房开业前买的瑜伽垫怎么做账?
  • 正确解读《非居民金融账户涉税信息尽职调查管理办法》
  • 工程款发票备注栏必须填写吗
  • 交通卡定额发票购买
  • 分期消费的实际收益
  • 直接收款涉及增值税吗
  • 加班工资是否属劳动关系
  • 向股东分配股利会影响所有者权益吗
  • 怎么写会计凭证
  • 补缴配套费
  • 本年利润贷方为正数
  • windows无法验证此设备数字签名
  • 税务发票上的账户是对公账户吗
  • 免征增值税的范围有
  • 企业无偿提供劳务
  • 增值税专用发票上注明的价款含税吗
  • python字符串操作作业
  • php特性包括
  • 长期股权投资资本化
  • framework架构
  • 结转已销售产品的实际生产成本会计分录
  • php面向对象和面向过程
  • php检测网站是否正常打开
  • 股东垫付款怎么处理
  • 尚融资本
  • 银行承兑汇票应由在承兑银行开立存款账户的存款人签发
  • 购买承兑的收益会计分录
  • 小规模纳税人当月应交增值税怎么算
  • sql随机数字
  • 以前年度损益调整结转到本年利润吗
  • mysql数据库恢复方式
  • 待报解预算收入是什么
  • 企业增值税包含哪些税项及税率
  • 应收账款资金占用费怎么算
  • 跨年取得的发票金额大于暂估金额
  • 银行抵债资产如何更快处置
  • 银行汇票转入银行分录
  • 金税三期升级功能2020
  • 航天信息服务费发票哪里打印
  • 一般纳税人怎样开3个点的专票
  • 知识产权服务费可以计入研发费用吗
  • 车船税怎么抵扣进项
  • 从增值税抵扣进什么科目
  • 事业单位职工福利费使用范围和标准
  • 外购固定资产
  • 在sql server中关于数据库的说法正确的是
  • SQL Transcation的一些总结分享
  • windows2003r2安装教程
  • windowsxp显卡驱动在哪个位置
  • 优盘安装系统
  • vrvprotect.sys
  • 思科用户模式命令
  • centos7 swap大小设多少
  • nb3是什么文件
  • 怎么使用linux
  • Win10应用程序无法正常启动0xc000007b
  • linux vmware命令行
  • opengl矩形
  • unity 3d书籍
  • 如何改变this指向
  • 用python播放音乐
  • js实现自动定时功能
  • unity ctrl
  • python文件处理方法
  • javascript简明教程
  • 冲红和红冲的区别
  • 粤泰股份公司
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设