当前位置: 首页 > news >正文

目标检测从入门到精通——数据增强方法总结

以下是YOLO系列算法(从YOLOv1到YOLOv7)中使用的数据增强方法的总结,包括每种方法的数学原理、相关论文以及对应的YOLO版本。

YOLO系列数据增强方法总结

数据增强方法数学原理相关论文
图像缩放将输入图像缩放到固定大小(如448x448),以适应网络输入。Redmon et al., “You Only Look Once: Unified Real-Time Object Detection”
随机裁剪从原始图像中随机裁剪出部分区域进行训练,增加样本多样性。Redmon & Farhadi, “YOLO9000: Better, Faster, Stronger”
随机翻转对图像进行水平翻转,增强模型对目标方向变化的鲁棒性。Redmon & Farhadi, “YOLO9000: Better, Faster, Stronger”
颜色抖动随机调整图像的亮度、对比度、饱和度和色调,增加数据多样性。Redmon & Farhadi, “YOLO9000: Better, Faster, Stronger”
随机缩放在训练过程中随机缩放图像,以适应不同尺寸的目标。Redmon & Farhadi, “YOLOv3: An Incremental Improvement”
Mosaic将四张图像拼接在一起形成一张新图像,帮助模型学习不同目标之间的上下文关系。Bochkovskiy et al., “YOLOv4: Optimal Speed and Accuracy of Object Detection”
Mixup将两张图像及其标签按比例混合,生成新的训练样本。Zhang et al., “Mixup: Beyond Empirical Risk Minimization”
CutMix将一张图像的部分区域切割并替换为另一张图像的相应区域,生成新的训练样本。Yun et al., “CutMix: Regularization Strategy to Train Strong Classifiers with Localizable Features”
随机擦除在图像中随机选择一个区域并将其置为零或随机值,帮助模型学习到目标的局部特征。Devries & Taylor, “Cutout: Regularization Strategy to Train Strong Classifiers”
随机旋转将图像随机旋转一定角度,帮助模型学习到目标在不同角度下的特征。Bochkovskiy et al., “YOLOv4: Optimal Speed and Accuracy of Object Detection”
随机噪声向图像中添加高斯噪声,以增强模型的鲁棒性。Redmon & Farhadi, “YOLOv3: An Incremental Improvement”
1. 图像缩放
  • 适用版本:YOLOv1, YOLOv2, YOLOv3, YOLOv4, YOLOv5, YOLOv6, YOLOv7
  • 数学原理:将输入图像缩放到固定大小(如448x448),以适应网络输入。
  • 相关论文:Redmon et al., “You Only Look Once: Unified Real-Time Object Detection”
import cv2def resize_image(image, size=(640, 640)):return cv2.resize(image, size)
2. 随机裁剪
  • 适用版本:YOLOv2, YOLOv3, YOLOv4, YOLOv5, YOLOv6, YOLOv7
  • 数学原理:从原始图像中随机裁剪出部分区域进行训练,增加样本多样性。
  • 相关论文:Redmon & Farhadi, “YOLO9000: Better, Faster, Stronger”
import randomdef random_crop(image, crop_size=(640, 640)):h, w, _ = image.shapecrop_x = random.randint(0, w - crop_size[1])crop_y = random.randint(0, h - crop_size[0])return image[crop_y:crop_y + crop_size[0], crop_x:crop_x + crop_size[1]]
3. 随机翻转
  • 适用版本:YOLOv2, YOLOv3, YOLOv4, YOLOv5, YOLOv6, YOLOv7
  • 数学原理:对图像进行水平翻转,增强模型对目标方向变化的鲁棒性。
  • 相关论文:Redmon & Farhadi, “YOLO9000: Better, Faster, Stronger”
def random_flip(image):if random.random() > 0.5:return cv2.flip(image, 1)  # 水平翻转return image
4. 颜色抖动
  • 适用版本:YOLOv2, YOLOv3, YOLOv4, YOLOv5, YOLOv6, YOLOv7
  • 数学原理:随机调整图像的亮度、对比度、饱和度和色调,增加数据多样性。
  • 相关论文:Redmon & Farhadi, “YOLO9000: Better, Faster, Stronger”
