测试
内容
测试¶
import torch
model_name = 'yolov5m'
image_size = 640
batch_size = 16
epochs = 10
device = '0' if torch.cuda.is_available() else 'cpu'
saved_model_name = 'best.pt'
# for test
confidence_threshold = 0.25 # Threshold of object inference
iou_threshold = 0.45 # Threshold of remove overlapping boxes
device
'0'
!python yolov5/detect.py --weights submission/best.pt \
--source datasets/images/test --img-size 640 \
--conf-thres 0.6 --iou-thres 0.6 --device 0
detect: weights=['submission/best.pt'], source=datasets/images/test, data=yolov5/data/coco128.yaml, imgsz=[640, 640], conf_thres=0.6, iou_thres=0.6, max_det=1000, device=0, view_img=False, save_txt=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=yolov5/runs/detect, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False, dnn=False
YOLOv5 🚀 v6.0-192-g436ffc4 torch 1.10.1 CUDA:0 (NVIDIA GeForce RTX 2080 Ti, 11017MiB)
Fusing layers...
Model Summary: 290 layers, 20861016 parameters, 0 gradients, 48.0 GFLOPs
image 1/5 /home/znjs/xinet/ai/pytorch-book/docs/yolo/face-mask/datasets/images/test/maksssksksss17.png: 640x512 1 with_mask, Done. (0.034s)
image 2/5 /home/znjs/xinet/ai/pytorch-book/docs/yolo/face-mask/datasets/images/test/maksssksksss18.png: 448x640 2 with_masks, Done. (0.032s)
image 3/5 /home/znjs/xinet/ai/pytorch-book/docs/yolo/face-mask/datasets/images/test/maksssksksss581.png: 640x512 1 with_mask, Done. (0.022s)
image 4/5 /home/znjs/xinet/ai/pytorch-book/docs/yolo/face-mask/datasets/images/test/maksssksksss753.png: 448x640 6 with_masks, Done. (0.022s)
image 5/5 /home/znjs/xinet/ai/pytorch-book/docs/yolo/face-mask/datasets/images/test/maksssksksss76.png: 416x640 3 with_masks, Done. (0.032s)
Speed: 0.4ms pre-process, 28.1ms inference, 1.4ms NMS per image at shape (1, 3, 640, 640)
Results saved to yolov5/runs/detect/exp
!python yolov5/detect.py --weights yolov5/runs/train/exp/weights/best.pt \
--source datasets/images/test --img-size 640 \
--conf-thres 0.6 --iou-thres 0.6 --device 0
detect: weights=['yolov5/runs/train/exp/weights/best.pt'], source=datasets/images/test, data=yolov5/data/coco128.yaml, imgsz=[640, 640], conf_thres=0.6, iou_thres=0.6, max_det=1000, device=0, view_img=False, save_txt=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=yolov5/runs/detect, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False, dnn=False
YOLOv5 🚀 v6.0-192-g436ffc4 torch 1.10.1 CUDA:0 (NVIDIA GeForce RTX 2080 Ti, 11017MiB)
Fusing layers...
Model Summary: 213 layers, 7018216 parameters, 0 gradients, 15.8 GFLOPs
image 1/5 /home/znjs/xinet/ai/pytorch-book/docs/yolo/face-mask/datasets/images/test/maksssksksss17.png: 640x512 1 with_mask, Done. (0.027s)
image 2/5 /home/znjs/xinet/ai/pytorch-book/docs/yolo/face-mask/datasets/images/test/maksssksksss18.png: 448x640 2 with_masks, Done. (0.025s)
image 3/5 /home/znjs/xinet/ai/pytorch-book/docs/yolo/face-mask/datasets/images/test/maksssksksss581.png: 640x512 1 with_mask, Done. (0.017s)
image 4/5 /home/znjs/xinet/ai/pytorch-book/docs/yolo/face-mask/datasets/images/test/maksssksksss753.png: 448x640 6 with_masks, Done. (0.016s)
image 5/5 /home/znjs/xinet/ai/pytorch-book/docs/yolo/face-mask/datasets/images/test/maksssksksss76.png: 416x640 3 with_masks, Done. (0.025s)
Speed: 0.4ms pre-process, 21.8ms inference, 1.4ms NMS per image at shape (1, 3, 640, 640)
Results saved to yolov5/runs/detect/exp
!python yolov5/detect.py --weights yolov5/runs/train/exp2/weights/best.pt \
--source datasets/images/test --img-size 640 \
--conf-thres 0.6 --iou-thres 0.6 --device 0
detect: weights=['yolov5/runs/train/exp2/weights/best.pt'], source=datasets/images/test, data=yolov5/data/coco128.yaml, imgsz=[640, 640], conf_thres=0.6, iou_thres=0.6, max_det=1000, device=0, view_img=False, save_txt=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=yolov5/runs/detect, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False, dnn=False
YOLOv5 🚀 v6.0-192-g436ffc4 torch 1.10.1 CUDA:0 (NVIDIA GeForce RTX 2080 Ti, 11017MiB)
Fusing layers...
Model Summary: 367 layers, 46119048 parameters, 0 gradients, 107.8 GFLOPs
image 1/5 /home/znjs/xinet/ai/pytorch-book/docs/yolo/face-mask/datasets/images/test/maksssksksss17.png: 640x512 1 with_mask, Done. (0.039s)
image 2/5 /home/znjs/xinet/ai/pytorch-book/docs/yolo/face-mask/datasets/images/test/maksssksksss18.png: 448x640 2 with_masks, Done. (0.041s)
image 3/5 /home/znjs/xinet/ai/pytorch-book/docs/yolo/face-mask/datasets/images/test/maksssksksss581.png: 640x512 1 with_mask, Done. (0.029s)
image 4/5 /home/znjs/xinet/ai/pytorch-book/docs/yolo/face-mask/datasets/images/test/maksssksksss753.png: 448x640 5 with_masks, Done. (0.029s)
image 5/5 /home/znjs/xinet/ai/pytorch-book/docs/yolo/face-mask/datasets/images/test/maksssksksss76.png: 416x640 3 with_masks, Done. (0.038s)
Speed: 0.4ms pre-process, 35.1ms inference, 1.4ms NMS per image at shape (1, 3, 640, 640)
Results saved to yolov5/runs/detect/exp4
可视化¶
from pathlib import Path
submission_path = 'yolov5/runs/detect/exp/'
origin_path = 'datasets/images/val/'
predict_images = [file.as_posix() for file in Path(submission_path).glob('*.png')]
from IPython.display import Image
Image(predict_images[2])
Image(predict_images[4])