一、下載darknet
(1)https://github.com/pjreddie/darknet 中clone&download
(2)https://pjreddie.com/darknet/install/ 在命令行下:
git clone https://github.com/pjreddie/darknet.git
二、安裝Cygwin
https://cygwin.com/install.html 根據系統位數下載;
安裝的時候鏡像隨便選一個能用的就行,比如默認的第一個:
一定要記得選擇安裝一些額外的包,gcc-core、gcc-g++、make、gdb、binutils
在View的Category下的Devel下可以找到:
添加“安裝目錄\cygwin64\bin”系統路徑Path,例如:
E:\cygwin64\bin
三、編譯darknet
(1)檢查gcc,在cmd中輸入:
which gcc
檢查gcc是否安裝設置爲cygwin,而不是MinGW的gcc:
(2)修改examples\Go.c 文件,開頭加上“#include <sys/select.h>”,否則編譯出錯。
(3)運行cygwin64,打開當前darknet的目錄,例如:
cd F:keras-yolo3-master/darknet
(4)編譯,輸入:
make
觀察到:
make過程中無報錯,且在..\darknet\obj文件夾下生成若干.o文件,即視爲編譯成功。
四、訓練yolo
1. Generate your own annotation file and class names file.
python voc_annotation.py
2. 運行:
python convert.py -w yolov3.cfg yolov3.weights model_data/yolo_weights.h5
The file model_data/yolo_weights.h5 is used to load pretrained weights.
或者:
wget https://pjreddie.com/media/files/yolov3.weights
得到預訓練好的權重,就不用自己再訓練了
3. 訓練:
python train.py
用CPU的話訓練時間非常長 ,50輪迭代,每次5個半小時。
Use your trained weights or checkpoint weights with command line option `--model model_file` when using yolo_video.py
Remember to modify class path or anchor path, with `--classes class_file` and `--anchors anchor_file`.
If you want to use original pretrained weights for YOLOv3:
1. `wget https://pjreddie.com/media/files/darknet53.conv.74`
2. rename it as darknet53.weights
3. `python convert.py -w darknet53.cfg darknet53.weights model_data/darknet53_weights.h5`
4. use model_data/darknet53_weights.h5 in train.py
五、預測
輸入:
./darknet
得到:
usage: ./darknet <function>
說明darknet編譯成功可以使用。
./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg
預測當前data文件夾下的dog圖片:
置信度如圖,在當前文件夾下得到predictions.jpg:
六、踩坑
如果之前沒有注意到要使用cygwin的gcc,誤使用MinGW的gcc來make的話,會報錯
[Makefile:89:obj/deconvolutional_layer.o] 錯誤 1
這個時候不僅要修改爲cygwin的gcc,還要在obj目錄下刪除乾淨使用MinGW的gcc編譯出的.o文件。