嘗試直接從官網移植
1.
需要將include/darknet.h文件copy到src
2.
發現老是報錯,說代碼有問題network net = parse_network_cfg(cfgfile);報錯
(network和network*的問題),查看源代碼,代碼應該無問題。。。。
在windows下使用vs編譯源代碼,看是否能行:發現vs2015安裝有問題,一打開軟件就軟件卡住了,並且可能會導致vs2013使用也出現問題,bug!!
裝了幾個版本的vs2015都不行,我已經放棄了!!!
3.
選用
該處的代碼,對不必要的代碼做刪減,嘗試使用SDx編譯,發現不行,如下的語法解釋不了:
#define YOLODLL_API __declspec(dllexport) ... YOLODLL_API Detector(std::string cfg_filename, std::string weight_filename, int gpu_id = 0); YOLODLL_API ~Detector();
4.
還是選用原始代碼,將network net都修改為network *net,然后將net.修改為net->,此類修改(發現源代碼中其實也是有部分改了,如yolo.c,有部分沒有改)
再將example中的代碼和src內的代碼都加入源中進行編譯
yolo_v2_class.cpp和yolo_v2_class.h,yolo_console_dll.cpp刪掉
編譯通過,但是運行錯誤
root@xilinx-zc706-2017_2:/mnt# ./YOLOv2.elf yolo test cfg/tiny-yolo.cfg tiny-yolo.weights data/dog.jpg layer filters size input output 0 conv 16 3 x 3 / 1 416 x 416 x 3 -> 416 x 416 x 16 1 max 2 x 2 / 2 416 x 416 x 16 -> 208 x 208 x 16 2 conv 32 3 x 3 / 1 208 x 208 x 16 -> 208 x 208 x 32 3 max 2 x 2 / 2 208 x 208 x 32 -> 104 x 104 x 32 4 conv 64 3 x 3 / 1 104 x 104 x 32 -> 104 x 104 x 64 5 max 2 x 2 / 2 104 x 104 x 64 -> 52 x 52 x 64 6 conv 128 3 x 3 / 1 52 x 52 x 64 -> 52 x 52 x 128 7 max 2 x 2 / 2 52 x 52 x 128 -> 26 x 26 x 128 8 conv 256 3 x 3 / 1 26 x 26 x 128 -> 26 x 26 x 256 9 max 2 x 2 / 2 26 x 26 x 256 -> 13 x 13 x 256 10 conv 512 3 x 3 / 1 13 x 13 x 256 -> 13 x 13 x 512 11 max 2 x 2 / 1 13 x 13 x 512 -> 13 x 13 x 512 12 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024 13 conv 512 3 x 3 / 1 13 x 13 x1024 -> 13 x 13 x 512 14 conv 425 1 x 1 / 1 13 x 13 x 512 -> 13 x 13 x 425 15 detection mask_scale: Using default '1.000000' Loading weights from tiny-yolo.weights...Done! data/dog.jpg: Predicted in 36.919891 seconds. Not compiled with OpenCV, saving to predictions.png instead root@xilinx-zc706-2017_2:/mnt#
5.
研究發現正確的指令應該是:
./darknet detector test cfg/voc.data cfg/tiny-yolo-voc.cfg tiny-yolo-voc.weights data/dog.jpg
或者(二者等效)
./darknet detect cfg/voc.data cfg/tiny-yolo-voc.cfg tiny-yolo-voc.weights data/dog.jpg
才可,與某一開源代碼中的運行方法不一致。
換成tiny-yolo.cfg不行,理論上應該將voc.data換為coco.data,但實際換了之后仍然沒有檢測結果。
以上均應該是cfg文件、weight文件、data文件不匹配造成的。
6.
最后按照
這里的源代碼移植編譯一次,將data.c中的rand_s(&Num)函數修改為Num=rand()編譯通過后(rand_s是vs的函數,fpga上編譯不通過),終於成功了結果如下:
root@xilinx-zc706-2017_2:/mnt# ./detect.elf detector test cfg/voc.data cfg/tiny-yolo-voc.cfg tiny-yolo-voc.weights data/dog.jpg layer filters size input output 0 conv 16 3 x 3 / 1 416 x 416 x 3 -> 416 x 416 x 16 1 max 2 x 2 / 2 416 x 416 x 16 -> 208 x 208 x 16 2 conv 32 3 x 3 / 1 208 x 208 x 16 -> 208 x 208 x 32 3 max 2 x 2 / 2 208 x 208 x 32 -> 104 x 104 x 32 4 conv 64 3 x 3 / 1 104 x 104 x 32 -> 104 x 104 x 64 5 max 2 x 2 / 2 104 x 104 x 64 -> 52 x 52 x 64 6 conv 128 3 x 3 / 1 52 x 52 x 64 -> 52 x 52 x 128 7 max 2 x 2 / 2 52 x 52 x 128 -> 26 x 26 x 128 8 conv 256 3 x 3 / 1 26 x 26 x 128 -> 26 x 26 x 256 9 max 2 x 2 / 2 26 x 26 x 256 -> 13 x 13 x 256 10 conv 512 3 x 3 / 1 13 x 13 x 256 -> 13 x 13 x 512 11 max 2 x 2 / 1 13 x 13 x 512 -> 13 x 13 x 512 12 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024 13 conv 1024 3 x 3 / 1 13 x 13 x1024 -> 13 x 13 x1024 14 conv 125 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 125 15 detection Loading weights from tiny-yolo-voc.weights...Done! data/dog.jpg: Predicted in 47.318359 seconds. car: 76% bicycle: 24% dog: 79% Not compiled with OpenCV, saving to predictions.png instead root@xilinx-zc706-2017_2:/mnt#
data/person.jpg: Predicted in 47.314194 seconds. person: 69% sheep: 82% cow: 52% Not compiled with OpenCV, saving to predictions.png instead
小結:
使用
root@xilinx-zc706-2017_2:/mnt# ./detect.elf detector test cfg/coco.data cfg/tiny-yolo.cfg tiny-yolo.weights data/dog.jpg root@xilinx-zc706-2017_2:/mnt# ./detect.elf detect cfg/tiny-yolo.cfg tiny-yolo.weights data/dog.jpg root@xilinx-zc706-2017_2:/mnt# ./detect.elf yolo est cfg/tiny-yolo.cfg tiny-yolo.weights data/dog.jpg
均能讀出cfg文件,加載weights,運行37s,但是檢測結果不顯示,要么是指令有誤,要么是配置文件有誤。
使用
root@xilinx-zc706-2017_2:/mnt# ./detect.elf yolo test cfg/tiny-yolo-voc.cfg tiny-yolo-voc.weights data/person.jpg
能讀出cfg文件,加載weights,運行47s,但是檢測結果不顯示。可能原因是沒有指明voc.data,導致的問題
使用
root@xilinx-zc706-2017_2:/mnt# ./detect.elf detect cfg/tiny-yolo-voc.cfg tiny-yolo-voc.weights data/person.jpg
能讀出cfg文件,加載weights,運行47s,但是檢測結果不正確。可能原因是沒有指明voc.data,導致的list name錯亂,如下:
root@xilinx-zc706-2017_2:/mnt# ./detect.elf detect cfg/tiny-yolo-voc.cfg tiny-yolo-voc.weights data/person.jpg layer filters size input output 0 conv 16 3 x 3 / 1 416 x 416 x 3 -> 416 x 416 x 16 1 max 2 x 2 / 2 416 x 416 x 16 -> 208 x 208 x 16 2 conv 32 3 x 3 / 1 208 x 208 x 16 -> 208 x 208 x 32 3 max 2 x 2 / 2 208 x 208 x 32 -> 104 x 104 x 32 4 conv 64 3 x 3 / 1 104 x 104 x 32 -> 104 x 104 x 64 5 max 2 x 2 / 2 104 x 104 x 64 -> 52 x 52 x 64 6 conv 128 3 x 3 / 1 52 x 52 x 64 -> 52 x 52 x 128 7 max 2 x 2 / 2 52 x 52 x 128 -> 26 x 26 x 128 8 conv 256 3 x 3 / 1 26 x 26 x 128 -> 26 x 26 x 256 9 max 2 x 2 / 2 26 x 26 x 256 -> 13 x 13 x 256 10 conv 512 3 x 3 / 1 13 x 13 x 256 -> 13 x 13 x 512 11 max 2 x 2 / 1 13 x 13 x 512 -> 13 x 13 x 512 12 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024 13 conv 1024 3 x 3 / 1 13 x 13 x1024 -> 13 x 13 x1024 14 conv 125 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 125 15 detection Loading weights from tiny-yolo-voc.weights...Done! data/person.jpg: Predicted in 47.305035 seconds. bird: 69% dog: 82% traffic light: 52% Not compiled with OpenCV, saving to predictions.png instead
使用完整、正確的方式,檢測的結果為:
root@xilinx-zc706-2017_2:/mnt# ./detect.elf detector test cfg/voc.data cfg/tiny-yolo-voc.cfg tiny-yolo-voc.weights data/person.jpg layer filters size input output 0 conv 16 3 x 3 / 1 416 x 416 x 3 -> 416 x 416 x 16 1 max 2 x 2 / 2 416 x 416 x 16 -> 208 x 208 x 16 2 conv 32 3 x 3 / 1 208 x 208 x 16 -> 208 x 208 x 32 3 max 2 x 2 / 2 208 x 208 x 32 -> 104 x 104 x 32 4 conv 64 3 x 3 / 1 104 x 104 x 32 -> 104 x 104 x 64 5 max 2 x 2 / 2 104 x 104 x 64 -> 52 x 52 x 64 6 conv 128 3 x 3 / 1 52 x 52 x 64 -> 52 x 52 x 128 7 max 2 x 2 / 2 52 x 52 x 128 -> 26 x 26 x 128 8 conv 256 3 x 3 / 1 26 x 26 x 128 -> 26 x 26 x 256 9 max 2 x 2 / 2 26 x 26 x 256 -> 13 x 13 x 256 10 conv 512 3 x 3 / 1 13 x 13 x 256 -> 13 x 13 x 512 11 max 2 x 2 / 1 13 x 13 x 512 -> 13 x 13 x 512 12 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024 13 conv 1024 3 x 3 / 1 13 x 13 x1024 -> 13 x 13 x1024 14 conv 125 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 125 15 detection Loading weights from tiny-yolo-voc.weights...Done! data/person.jpg: Predicted in 47.306183 seconds. person: 69% sheep: 82% cow: 52% Not compiled with OpenCV, saving to predictions.png instead
也可以用來做分類:
root@xilinx-zc706-2017_2:/mnt# ./detect.elf classifier predict cfg/imagenet1k.data cfg/darknet.cfg darknet.weights data/dog.jpg layer filters size input output 0 conv 16 3 x 3 / 1 224 x 224 x 3 -> 224 x 224 x 16 1 max 2 x 2 / 2 224 x 224 x 16 -> 112 x 112 x 16 2 conv 32 3 x 3 / 1 112 x 112 x 16 -> 112 x 112 x 32 3 max 2 x 2 / 2 112 x 112 x 32 -> 56 x 56 x 32 4 conv 64 3 x 3 / 1 56 x 56 x 32 -> 56 x 56 x 64 5 max 2 x 2 / 2 56 x 56 x 64 -> 28 x 28 x 64 6 conv 128 3 x 3 / 1 28 x 28 x 64 -> 28 x 28 x 128 7 max 2 x 2 / 2 28 x 28 x 128 -> 14 x 14 x 128 8 conv 256 3 x 3 / 1 14 x 14 x 128 -> 14 x 14 x 256 9 max 2 x 2 / 2 14 x 14 x 256 -> 7 x 7 x 256 10 conv 512 3 x 3 / 1 7 x 7 x 256 -> 7 x 7 x 512 11 max 2 x 2 / 2 7 x 7 x 512 -> 4 x 4 x 512 12 conv 1024 3 x 3 / 1 4 x 4 x 512 -> 4 x 4 x1024 13 conv 1000 1 x 1 / 1 4 x 4 x1024 -> 4 x 4 x1000 14 avg 4 x 4 x1000 -> 1000 15 softmax 1000 16 cost 1000 Loading weights from darknet.weights...Done! 298 224 data/dog.jpg: Predicted in 7.463062 seconds. malamute: 0.222252 Norwegian elkhound: 0.101390 German shepherd: 0.089522 keeshond: 0.068499 Eskimo dog: 0.067451