μ½˜ν…μΈ λ‘œ κ±΄λ„ˆλ›°κΈ°

ν•˜μ΄νΌνŒŒλΌλ―Έν„° 진화

이 κ°€μ΄λ“œμ—μ„œλŠ” YOLOv5 πŸš€μ— λŒ€ν•œ ν•˜μ΄νΌνŒŒλΌλ―Έν„° 진화에 λŒ€ν•΄ μ„€λͺ…ν•©λ‹ˆλ‹€. ν•˜μ΄νΌνŒŒλΌλ―Έν„° μ§„ν™”λŠ” μ΅œμ ν™”λ₯Ό μœ„ν•΄ μœ μ „ μ•Œκ³ λ¦¬μ¦˜ (GA)을 μ‚¬μš©ν•˜λŠ” ν•˜μ΄νΌνŒŒλΌλ―Έν„° μ΅œμ ν™” λ°©λ²•μž…λ‹ˆλ‹€.

ML의 ν•˜μ΄νΌνŒŒλΌλ―Έν„°λŠ” ν•™μŠ΅μ˜ λ‹€μ–‘ν•œ 츑면을 μ œμ–΄ν•˜λ©°, 이에 λŒ€ν•œ 졜적의 값을 μ°ΎλŠ” 것은 μ–΄λ €μš΄ 일이 될 수 μžˆμŠ΅λ‹ˆλ‹€. κ·Έλ¦¬λ“œ 검색과 같은 κΈ°μ‘΄ 방법은 1) 높은 μ°¨μ›μ˜ 검색 곡간 2) 차원 κ°„μ˜ μ•Œλ €μ§€μ§€ μ•Šμ€ 상관관계 3) 각 μ§€μ μ—μ„œ 적합성을 ν‰κ°€ν•˜λŠ” 데 λ§Žμ€ λΉ„μš©μ΄ λ“€κΈ° λ•Œλ¬Έμ— ν•˜μ΄νΌνŒŒλΌλ―Έν„° 검색에 μ ν•©ν•œ ν›„λ³΄λ‘œ GAκ°€ 적합할 수 μžˆμŠ΅λ‹ˆλ‹€.

μ‹œμž‘ν•˜κΈ° 전에

리포지토리λ₯Ό λ³΅μ œν•˜κ³  μš”κ΅¬μ‚¬ν•­.txtλ₯Ό μ„€μΉ˜ν•©λ‹ˆλ‹€. Python>=3.8.0 ν™˜κ²½μ„ ν¬ν•¨ν•˜μ—¬ PyTorch>=1.8. λͺ¨λΈ 및 데이터 μ„ΈνŠΈλŠ” μ΅œμ‹  YOLOv5 λ¦΄λ¦¬μŠ€μ—μ„œ μžλ™μœΌλ‘œ λ‹€μš΄λ‘œλ“œλ©λ‹ˆλ‹€.

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

1. ν•˜μ΄νΌνŒŒλΌλ―Έν„° μ΄ˆκΈ°ν™”

YOLOv5 μ—λŠ” λ‹€μ–‘ν•œ νŠΈλ ˆμ΄λ‹ 섀정에 μ‚¬μš©λ˜λŠ” μ•½ 30개의 ν•˜μ΄νΌνŒŒλΌλ―Έν„°κ°€ μžˆμŠ΅λ‹ˆλ‹€. μ΄λŸ¬ν•œ ν•˜μ΄νΌνŒŒλΌλ―Έν„°λŠ” λ‹€μŒμ—μ„œ μ •μ˜λ©λ‹ˆλ‹€. *.yaml νŒŒμΌμ— μžˆλŠ” /data/hyps 디렉토리에 μ €μž₯ν•©λ‹ˆλ‹€. 초기 좔츑이 μ •ν™•ν• μˆ˜λ‘ μ΅œμ’… κ²°κ³Όκ°€ 더 μ’‹μœΌλ―€λ‘œ μ§„ν™”ν•˜κΈ° 전에 μ΄λŸ¬ν•œ 값을 μ μ ˆν•˜κ²Œ μ΄ˆκΈ°ν™”ν•˜λŠ” 것이 μ€‘μš”ν•©λ‹ˆλ‹€. ν™•μ‹€ν•˜μ§€ μ•Šμ€ 경우 YOLOv5 COCO κ΅μœ‘μ— μ΅œμ ν™”λœ 기본값을 μ²˜μŒλΆ€ν„° μ‚¬μš©ν•˜λ©΄ λ©λ‹ˆλ‹€.

