github源代碼:https://github.com/qqwweee/keras-yolo3
Cuda下載地址:https://developer.nvidia.com/cuda-toolkit-archive
Cudnn下載地址:https://developer.nvidia.com/rdp/cudnn-archive
yolo3預訓練權重:https://pjreddie.com/media/files/yolov3.weights
TinyYOLOv3的權重文件下載:https://pjreddie.com/media/files/yolov3-tiny.weights
查看windows下顯卡的版本,控制面板->硬件和聲音->Nvidia控制面板->幫助->系統信息->組件 看cuda dll版本
yolo3的github說明文檔中,說明了配置文件:
Python 3.5.2 (自己用3.6依舊可以運行)
Keras 2.1.5
tensorflow 1.6.0
注意,tensorflow 1.6.0需要Cuda9.0以及cudnn7.0.*的版本,特別cudnn版本高了會報錯,下載了cudnn7.1的結果就運行出錯:
Check failed: stream->parent()->GetConvolveAlgorithms( conv_parameters.ShouldIncludeWinogr adNonfuse
在anaconda中重新創建一個新環境,安放tensorflow-gpu
conda create -n tensorflow-gpu python=3.6
conda activate tensorflow-gpu
安裝上述的包,用pip下載速度慢,可以用鏡像加速。推薦豆瓣或者清華源。
http://pypi.douban.com/simple/ (豆瓣)
https://pypi.tuna.tsinghua.edu.cn/simple (清華)
pip install --ignore-installed --upgrade tensorflow-gpu==1.6.0 -i http://pypi.douban.com/simple/
pip install --ignore-installed --upgrade keras==2.1.5 -i http://pypi.douban.com/simple/
同時安裝一些yolo3裏面用到的python庫
pip install --ignore-installed --upgrade pillow h5py matplotlib opencv_python==3.2.0.8 -i http://pypi.douban.com/simple/
轉化配置文件
python convert.py yolov3.cfg yolov3.weights model_data/yolo.h5
python convert.py yolov3-tiny.cfg yolov3-tiny.weights model_data/yolo.h5
測試:
python yolo_video.py --image
輸入圖片路徑,即可得到最終結果
接着測試實時視頻流:
將yolo.py
vid = cv2.VideoCapture(video_path) 修改爲
vid = cv2.VideoCapture(0)
運行
python yolo_video.py
可以直接從攝像頭讀取視頻