YOLO5的GitHub地址:
https://github.com/ultralytics/yolov5
选择部署的平台是极链AI云平台
优势:价格便宜,按实际使用时间扣费,适合学生进行科研探索;使用灵活,即用即停;选择较多,可以选择不同的Pytorch、Python、CUDA版本。
官网:https://cloud.videojj.com
部署
部署的环境要求:
Python>=3.6.0 is required with all requirements.txt installed including PyTorch>=1.7
安装过程:
cd /opt # 这一步可以省略,可以安装在自己想要安装的地方
git clone https://github.com/ultralytics/yolov5
cd yolov5
pip install -r requirements.txt
安装完之后,yolov5文件夹下的目录树为:
root@60ed0d8d61d98f582e7fb46b:/opt/yolov5# tree
.
├── CONTRIBUTING.md
├── data
│ ├── Argoverse_HD.yaml
│ ├── coco128.yaml
│ ├── coco.yaml
│ ├── GlobalWheat2020.yaml
│ ├── hyps
│ │ ├── hyp.finetune_objects365.yaml
│ │ ├── hyp.finetune.yaml
│ │ ├── hyp.scratch-p6.yaml
│ │ └── hyp.scratch.yaml
│ ├── images
│ │ ├── bus.jpg
│ │ └── zidane.jpg
│ ├── Objects365.yaml
│ ├── scripts
│ │ ├── download_weights.sh
│ │ ├── get_coco128.sh
│ │ └── get_coco.sh
│ ├── SKU-110K.yaml
│ ├── VisDrone.yaml
│ ├── VOC.yaml
│ └── xView.yaml
├── detect.py
├── Dockerfile
├── export.py
├── hubconf.py
├── LICENSE
├── models
│ ├── common.py
│ ├── experimental.py
│ ├── hub
│ │ ├── anchors.yaml
│ │ ├── yolov3-spp.yaml
│ │ ├── yolov3-tiny.yaml
│ │ ├── yolov3.yaml
│ │ ├── yolov5-fpn.yaml
│ │ ├── yolov5l6.yaml
│ │ ├── yolov5m6.yaml
│ │ ├── yolov5-p2.yaml
│ │ ├── yolov5-p6.yaml
│ │ ├── yolov5-p7.yaml
│ │ ├── yolov5-panet.yaml
│ │ ├── yolov5s6.yaml
│ │ ├── yolov5s-transformer.yaml
│ │ └── yolov5x6.yaml
│ ├── __init__.py
│ ├── yolo.py
│ ├── yolov5l.yaml
│ ├── yolov5m.yaml
│ ├── yolov5s.yaml
│ └── yolov5x.yaml
├── README.md
├── requirements.txt
├── train.py
├── tutorial.ipynb
├── utils
│ ├── activations.py
│ ├── augmentations.py
│ ├── autoanchor.py
│ ├── aws
│ │ ├── __init__.py
│ │ ├── mime.sh
│ │ ├── resume.py
│ │ └── userdata.sh
│ ├── datasets.py
│ ├── flask_rest_api
│ │ ├── example_request.py
│ │ ├── README.md
│ │ └── restapi.py
│ ├── general.py
│ ├── google_app_engine
│ │ ├── additional_requirements.txt
│ │ ├── app.yaml
│ │ └── Dockerfile
│ ├── google_utils.py
│ ├── __init__.py
│ ├── loss.py
│ ├── metrics.py
│ ├── plots.py
│ ├── torch_utils.py
│ └── wandb_logging
│ ├── __init__.py
│ ├── log_dataset.py
│ ├── sweep.py
│ ├── sweep.yaml
│ └── wandb_utils.py
└── val.py
推断
本文中使用detect.py文件进行推断。
如下示例,detect.py可以在各种源上运行YOLOv5推断。
python detect.py --source 0 # webcam
file.jpg # image
file.mp4 # video
path/ # directory
path/*.jpg # glob
'https://youtu.be/NUsoVlDFqZg' # YouTube video
'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP stream
detect.py的使用方法如下:
optional arguments:
-h, --help show this help message and exit
--weights WEIGHTS [WEIGHTS ...]
model.pt path(s)
--source SOURCE file/dir/URL/glob, 0 for webcam
--imgsz IMGSZ, --img IMGSZ, --img-size IMGSZ
inference size (pixels)
--conf-thres CONF_THRES
confidence threshold
--iou-thres IOU_THRES
NMS IoU threshold
--max-det MAX_DET maximum detections per image
--device DEVICE cuda device, i.e. 0 or 0,1,2,3 or cpu
--view-img show results
--save-txt save results to *.txt
--save-conf save confidences in --save-txt labels
--save-crop save cropped prediction boxes
--nosave do not save images/videos
--classes CLASSES [CLASSES ...]
filter by class: --class 0, or --class 0 2 3
--agnostic-nms class-agnostic NMS
--augment augmented inference
--visualize visualize features
--update update all models
--project PROJECT save results to project/name
--name NAME save results to project/name
--exist-ok existing project/name ok, do not increment
--line-thickness LINE_THICKNESS
bounding box thickness (pixels)
--hide-labels hide labels
--hide-conf hide confidences
--half use FP16 half-precision inference
测试语句如下。请注意该语句应该要在yolov5路径下执行。
python detect.py --weights yolov5s.pt --img 640 --conf 0.25 --source data/images/
运行完该语句后,运行结果图保存在yolov5/runs/detect/exp文件夹下。
如果有想要测试的图片或视频,可以使用Filezilla传输到云服务器:
https://cloud.videojj.com/help/docs/data_manage.html#filezilla
然后修改该推断语句中source后的文件路径。
python detect.py --weights yolov5s.pt --img 640 --conf 0.25 --source /mydata_path
关于yolo5的权重文件
以下图源自https://github.com/ultralytics/yolov5。
其他的测试结果