# YOLOv5 πŸš€ by Ultralytics, AGPL-3.0 license
# Hyperparameters for low-augmentation COCO training from scratch
# python train.py --batch 64 --cfg yolov5n6.yaml --weights '' --data coco.yaml --img 640 --epochs 300 --linear
# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials

lr0: 0.01  # initial learning rate (SGD=1E-2, Adam=1E-3)
lrf: 0.01  # 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)

2. ν”ΌνŠΈλ‹ˆμŠ€ μ •μ˜

ν”ΌνŠΈλ‹ˆμŠ€λŠ” μš°λ¦¬κ°€ κ·ΉλŒ€ν™”ν•˜κ³ μž ν•˜λŠ” κ°€μΉ˜μž…λ‹ˆλ‹€. YOLOv5 μ—μ„œλŠ” κΈ°λ³Έ ν”ΌνŠΈλ‹ˆμŠ€ ν•¨μˆ˜λ₯Ό λ©”νŠΈλ¦­μ˜ κ°€μ€‘μΉ˜ μ‘°ν•©μœΌλ‘œ μ •μ˜ν•©λ‹ˆλ‹€: mAP@0.5 λŠ” 무게의 10%λ₯Ό μ°¨μ§€ν•˜κ³  mAP@0.5:0.95 κ°€ λ‚˜λ¨Έμ§€ 90%λ₯Ό μ°¨μ§€ν•˜λ©° 정밀도 P 및 리콜 R λΆ€μž¬. μ μ ˆν•˜λ‹€κ³  νŒλ‹¨λ˜λŠ” 경우 이λ₯Ό μ‘°μ •ν•˜κ±°λ‚˜ utils/metrics.py의 κΈ°λ³Έ 적합성 μ •μ˜λ₯Ό μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€(ꢌμž₯).

def fitness(x):
    # Model fitness as a weighted combination of metrics
    w = [0.0, 0.0, 0.1, 0.9]  # weights for [P, R, mAP@0.5, mAP@0.5:0.95]
    return (x[:, :4] * w).sum(1)

3. 진화

μ§„ν™”λŠ” κ°œμ„ ν•˜κ³ μž ν•˜λŠ” κΈ°λ³Έ μ‹œλ‚˜λ¦¬μ˜€μ— λŒ€ν•΄ μˆ˜ν–‰λ©λ‹ˆλ‹€. 이 예제의 κΈ°λ³Έ μ‹œλ‚˜λ¦¬μ˜€λŠ” 사전 ν•™μŠ΅λœ YOLOv5λ₯Ό μ‚¬μš©ν•˜μ—¬ 10νšŒμ— 걸쳐 COCO128을 λ―Έμ„Έ μ‘°μ •ν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€. κΈ°λ³Έ μ‹œλ‚˜λ¦¬μ˜€ ν›ˆλ ¨ λͺ…령은 λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€:

python train.py --epochs 10 --data coco128.yaml --weights yolov5s.pt --cache

ν•˜μ΄νΌνŒŒλΌλ―Έν„°λ₯Ό λ°œμ „μ‹œν‚€λ €λ©΄ 이 μ‹œλ‚˜λ¦¬μ˜€μ— νŠΉμ •ν•œμ— μ •μ˜λœ 초기 κ°’μ—μ„œ μ‹œμž‘ν•˜μ—¬ μ„Ήμ…˜ 1.에 μ •μ˜λœ 체λ ₯을 κ·ΉλŒ€ν™”ν•˜κ³  μ„Ήμ…˜ 2.μΆ”κ°€ --evolve:

