mAP@[.5:.95](someone denoted mAP@[.5,.95]) means average mAP over different IoU thresholds, from 0.5 to 0.95, step 0.05 (0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95).

hyp参数列表

lr0: 0.01  # initial learning rate (SGD=1E-2, Adam=1E-3)
lrf: 0.2  # final OneCycleLR learning rate (lr0 * lrf)
momentum: 0.937  # SGD momentum/Adam beta1
weight_decay: 0.0005  # optimizer weight decay 5e-4
warmup_epochs: 3.0  # warmup epochs (fractions ok)
warmup_momentum: 0.8  # warmup initial momentum
warmup_bias_lr: 0.1  # warmup initial bias lr
box: 0.05  # box loss gain
cls: 0.5  # cls loss gain
cls_pw: 1.0  # cls BCELoss positive_weight
obj: 1.0  # obj loss gain (scale with pixels)
obj_pw: 1.0  # obj BCELoss positive_weight
iou_t: 0.20  # IoU training threshold
anchor_t: 4.0  # anchor-multiple threshold
# anchors: 3  # anchors per output layer (0 to ignore)
fl_gamma: 0.0  # focal loss gamma (efficientDet default gamma=1.5)
============================分割线==================================================
hsv_h: 0.015  # image HSV-Hue augmentation (fraction)
hsv_s: 0.7  # image HSV-Saturation augmentation (fraction)
hsv_v: 0.4  # image HSV-Value augmentation (fraction)
degrees: 0.0  # image rotation (+/- deg)
translate: 0.1  # image translation (+/- fraction)
scale: 0.5  # image scale (+/- gain)
shear: 0.0  # image shear (+/- deg)
perspective: 0.0  # image perspective (+/- fraction), range 0-0.001
flipud: 0.0  # image flip up-down (probability)
fliplr: 0.5  # image flip left-right (probability)
mosaic: 1.0  # image mosaic (probability)
mixup: 0.0  # image mixup (probability)
copy_paste: 0.0  # segment copy-paste (probability)

其中hsv以下属于数据增强的内容,基本都在datasets.py这个文件中,新的版本调整到augmentations.py文件并增加了copy paste,说明对此越来越重视了。 对照参考B站的up主BAI Yong绘制的网络结构图

  • 首先loadimage, 把image resize成按照长边原图像比例,defualt = 640
def load_image(self, index):# loads 1 image from dataset, returns img, original hw, resized hwimg = self.imgs[index]if img is None:  # not cachedpath = self.img_files[index]img = cv2.imread(path)  # BGRassert img is not None, 'Image Not Found ' + pathh0, w0 = img.shape[:2]  # orig hwr = self.img_size / max(h0, w0)  # ratioif r != 1:  # if sizes are not equalimg = cv2.resize(img, (int(w0 * r), int(h0 * r)),interpolation=cv2.INTER_AREA if r < 1 and not self.augment else cv2.INTER_LINEAR)return img, (h0, w0), img.shape[:2]  # img, hw_original, hw_resizedelse:return self.imgs[index], self.img_hw0[index], self.img_hw[index]  # img, hw_original, hw_resized
  • 然后进行letterbox填充
    参考https://blog.csdn.net/ChuiGeDaQiQiu/article/details/113048124
