yolov5模型集成
在你開(kāi)始前
克隆這個(gè) repo 并安裝requirements.txt依賴項(xiàng),包括Python>=3.8和PyTorch>=1.7。
git clone https://github.com/ultralytics/yolov5 # clone repo
cd yolov5
pip install -r requirements.txt # install requirements.txt
正常測(cè)試
在集成之前,我們要建立單個(gè)模型的基線性能。此命令在 COCO val2017 上以 640 像素的圖像大小測(cè)試 YOLOv5x。yolov5x.pt是可用的最大和最準(zhǔn)確的模型。其他選項(xiàng)是yolov5s.pt, yolov5m.ptand yolov5l.pt, 或者您擁有訓(xùn)練自定義數(shù)據(jù)集的檢查點(diǎn)./weights/best.pt。有關(guān)所有可用模型的詳細(xì)信息,請(qǐng)參閱我們的自述文件表。
$ python test.py --weights yolov5x.pt --data coco.yaml --img 640
輸出:
Namespace(augment=False, batch_size=32, conf_thres=0.001, data='./data/coco.yaml', device='', img_size=640, iou_thres=0.65, save_json=True, save_txt=False, single_cls=False, task='val', verbose=False, weights=['yolov5x.pt'])
Using CUDA device0 _CudaDeviceProperties(name='Tesla P100-PCIE-16GB', total_memory=16280MB)
Fusing layers... Model Summary: 284 layers, 8.89222e+07 parameters, 0 gradients
Scanning labels ../coco/labels/val2017.cache (4952 found, 0 missing, 48 empty, 0 duplicate, for 5000 images): 5000it [00:00, 17761.74it/s]
Class Images Targets P R [email protected] [email protected]:.95: 100% 157/157 [02:34<00:00, 1.02it/s]
all 5e+03 3.63e+04 0.409 0.754 0.669 0.476
Speed: 23.6/1.6/25.2 ms inference/NMS/total per 640x640 image at batch-size 32
COCO mAP with pycocotools... saving detections_val2017__results.json...
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.492 < ---------- baseline mAP
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.676
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.534
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.318
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.541
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.633
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.376
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.616
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.670
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.493
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.723
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.812
集成測(cè)試
通過(guò)簡(jiǎn)單地將額外的模型附加到--weights任何現(xiàn)有 test.py 或 detect.py 命令中的參數(shù),可以在測(cè)試和推理時(shí)將多個(gè)預(yù)訓(xùn)練模型集成在一起。這個(gè)例子測(cè)試了 2 個(gè)模型的集合:- YOLOv5x - YOLOv5l
$ python test.py --weights yolov5x.pt yolov5l.pt --data coco.yaml --img 640
輸出:
Namespace(augment=False, batch_size=32, conf_thres=0.001, data='./data/coco.yaml', device='', img_size=640, iou_thres=0.65, save_json=True, save_txt=False, single_cls=False, task='val', verbose=False, weights=['yolov5x.pt', 'yolov5l.pt'])
Using CUDA device0 _CudaDeviceProperties(name='Tesla P100-PCIE-16GB', total_memory=16280MB)
Fusing layers... Model Summary: 284 layers, 8.89222e+07 parameters, 0 gradients # Model 1
Fusing layers... Model Summary: 236 layers, 4.77901e+07 parameters, 0 gradients # Model 2
Ensemble created with ['yolov5x.pt', 'yolov5l.pt'] # Ensemble Notice
Scanning labels ../coco/labels/val2017.cache (4952 found, 0 missing, 48 empty, 0 duplicate, for 5000 images): 5000it [00:00, 17883.26it/s]
Class Images Targets P R [email protected] [email protected]:.95: 100% 157/157 [03:42<00:00, 1.42s/it]
all 5e+03 3.63e+04 0.402 0.764 0.677 0.48
Speed: 37.5/1.4/38.9 ms inference/NMS/total per 640x640 image at batch-size 32
COCO mAP with pycocotools... saving detections_val2017__results.json...
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.496 < ---------- improved mAP
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.684
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.538
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.323
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.548
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.633
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.377
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.615
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.670
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.495
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.723
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.815
集成推理
將額外的模型附加到--weights參數(shù)以運(yùn)行集成推理:
$ python detect.py --weights yolov5x.pt yolov5l.pt --img 640 --source ./inference/images/
輸出:
Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.25, device='', img_size=640, iou_thres=0.45, output='inference/output', save_txt=False, source='./inference/images/', update=False, view_img=False, weights=['yolov5x.pt', 'yolov5l.pt'])
Using CUDA device0 _CudaDeviceProperties(name='Tesla P100-PCIE-16GB', total_memory=16280MB)
Fusing layers... Model Summary: 284 layers, 8.89222e+07 parameters, 0 gradients # Model 1
Fusing layers... Model Summary: 236 layers, 4.77901e+07 parameters, 0 gradients # Model 2
Ensemble created with ['yolov5x.pt', 'yolov5l.pt'] # Ensemble Notice
image 1/2 inference/images/bus.jpg: 640x512 4 persons, 1 bicycles, 1 buss, Done. (0.073s)
image 2/2 inference/images/zidane.jpg: 384x640 3 persons, 3 ties, Done. (0.063s)
Results saved to inference/output
Done. (0.319s)

評(píng)論
圖片
表情