# Single-GPU
python train.py --epochs 10 --data coco128.yaml --weights yolov5s.pt --cache --evolve

# Multi-GPU
for i in 0 1 2 3 4 5 6 7; do
  sleep $(expr 30 \* $i) &&  # 30-second delay (optional)
  echo 'Starting GPU '$i'...' &&
  nohup python train.py --epochs 10 --data coco128.yaml --weights yolov5s.pt --cache --device $i --evolve > evolve_gpu_$i.log &
done

# Multi-GPU bash-while (not recommended)
for i in 0 1 2 3 4 5 6 7; do
  sleep $(expr 30 \* $i) &&  # 30-second delay (optional)
  echo 'Starting GPU '$i'...' &&
  "$(while true; do nohup python train.py... --device $i --evolve 1 > evolve_gpu_$i.log; done)" &
done

κΈ°λ³Έ 진화 섀정은 κΈ°λ³Έ μ‹œλ‚˜λ¦¬μ˜€λ₯Ό 300회, 즉 300μ„ΈλŒ€ λ™μ•ˆ μ‹€ν–‰ν•©λ‹ˆλ‹€. μ„ΈλŒ€λ₯Ό μˆ˜μ •ν•˜λ €λ©΄ --evolve 인수, 즉 python train.py --evolve 1000.

μ£Όμš” μœ μ „μž μ—°μ‚°μžλŠ” λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€. ν¬λ‘œμŠ€μ˜€λ²„ 그리고 λŒμ—°λ³€μ΄. 이 μž‘μ—…μ—μ„œλŠ” 80%의 ν™•λ₯ κ³Ό 0.04의 λΆ„μ‚°μœΌλ‘œ λŒμ—°λ³€μ΄κ°€ μ‚¬μš©λ˜μ–΄ 이전 μ„ΈλŒ€μ˜ λͺ¨λ“  λΆ€λͺ¨ 쀑 κ°€μž₯ μš°μˆ˜ν•œ λΆ€λͺ¨μ˜ 쑰합을 기반으둜 μƒˆλ‘œμš΄ μžμ†μ„ μƒμ„±ν•©λ‹ˆλ‹€. κ²°κ³ΌλŠ” λ‹€μŒ μœ„μΉ˜μ— κΈ°λ‘λ©λ‹ˆλ‹€. runs/evolve/exp/evolve.csv그리고 κ°€μž₯ 체λ ₯이 쒋은 μžμ†μ€ 맀 μ„ΈλŒ€λ§ˆλ‹€ λ‹€μŒκ³Ό 같이 μ €μž₯λ©λ‹ˆλ‹€. runs/evolve/hyp_evolved.yaml:

# YOLOv5 Hyperparameter Evolution Results
# Best generation: 287
# Last generation: 300
#    metrics/precision,       metrics/recall,      metrics/mAP_0.5, metrics/mAP_0.5:0.95,         val/box_loss,         val/obj_loss,         val/cls_loss
#              0.54634,              0.55625,              0.58201,              0.33665,             0.056451,             0.042892,             0.013441

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)

μ΅œμƒμ˜ κ²°κ³Όλ₯Ό μœ„ν•΄ μ΅œμ†Œ 300μ„ΈλŒ€ μ΄μƒμ˜ 진화λ₯Ό ꢌμž₯ν•©λ‹ˆλ‹€. κΈ°λ³Έ μ‹œλ‚˜λ¦¬μ˜€λ₯Ό 수백 번 ν›ˆλ ¨ν•˜κΈ° λ•Œλ¬Έμ— 일반적으둜 μ§„ν™”μ—λŠ” λΉ„μš©κ³Ό μ‹œκ°„μ΄ 많이 μ†Œμš”λ˜λ©°, 수백 λ˜λŠ” 수천 개의 GPU μ‹œκ°„μ΄ ν•„μš”ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

4. μ‹œκ°ν™”

