1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

YOLOv5自前のデータを水増しして学習する

Posted at

YOLOv5で自前のデータを学習させる時に精度向上のために
簡単に水増しできる手法を紹介します

pytorchでAlbumentationsを用いて行います
主に屋外での物体検知で使う水増し処理について紹介します

###環境
・YOLOv5 https://github.com/ultralytics/yolov5

###更新履歴
2021年10月 初版

##このシリーズのゴール
学習データの水増し処理を簡単に行えるようになる

##1.準備
YOLOv5で自前データを用いてで学習できること
[colabにて学習方法が紹介されています]
(https://colab.research.google.com/github/roboflow-ai/yolov5-custom-training-tutorial/blob/main/yolov5-custom-training.ipynb#scrollTo=g8dHcni6CJYt)

さらに
データ拡張用ライブラリを導入します

pip install albumentations

##2.実装

yolov5/utils/augmentations.py
を確認します

albumentationsが導入されていれば
自動的に実行されます

            self.transform = A.Compose([
                A.Blur(p=0.01),
                A.MedianBlur(p=0.01),
                A.ToGray(p=0.01),
                A.CLAHE(p=0.01),
                A.RandomBrightnessContrast(p=0.0),
                A.RandomGamma(p=0.0),
                A.ImageCompression(quality_lower=75, p=0.0)],
                bbox_params=A.BboxParams(format='yolo', label_fields=['class_labels']))

RandomSnow
RandomRain
RandomFog
RandomSunFlare
RandomShadow
などを必要に応じて追加します

            self.transform = A.Compose([
                A.Blur(p=0.01),
                A.MedianBlur(p=0.01),
                A.ToGray(p=0.01),
                A.CLAHE(p=0.01),
                A.RandomBrightnessContrast(p=0.0),
                A.RandomGamma(p=0.0),
                A.ImageCompression(quality_lower=75, p=0.0)
                A.RandomSnow(p=0.2)
                A.RandomRain(p=0.2)],
                bbox_params=A.BboxParams(format='yolo', label_fields=['class_labels']))

yolov5/data/hyps/ にも
水増しがあるためかぶらないように注意

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.9  # 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.1  # image mixup (probability)
copy_paste: 0.1  # segment copy-paste (probability)
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?