def letterbox(img, new_shape=(640, 640), color=(114, 114, 114), auto=True, scaleFill=False, scaleup=True, stride=32):# Resize and pad image while meeting stride-multiple constraintsshape = img.shape[:2]  # current shape [height, width]if isinstance(new_shape, int):new_shape = (new_shape, new_shape)# Scale ratio (new / old)r = min(new_shape[0] / shape[0], new_shape[1] / shape[1])if not scaleup:  # only scale down, do not scale up (for better test mAP)r = min(r, 1.0)# Compute paddingratio = r, r  # width, height ratiosnew_unpad = int(round(shape[1] * r)), int(round(shape[0] * r))dw, dh = new_shape[1] - new_unpad[0], new_shape[0] - new_unpad[1]  # wh paddingif auto:  # minimum rectangledw, dh = np.mod(dw, stride), np.mod(dh, stride)  # wh paddingelif scaleFill:  # stretchdw, dh = 0.0, 0.0new_unpad = (new_shape[1], new_shape[0])ratio = new_shape[1] / shape[1], new_shape[0] / shape[0]  # width, height ratiosdw /= 2  # divide padding into 2 sidesdh /= 2if shape[::-1] != new_unpad:  # resizeimg = cv2.resize(img, new_unpad, interpolation=cv2.INTER_LINEAR)top, bottom = int(round(dh - 0.1)), int(round(dh + 0.1))left, right = int(round(dw - 0.1)), int(round(dw + 0.1))img = cv2.copyMakeBorder(img, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color)  # add borderreturn img, ratio, (dw, dh)
  • 然后随机是否进行mosaic 4张图拼接增强
    参考https://blog.csdn.net/weixin_44791964/article/details/105996954

  • 然后随机random_perspective,里面包含了degrees,translate,scale,shear,perspective因素

    # CenterC = np.eye(3)C[0, 2] = -img.shape[1] / 2  # x translation (pixels)C[1, 2] = -img.shape[0] / 2  # y translation (pixels)# PerspectiveP = np.eye(3)P[2, 0] = random.uniform(-perspective, perspective)  # x perspective (about y)P[2, 1] = random.uniform(-perspective, perspective)  # y perspective (about x)# Rotation and ScaleR = np.eye(3)a = random.uniform(-degrees, degrees)# a += random.choice([-180, -90, 0, 90])  # add 90deg rotations to small rotationss = random.uniform(1 - scale, 1 + scale)# s = 2 ** random.uniform(-scale, scale)R[:2] = cv2.getRotationMatrix2D(angle=a, center=(0, 0), scale=s)# ShearS = np.eye(3)S[0, 1] = math.tan(random.uniform(-shear, shear) * math.pi / 180)  # x shear (deg)S[1, 0] = math.tan(random.uniform(-shear, shear) * math.pi / 180)  # y shear (deg)# TranslationT = np.eye(3)T[0, 2] = random.uniform(0.5 - translate, 0.5 + translate) * width  # x translation (pixels)T[1, 2] = random.uniform(0.5 - translate, 0.5 + translate) * height  # y translation (pixels)# Combined rotation matrixM = T @ S @ R @ P @ C  # order of operations (right to left) is IMPORTANTif (border[0] != 0) or (border[1] != 0) or (M != np.eye(3)).any():  # image changedif perspective:img = cv2.warpPerspective(img, M, dsize=(width, height), borderValue=(114, 114, 114))else:  # affineimg = cv2.warpAffine(img, M[:2], dsize=(width, height), borderValue=(114, 114, 114))
  • 颜色随机
def augment_hsv(img, hgain=0.5, sgain=0.5, vgain=0.5):if hgain or sgain or vgain:r = np.random.uniform(-1, 1, 3) * [hgain, sgain, vgain] + 1  # random gainshue, sat, val = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HSV))dtype = img.dtype  # uint8x = np.arange(0, 256, dtype=r.dtype)lut_hue = ((x * r[0]) % 180).astype(dtype)lut_sat = np.clip(x * r[1], 0, 255).astype(dtype)lut_val = np.clip(x * r[2], 0, 255).astype(dtype)img_hsv = cv2.merge((cv2.LUT(hue, lut_hue), cv2.LUT(sat, lut_sat), cv2.LUT(val, lut_val)))cv2.cvtColor(img_hsv, cv2.COLOR_HSV2BGR, dst=img)  # no return needed
  • mixup
def mixup(im, labels, im2, labels2):# Applies MixUp augmentation https://arxiv.org/pdf/1710.09412.pdfr = np.random.beta(32.0, 32.0)  # mixup ratio, alpha=beta=32.0im = (im * r + im2 * (1 - r)).astype(np.uint8)labels = np.concatenate((labels, labels2), 0)return im, labels
  • copy_paste
def copy_paste(im, labels, segments, p=0.5):# Implement Copy-Paste augmentation https://arxiv.org/abs/2012.07177, labels as nx5 np.array(cls, xyxy)n = len(segments)if p and n:h, w, c = im.shape  # height, width, channelsim_new = np.zeros(im.shape, np.uint8)for j in random.sample(range(n), k=round(p * n)):l, s = labels[j], segments[j]box = w - l[3], l[2], w - l[1], l[4]ioa = bbox_ioa(box, labels[:, 1:5])  # intersection over areaif (ioa < 0.30).all():  # allow 30% obscuration of existing labelslabels = np.concatenate((labels, [[l[0], *box]]), 0)segments.append(np.concatenate((w - s[:, 0:1], s[:, 1:2]), 1))cv2.drawContours(im_new, [segments[j].astype(np.int32)], -1, (255, 255, 255), cv2.FILLED)result = cv2.bitwise_and(src1=im, src2=im_new)result = cv2.flip(result, 1)  # augment segments (flip left-right)i = result > 0  # pixels to replace# i[:, :] = result.max(2).reshape(h, w, 1)  # act over chim[i] = result[i]  # cv2.imwrite('debug.jpg', im)  # debugreturn im, labels, segments

题外