evolve.csv λŠ” λ‹€μŒκ³Ό 같이 ν”Œλ‘―λ©λ‹ˆλ‹€. evolve.png by utils.plots.plot_evolve() 진화가 μ™„λ£Œλœ ν›„ ν•˜μ΄νΌνŒŒλΌλ―Έν„°λ‹Ή ν•˜λ‚˜μ˜ ν•˜μœ„ ν”Œλ‘―μœΌλ‘œ 적합도(yμΆ•) λŒ€ ν•˜μ΄νΌνŒŒλΌλ―Έν„° κ°’(xμΆ•)을 ν‘œμ‹œν•©λ‹ˆλ‹€. λ…Έλž€μƒ‰μ€ 더 높은 농도λ₯Ό λ‚˜νƒ€λƒ…λ‹ˆλ‹€. 수직 λΆ„ν¬λŠ” λ§€κ°œλ³€μˆ˜κ°€ λΉ„ν™œμ„±ν™”λ˜μ–΄ 변이가 μΌμ–΄λ‚˜μ§€ μ•ŠμŒμ„ λ‚˜νƒ€λƒ…λ‹ˆλ‹€. μ΄λŠ” μ‚¬μš©μžκ°€ meta λ”•μ…”λ„ˆλ¦¬λ₯Ό μΆ”κ°€ν•  수 있으며, λ§€κ°œλ³€μˆ˜λ₯Ό μˆ˜μ •ν•˜κ³  μ§„ν™”ν•˜λŠ” 것을 λ°©μ§€ν•˜λŠ” 데 μœ μš©ν•©λ‹ˆλ‹€.

진화

지원 ν™˜κ²½

Ultralytics λŠ” λ°”λ‘œ μ‚¬μš©ν•  수 μžˆλŠ” λ‹€μ–‘ν•œ ν™˜κ²½μ„ μ œκ³΅ν•˜λ©°, 각 ν™˜κ²½μ—λŠ” CUDA, CUDNNκ³Ό 같은 ν•„μˆ˜ 쒅속성이 사전 μ„€μΉ˜λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€, Python및 PyTorch와 같은 ν•„μˆ˜ 쒅속 μš”μ†Œκ°€ 사전 μ„€μΉ˜λ˜μ–΄ μžˆμ–΄ ν”„λ‘œμ νŠΈλ₯Ό μ‹œμž‘ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

ν”„λ‘œμ νŠΈ μƒνƒœ

YOLOv5 CI

이 λ°°μ§€λŠ” λͺ¨λ“  YOLOv5 GitHub Actions 지속적 톡합(CI) ν…ŒμŠ€νŠΈκ°€ μ„±κ³΅μ μœΌλ‘œ ν†΅κ³Όλ˜μ—ˆμŒμ„ λ‚˜νƒ€λƒ…λ‹ˆλ‹€. μ΄λŸ¬ν•œ CI ν…ŒμŠ€νŠΈλŠ” ꡐ윑, 검증, μΆ”λ‘ , 내보내기 및 벀치마크 λ“± λ‹€μ–‘ν•œ μ£Όμš” μΈ‘λ©΄μ—μ„œ YOLOv5 의 κΈ°λŠ₯κ³Ό μ„±λŠ₯을 μ—„κ²©ν•˜κ²Œ ν™•μΈν•©λ‹ˆλ‹€. 24μ‹œκ°„λ§ˆλ‹€ 그리고 μƒˆλ‘œμš΄ 컀밋이 μžˆμ„ λ•Œλ§ˆλ‹€ ν…ŒμŠ€νŠΈλ₯Ό μˆ˜ν–‰ν•˜μ—¬ macOS, Windows 및 Ubuntuμ—μ„œ μΌκ΄€λ˜κ³  μ•ˆμ •μ μΈ μž‘λ™μ„ 보μž₯ν•©λ‹ˆλ‹€.



생성 2023-11-12, μ—…λ°μ΄νŠΈ 2023-12-03
μž‘μ„±μž: glenn-jocher (2)

λŒ“κΈ€