源碼地址:https://github.com/ultralytics/yolov5
配置環境
Ubuntu18.04
本篇創建虛擬環境training_pytorch,並安裝python3.8.5,torch1.7.1進行yolov5環境的配置。
所需依賴的安裝,並沒有遇到別的博客中所描述的,記憶中一切都很順利,也許缺啥補啥吧。直接按照源碼地址中描述的安裝即可。
pip install -r requirements.txt
requiremets.txt包含的依賴包如下圖所示(202101010)。
下載預訓練模型
目前,在YOLOv5中一共包含5種與訓練模型,網絡輸入分辨率、精度、參數量、實時性如下圖所示。預訓練模型鏈接。建議剛開始配置時選擇最輕量級的YOLOv5s模型,下載起來相對快一些。
試用模型Inference
基礎環境搭好以后,便可以使用試用模型進行檢測,預訓練模型支持80個類別的識別。所以可以先用來檢驗環境搭建是否成功。
為了簡化試用模型時,調用detect.py所需要的配置參數,可以對默認參數進行修改。如下圖所示。
修改后,執行detect.py后,便可以在runs/detect/exp中看到相應的檢測結果。
python detect.py
當然,如果不想修改detect.py的默認配置,可以通過調用detect.py傳參的方式進行。
python detect.py --weights yolov5s.pt --img 640 --conf 0.25 --source data/images/
Image(filename='runs/detect/exp/zidane.jpg', width=600)
Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.25, device='', exist_ok=False, img_size=640, iou_thres=0.45, name='exp', project='runs/detect', save_conf=False, save_txt=False, source='data/images/', update=False, view_img=False, weights=['yolov5s.pt'])
YOLOv5 v4.0-21-gb26a2f6 torch 1.7.0+cu101 CUDA:0 (Tesla V100-SXM2-16GB, 16130.5MB)
Fusing layers...
Model Summary: 224 layers, 7266973 parameters, 0 gradients, 17.0 GFLOPS
image 1/2 /content/yolov5/data/images/bus.jpg: 640x480 4 persons, 1 buss, 1 skateboards, Done. (0.011s)
image 2/2 /content/yolov5/data/images/zidane.jpg: 384x640 2 persons, 2 ties, Done. (0.011s)
Results saved to runs/detect/exp
Done. (0.110s)
下面是github上給出的參數配置示例:
對於有行人、汽車檢測背景需要的同學,可以先用預訓練模型試試自己場景的圖像。