尝试直接从官网移植
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