from PIL import ImageEnhance, Imagedef color_jitter(image):image = Image.fromarray(image)brightness = ImageEnhance.Brightness(image).enhance(random.uniform(0.5, 1.5))contrast = ImageEnhance.Contrast(brightness).enhance(random.uniform(0.5, 1.5))saturation = ImageEnhance.Color(contrast).enhance(random.uniform(0.5, 1.5    return np.array(saturation)
5. 随机缩放
  • 适用版本:YOLOv3, YOLOv4, YOLOv5, YOLOv6, YOLOv7
  • 数学原理:在训练过程中随机缩放图像,以适应不同尺寸的目标。
  • 相关论文:Redmon & Farhadi, “YOLOv3: An Incremental Improvement”
6. Mosaic
  • 适用版本:YOLOv4, YOLOv5, YOLOv6, YOLOv7
  • 数学原理:将四张图像拼接在一起形成一张新图像,帮助模型学习不同目标之间的上下文关系。
  • 相关论文:Bochkovskiy et al., “YOLOv4: Optimal Speed and Accuracy of Object Detection”
def mosaic(images, size=(640, 640)):h, w = sizemosaic_image = np.zeros((h, w, 3), dtype=np.uint8)for i in range(2):for j in range(2):img = images[random.randint(0, len(images) - 1)]img = cv2.resize(img, (w // 2, h // 2))mosaic_image[i * (h // 2):(i + 1) * (h // 2), j * (w // 2):(j + 1) * (w // 2)] = imgreturn mosaic_image
7. Mixup
  • 适用版本:YOLOv3, YOLOv4, YOLOv5, YOLOv6, YOLOv7
  • 数学原理:将两张图像及其标签按比例混合,生成新的训练样本。公式为:
    x ~ = λ x 1 + ( 1 − λ ) x 2 \tilde{x} = \lambda x_1 + (1 - \lambda) x_2 x~=λx1+(1λ)x2
    y ~ = λ y 1 + ( 1 − λ ) y 2 \tilde{y} = \lambda y_1 + (1 - \lambda) y_2 y~=λy1+(1λ)y2
    其中, λ \lambda λ 是从Beta分布中采样的值。
  • 相关论文:Zhang et al., “Mixup: Beyond Empirical Risk Minimization”
def mixup(image1, image2, alpha=0.2):lambda_ = np.random.beta(alpha, alpha)mixed_image = lambda_ * image1 + (1 - lambda_) * image2return mixed_image.astype(np.uint8)
8. CutMix
  • 适用版本:YOLOv4, YOLOv5, YOLOv6, YOLOv7
  • 数学原理:将一张图像的部分区域切割并替换为另一张图像的相应区域,生成新的训练样本。公式为:
    x ~ = M ⊙ x 1 + ( 1 − M ) ⊙ x 2 \tilde{x} = M \odot x_1 + (1 - M) \odot x_2 x~=Mx1+(1M)x2
    y ~ = λ y 1 + ( 1 − λ ) y 2 \tilde{y} = \lambda y_1 + (1 - \lambda) y_2 y~=λy1+(1λ)y2
    其中, M M M 是二进制掩码, λ \lambda λ 是切割区域的面积与原始图像面积的比值。
  • 相关论文:Yun et al., “CutMix: Regularization Strategy to Train Strong Classifiers with Localizable Features”
def cutmix(image1, image2, alpha=0.2):h, w, _ = image1.shapelambda_ = np.random.beta(alpha, alpha)target_area = np.random.uniform(0.1 * h * w, 0.5 * h * w)aspect_ratio = np.random.uniform(0.5, 2.0)h_cut = int(np.sqrt(target_area * aspect_ratio))w_cut = int(np.sqrt(target_area / aspect_ratio))if h_cut > h:h_cut = hif w_cut > w:w_cut = wx = np.random.randint(0, h - h_cut)y = np.random.randint(0, w - w_cut)mixed_image = image1.copy()mixed_image[x:x + h_cut, y:y + w_cut] = image2[x:x + h_cut, y:y + w_cut]return mixed_image
9. 随机擦除
  • 适用版本:YOLOv4, YOLOv5, YOLOv6, YOLOv7
  • 数学原理:在图像中随机选择一个区域并将其置为零或随机值,帮助模型学习到目标的局部特征。公式为:
    Erase ( x ) = { 0 if  ( x , y ) in erased area x otherwise \text{Erase}(x) = \begin{cases} 0 & \text{if } (x,y) \text{ in erased area} \\ x & \text{otherwise} \end{cases} Erase(x)={0xif (x,y) in erased areaotherwise
  • 相关论文:Devries & Taylor, “Cutout: Regularization Strategy to Train Strong Classifiers”
def random_erasing(image, probability=0.5):if random.random() > probability:return imageh, w, _ = image.shapearea = h * wtarget_area = np.random.randint(0.02 * area, 0.33 * area)aspect_ratio = np.random.uniform(0.3, 3.3)h_erased = int(np.sqrt(target_area * aspect_ratio))w_erased = int(np.sqrt(target_area / aspect_ratio))if h_erased > h:h_erased = hif w_erased > w:w_erased = wx = np.random.randint(0, h - h_erased)y = np.random.randint(0, w - w_erased)image[x:x + h_erased, y:y + w_erased, :] = 0  # 或者随机值return image
10. 随机旋转
  • 适用版本:YOLOv5, YOLOv6, YOLOv7
  • 数学原理:将图像随机旋转一定角度,帮助模型学习到目标在不同角度下的特征。旋转矩阵为:
    R ( θ ) = [ cos ⁡ ( θ ) − sin ⁡ ( θ ) sin ⁡ ( θ ) cos ⁡ ( θ ) ] R(\theta) = \begin{bmatrix} \cos(\theta) & -\sin(\theta) \\ \sin(\theta) & \cos(\theta) \end{bmatrix} R(θ)=[cos(θ)sin(θ)sin(θ)cos(θ)]
  • 相关论文:Bochkovskiy et al., “YOLOv4: Optimal Speed and Accuracy of Object Detection”
def random_rotate(image, angle_range=(-30, 30)):angle = random.uniform(angle_range[0], angle_range[1])h, w = image.shape[:2]M = cv2.getRotationMatrix2D((w // 2, h // 2), angle, 1.0)return cv2.warpAffine(image, M, (w, h))
11. 随机噪声
  • 适用版本:YOLOv4, YOLOv5, YOLOv6, YOLOv7
  • 数学原理:向图像中添加高斯噪声,以增强模型的鲁棒性。高斯噪声的公式为:
    I ′ ( x , y ) = I ( x , y ) + N ( 0 , σ 2 ) I'(x,y) = I(x,y) + N(0, \sigma^2) I(x,y)=I(x,y)+N(0,σ2)
    其中, I I I 是原始图像, N ( 0 , σ 2 ) N(0, \sigma^2) N(0,σ2) 是高斯噪声。
  • 相关论文:Redmon & Farhadi, “YOLOv3: An Incremental Improvement”
def add_gaussian_noise(image, mean=0, var=0.1):sigma = var**0.5gauss = np.random.normal(mean, sigma, image.shape)noisy_image = np.clip(image + gauss, 0, 255).astype(np.uint8)return noisy_image

YOLO系列算法在不同版本中逐步引入了多种数据增强方法,从最初的简单缩放和翻转,到后来的Mixup、CutMix等复杂方法。这些数据增强技术不仅提高了模型的性能,还增强了其对不同场景和条件的适应能力。随着YOLO算法的不断发展,数据增强方法也在不断演进,为目标检测任务提供了更强大的支持。

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 使用vue2+axios+chart.js画折线图 ,出现 RangeError: Maximum call stack size exceeded 错误
  • 远程访问电脑共享文件
  • 一文说清什么是数据仓库
  • 灌区信息化建设的主要内容
  • 视频监控基础学习
  • GaN挑战Si价格底线?英飞凌推出全球首个12英寸GaN晶圆技术
  • 使用程序方式获取与处理MySQL表数据
  • [Unity Demo]从零开始制作空洞骑士Hollow Knight第二集:通过InControl插件实现绑定玩家输入以及制作小骑士移动空闲动画
  • Spring Cloud之二 微服务注册
  • JS中判断字符串中是否包含指定字符
  • 代码随想录刷题day32丨动态规划理论基础,509. 斐波那契数, 70. 爬楼梯, 746. 使用最小花费爬楼梯
  • Failed building wheel for opencv-python-headless
  • 林草湿地址、导出echart为word
  • Xcode 16 RC (16A242) 发布下载,正式版下周公布
  • Spring Boot 中关闭 Actuator 端点
  • 【162天】黑马程序员27天视频学习笔记【Day02-上】
  • angular组件开发
  • Java知识点总结(JavaIO-打印流)
  • Linux快速复制或删除大量小文件
  • MaxCompute访问TableStore(OTS) 数据
  • Netty 4.1 源代码学习:线程模型
  • nginx 负载服务器优化
  • nodejs:开发并发布一个nodejs包
  • use Google search engine
  • 从零开始的webpack生活-0x009:FilesLoader装载文件
  • 技术发展面试
  • 将 Measurements 和 Units 应用到物理学
  • 理清楚Vue的结构
  • 罗辑思维在全链路压测方面的实践和工作笔记
  • 十年未变!安全,谁之责?(下)
  • 数据仓库的几种建模方法
  • 我的zsh配置, 2019最新方案
  • 协程
  • FaaS 的简单实践
  • ​LeetCode解法汇总2808. 使循环数组所有元素相等的最少秒数
  • # 数仓建模:如何构建主题宽表模型?
  • #快捷键# 大学四年我常用的软件快捷键大全,教你成为电脑高手!!
  • #我与Java虚拟机的故事#连载02:“小蓝”陪伴的日日夜夜
  • #我与Java虚拟机的故事#连载14:挑战高薪面试必看
  • (1)bark-ml
  • (libusb) usb口自动刷新
  • (二)c52学习之旅-简单了解单片机
  • (六)DockerCompose安装与配置
  • (论文阅读40-45)图像描述1
  • (切换多语言)vantUI+vue-i18n进行国际化配置及新增没有的语言包
  • (淘宝无限适配)手机端rem布局详解(转载非原创)
  • (一)spring cloud微服务分布式云架构 - Spring Cloud简介
  • (原創) 如何動態建立二維陣列(多維陣列)? (.NET) (C#)
  • (转)自己动手搭建Nginx+memcache+xdebug+php运行环境绿色版 For windows版
  • .Net 8.0 新的变化
  • .NET连接数据库方式
  • .NET中winform传递参数至Url并获得返回值或文件
  • [ vulhub漏洞复现篇 ] Grafana任意文件读取漏洞CVE-2021-43798
  • []使用 Tortoise SVN 创建 Externals 外部引用目录
  • [1]从概念到实践:电商智能助手在AI Agent技术驱动下的落地实战案例深度剖析(AI Agent技术打造个性化、智能化的用户助手)