Darknet--YOLO的基本使用
測試圖片
Joseph大佬已經訓練好了一個權重, 我們要拿來用吧。
wget https://pjreddie.com/media/files/yolov3.weights # yolov3權重
wget https://pjreddie.com/media/files/yolov3-tiny.weights # 小的yolov3權重
由於一些原因,下載速度可能非常慢,我保存了。
鏈接: https://pan.baidu.com/s/1rX5IY-FtBIrNABObzsLp-A 提取碼: 2us8
雖然百度雲也慢的不行。。鏈接失效了, 嫌百度雲速度慢,留個郵箱吧。
檢測一張圖片吧,注意權重文件的路徑
./darknet detect cfg/yolov3-tiny.cfg yolov3.weights data/dog.jpg
cpu上一張圖片大概十秒吧,GPU就快得很了。
如果沒有編譯opencv, 那么最終結果是這樣的
layer filters size input output
0 conv 32 3 x 3 / 1 416 x 416 x 3 -> 416 x 416 x 32 0.299 BFLOPs
1 conv 64 3 x 3 / 2 416 x 416 x 32 -> 208 x 208 x 64 1.595 BFLOPs
.......
105 conv 255 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 255 0.353 BFLOPs
106 detection
truth_thresh: Using default '1.000000'
Loading weights from yolov3.weights...Done!
data/dog.jpg: Predicted in 0.029329 seconds.
dog: 99%
truck: 93%
bicycle: 99%
結果保存在了predictions.png。編譯了opencv才會直接顯示圖片, 中間出現了一堆窗口?那就對了!讓你看懂YOLO咋工作的。
還可以這樣做。
./darknet detect cfg/yolov3.cfg yolov3.weights
然后會提示讓你輸入圖片的路徑。
./darknet detect cfg/yolov3.cfg yolov3.weights
layer filters size input output
0 conv 32 3 x 3 / 1 416 x 416 x 3 -> 416 x 416 x 32 0.299 BFLOPs
1 conv 64 3 x 3 / 2 416 x 416 x 32 -> 208 x 208 x 64 1.595 BFLOPs
.......
104 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256 1.595 BFLOPs
105 conv 255 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 255 0.353 BFLOPs
106 detection
Loading weights from yolov3.weights...Done!
Enter Image Path:
輸入圖片路徑就可以啦。
關於Thresh, YOLO只會展示確信值高於0.25的對象。
./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg -thresh 0 # 你可以設置為0, 或者任意0-1的值
測試視頻
測試視頻必須要編譯opencv了。把Makefile中的opencv=0 改成 opencv = 1。
這是我[安裝opencv c++的過程] (https://www.cnblogs.com/hichens/p/12665897.html)
最好再GPU下測試, CPU, 嘿嘿,誰試誰知道。
./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights <video file> # <video file>是視頻問價的路徑
./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights -c num # num 是電腦攝像頭(webcam)的代號, 默認為 0