๋ชจ๋ธ ์์๋ธ
๐ This guide explains how to use YOLOv5 ๐ model ensembling during testing and inference for improved mAP and Recall.
์ถ์ฒ: https: //en.wikipedia.org/wiki/Ensemble_learning:
Ensemble modeling is a process where multiple diverse models are created to predict an outcome, either by using many different modeling algorithms or using different training data sets. The ensemble model then aggregates the prediction of each base model and results in once final prediction for the unseen data. The motivation for using ensemble models is to reduce the generalization error of the prediction. As long as the base models are diverse and independent, the prediction error of the model decreases when the ensemble approach is used. The approach seeks the wisdom of crowds in making a prediction. Even though the ensemble model has multiple base models within the model, it acts and performs as a single model.
์์ํ๊ธฐ ์ ์
๋ฆฌํฌ์งํ ๋ฆฌ๋ฅผ ๋ณต์ ํ๊ณ ์๊ตฌ์ฌํญ.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
์ ์์ ์ผ๋ก ํ ์คํธ
์ด์
๋ธํ๊ธฐ ์ ์ ๋จ์ผ ๋ชจ๋ธ์ ๊ธฐ์ค ์ฑ๋ฅ์ ์ค์ ํ๊ณ ์ถ์ต๋๋ค. ์ด ๋ช
๋ น์ ์ด๋ฏธ์ง ํฌ๊ธฐ 640ํฝ์
์ COCO val2017์์ YOLOv5x๋ฅผ ํ
์คํธํฉ๋๋ค. yolov5x.pt
์ ๊ฐ์ฅ ํฌ๊ณ ์ ํํ ๋ชจ๋ธ์
๋๋ค. ๋ค๋ฅธ ์ต์
์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. yolov5s.pt
, yolov5m.pt
๊ทธ๋ฆฌ๊ณ yolov5l.pt
๋๋ ์ฌ์ฉ์ ์ง์ ๋ฐ์ดํฐ ์ธํธ ํ์ต์์ ์ป์ ์์ฒด ์ฒดํฌํฌ์ธํธ ./weights/best.pt
. ์ฌ์ฉ ๊ฐ๋ฅํ ๋ชจ๋ ๋ชจ๋ธ์ ๋ํ ์์ธํ ๋ด์ฉ์ README๋ฅผ ์ฐธ์กฐํ์ธ์. ํ
์ด๋ธ.
์ถ๋ ฅ:
val: data=./data/coco.yaml, weights=['yolov5x.pt'], batch_size=32, imgsz=640, conf_thres=0.001, iou_thres=0.65, task=val, device=, single_cls=False, augment=False, verbose=False, save_txt=False, save_hybrid=False, save_conf=False, save_json=True, project=runs/val, name=exp, exist_ok=False, half=True
YOLOv5 ๐ v5.0-267-g6a3ee7c torch 1.9.0+cu102 CUDA:0 (Tesla P100-PCIE-16GB, 16280.875MB)
Fusing layers...
Model Summary: 476 layers, 87730285 parameters, 0 gradients
val: Scanning '../datasets/coco/val2017' images and labels...4952 found, 48 missing, 0 empty, 0 corrupted: 100% 5000/5000 [00:01<00:00, 2846.03it/s]
val: New cache created: ../datasets/coco/val2017.cache
Class Images Labels P R mAP@.5 mAP@.5:.95: 100% 157/157 [02:30<00:00, 1.05it/s]
all 5000 36335 0.746 0.626 0.68 0.49
Speed: 0.1ms pre-process, 22.4ms inference, 1.4ms NMS per image at shape (32, 3, 640, 640) # <--- baseline speed
Evaluating pycocotools mAP... saving runs/val/exp/yolov5x_predictions.json...
...
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.504 # <--- baseline mAP
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.688
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.546
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.351
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.551
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.644
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.382
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.628
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.681 # <--- baseline mAR
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.524
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.735
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.826
์์๋ธ ํ ์คํธ
์ฌ์ ํ์ต๋ ์ฌ๋ฌ ๋ชจ๋ธ์ ํ
์คํธ ๋ฐ ์ถ๋ก ์์ ์ ์ถ๊ฐ ๋ชจ๋ธ์ ์ถ๊ฐํ์ฌ ํจ๊ป ์กฐํฉํ ์ ์์ต๋๋ค. --weights
์ธ์๋ฅผ ์ถ๊ฐํ ์ ์์ต๋๋ค. ์ด ์์์๋ ๋ ๋ชจ๋ธ์ ์์๋ธ์ ํจ๊ป ํ
์คํธํฉ๋๋ค:
- YOLOv5x
- YOLOv5l6
์ถ๋ ฅ:
val: data=./data/coco.yaml, weights=['yolov5x.pt', 'yolov5l6.pt'], batch_size=32, imgsz=640, conf_thres=0.001, iou_thres=0.6, task=val, device=, single_cls=False, augment=False, verbose=False, save_txt=False, save_hybrid=False, save_conf=False, save_json=True, project=runs/val, name=exp, exist_ok=False, half=True
YOLOv5 ๐ v5.0-267-g6a3ee7c torch 1.9.0+cu102 CUDA:0 (Tesla P100-PCIE-16GB, 16280.875MB)
Fusing layers...
Model Summary: 476 layers, 87730285 parameters, 0 gradients # Model 1
Fusing layers...
Model Summary: 501 layers, 77218620 parameters, 0 gradients # Model 2
Ensemble created with ['yolov5x.pt', 'yolov5l6.pt'] # Ensemble notice
val: Scanning '../datasets/coco/val2017.cache' images and labels... 4952 found, 48 missing, 0 empty, 0 corrupted: 100% 5000/5000 [00:00<00:00, 49695545.02it/s]
Class Images Labels P R mAP@.5 mAP@.5:.95: 100% 157/157 [03:58<00:00, 1.52s/it]
all 5000 36335 0.747 0.637 0.692 0.502
Speed: 0.1ms pre-process, 39.5ms inference, 2.0ms NMS per image at shape (32, 3, 640, 640) # <--- ensemble speed
Evaluating pycocotools mAP... saving runs/val/exp3/yolov5x_predictions.json...
...
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.515 # <--- ensemble mAP
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.699
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.557
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.356
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.563
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.668
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.387
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.638
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.689 # <--- ensemble mAR
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.526
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.743
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.844
์์๋ธ ์ถ๋ก
์ถ๊ฐ ๋ชจ๋ธ์ ์ถ๊ฐํฉ๋๋ค. --weights
์ธ์๋ฅผ ์ฌ์ฉํ์ฌ ์์๋ธ ์ถ๋ก ์ ์คํํฉ๋๋ค:
์ถ๋ ฅ:
YOLOv5 ๐ v5.0-267-g6a3ee7c torch 1.9.0+cu102 CUDA:0 (Tesla P100-PCIE-16GB, 16280.875MB)
Fusing layers...
Model Summary: 476 layers, 87730285 parameters, 0 gradients
Fusing layers...
Model Summary: 501 layers, 77218620 parameters, 0 gradients
Ensemble created with ['yolov5x.pt', 'yolov5l6.pt']
image 1/2 /content/yolov5/data/images/bus.jpg: 640x512 4 persons, 1 bus, 1 tie, Done. (0.063s)
image 2/2 /content/yolov5/data/images/zidane.jpg: 384x640 3 persons, 2 ties, Done. (0.056s)
Results saved to runs/detect/exp2
Done. (0.223s)
์ง์ ํ๊ฒฝ
Ultralytics ๋ ๋ฐ๋ก ์ฌ์ฉํ ์ ์๋ ๋ค์ํ ํ๊ฒฝ์ ์ ๊ณตํ๋ฉฐ, ๊ฐ ํ๊ฒฝ์๋ ๋ค์๊ณผ ๊ฐ์ ํ์ ์ข ์์ฑ์ด ์ฌ์ ์ค์น๋์ด ์์ต๋๋ค. CUDA, CUDNN, Python, ๋ฐ PyTorch์ ๊ฐ์ ํ์ ์ข ์ ์์๋ฅผ ์ค์นํ์ฌ ํ๋ก์ ํธ๋ฅผ ์์ํ ์ ์์ต๋๋ค.
- ๋ฌด๋ฃ GPU ๋ ธํธ๋ถ:
- Google Cloud: GCP ๋น ๋ฅธ ์์ ๊ฐ์ด๋
- Amazon: AWS ๋น ๋ฅธ ์์ ๊ฐ์ด๋
- Azure: AzureML ๋น ๋ฅธ ์์ ๊ฐ์ด๋
- Docker: Docker ๋น ๋ฅธ ์์ ๊ฐ์ด๋
ํ๋ก์ ํธ ์ํ
์ด ๋ฐฐ์ง๋ ๋ชจ๋ YOLOv5 GitHub Actions ์ง์์ ํตํฉ(CI) ํ ์คํธ๊ฐ ์ฑ๊ณต์ ์ผ๋ก ํต๊ณผ๋์์์ ๋ํ๋ ๋๋ค. ์ด๋ฌํ CI ํ ์คํธ๋ ๊ต์ก, ๊ฒ์ฆ, ์ถ๋ก , ๋ด๋ณด๋ด๊ธฐ ๋ฐ ๋ฒค์น๋งํฌ ๋ฑ ๋ค์ํ ์ฃผ์ ์ธก๋ฉด์์ YOLOv5 ์ ๊ธฐ๋ฅ๊ณผ ์ฑ๋ฅ์ ์๊ฒฉํ๊ฒ ํ์ธํฉ๋๋ค. 24์๊ฐ๋ง๋ค ๊ทธ๋ฆฌ๊ณ ์๋ก์ด ์ปค๋ฐ์ด ์์ ๋๋ง๋ค ํ ์คํธ๋ฅผ ์ํํ์ฌ macOS, Windows ๋ฐ Ubuntu์์ ์ผ๊ด๋๊ณ ์์ ์ ์ธ ์๋์ ๋ณด์ฅํฉ๋๋ค.