yolov5模型集成
在你开始前
克隆这个 repo 并安装requirements.txt依赖项,包括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
正常测试
在集成之前,我们要建立单个模型的基线性能。此命令在 COCO val2017 上以 640 像素的图像大小测试 YOLOv5x。yolov5x.pt
是可用的最大和最准确的模型。其他选项是yolov5s.pt
, yolov5m.pt
and yolov5l.pt
, 或者您拥有训练自定义数据集的检查点./weights/best.pt
。有关所有可用模型的详细信息,请参阅我们的自述文件表。
$ 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 mAP@.5 mAP@.5:.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
集成测试
通过简单地将额外的模型附加到--weights
任何现有 test.py 或 detect.py 命令中的参数,可以在测试和推理时将多个预训练模型集成在一起。这个例子测试了 2 个模型的集合:- 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 mAP@.5 mAP@.5:.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
参数以运行集成推理:
$ 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)
评论