如果遇到_pickle.UnpicklingError: STACK_GLOBAL requires str问题,需要删除一下dataset中的缓存文件xxx.cache

Deep Learning的案例-YoloV5中的数据增强相关推荐

  1. 机器学习(Machine Learning)、深度学习(Deep Learning)、NLP面试中常考到的知识点和代码实现

    网址:https://github.com/NLP-LOVE/ML-NLP 此项目是机器学习(Machine Learning).深度学习(Deep Learning).NLP面试中常考到的知识点和代 ...

  2. 【技术综述】深度学习中的数据增强(下)

    文章首发于微信公众号<有三AI> [技术综述]深度学习中的数据增强(下) 今天带来深度学习中的数据增强方法的下篇.我们将从以下几个方向入手.1,介绍一下什么是无监督的数据增强方法.2,简单 ...

  3. 总结 62 种在深度学习中的数据增强方式

    数据增强 数据增强通常是依赖从现有数据生成新的数据样本来人为地增加数据量的过程 这包括对数据进行不同方向的扰动处理 或使用深度学习模型在原始数据的潜在空间(latent space)中生成新数据点从而 ...

  4. NLP中的数据增强技术综述

    NLP数据增强技术 1. 词汇替换 Lexical Substitution 基于词典的替换 Thesaurus-based substitution 基于词向量的替换 Word-Embeddings ...

  5. 图机器学习中的数据增强技术

    文稿整理者:张琳 审稿&修改:赵通 本人总结来自圣母大学的博士生赵通在深蓝学院分享的"图机器学习中的数据增强技术"公开课.通过介绍图机器学习的概念,发展历程等,以及分享两篇 ...

  6. [综述类] 一文道尽深度学习中的数据增强方法(上)

    今天带来一次有关于深度学习中的数据增强方法的分享. 00 什么是数据增强 在深度学习项目中,寻找数据花费了相当多的时间.但在很多实际的项目中,我们难以找到充足的数据来完成任务. 为了要保证完美地完成项 ...

  7. 深度学习中的数据增强(上)

    feic非[技术综述] 深度学习中的数据增强(上) - 知乎 https://zhuanlan.zhihu.com/p/38345420 [技术综述]深度学习中的数据增强(下) - 知乎 https: ...

  8. gan 总结 数据增强_深度学习中的数据增强(下)

    言有三 毕业于中国科学院,计算机视觉方向从业者,有三工作室等创始人 编辑 | 言有三 今天带来深度学习中的数据增强方法的下篇.我们将从以下几个方向入手.1,介绍一下什么是无监督的数据增强方法.2,简单 ...

  9. 目标检测中的数据增强

    目标检测中的数据增强 技术标签: 深度学习 人工智能 一.图像遮挡 ①random erase 用随机值或训练集的平均像素替换图像区域. URL: https://arxiv.org/pdf/1708 ...

最新文章

  1. java 502错误,Spring Boot连接超时导致502错误的实战案例
  2. 查看mysql数据库的主机_MySQL查看或显示数据库(SHOW DATABASES语句)
  3. GCD 深入理解:第一部分
  4. 在WORD中插入带圈的数字的序号
  5. MEF初体验之九:部件生命周期
  6. [转]oracle分析函数Rank, Dense_rank, row_number
  7. 基础省选+NOI 第5部分 数论进阶
  8. linux系统io编程,Linux系统编程(1) —— 文件IO
  9. FineReport层式报表解决大数据集展示问题攻略
  10. 当我们写Controller时,VisitRefer注解是干什么的。
  11. !heap 和 _HEAP_ENTRY
  12. webstorm 配置sass 编译
  13. 统信UOS安装flash浏览器插件
  14. 解决从PDF复制文本到word的时候排版问题小技巧
  15. android 复制assets,Android复制Assets目录下的文件到指定目录
  16. html5出生年月日,出生年月日五行查询表
  17. jsp调试java_[求助]jsp+javaBean调试环境问题!
  18. Elang 学习笔记(二)
  19. 商务智能与数据挖掘 - 认识数据
  20. ShaderToy 转换到 Unity中(超级方便的一个工具)

热门文章

  1. 幼师资格证综合素质计算机知识点,幼儿教师资格证考试综合素质考点:文化常识...
  2. UEFI开发探索34 – Option ROM前传1
  3. 设置古腾堡专栏的风格
  4. 【Simulink】常用模块知识总结
  5. NSTimer 暂停 继续 停止 的方法
  6. 南京银行09中报初探
  7. 【Tools】推荐一些文件转换转换工具
  8. GUI_Type.h和GUI.h
  9. 工程项目管理与国际惯例接轨的几点思考(转)
  10. 什么是JVM、Java编译器和Java解释器