YOLO算法的ZYNQ移植尝试(SDx方法、ARM部分)

尝试直接从官网移植 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 layerfilterssizeinputoutput 0 conv163 x 3 / 1416 x 416 x3->416 x 416 x16 1 max2 x 2 / 2416 x 416 x16->208 x 208 x16 2 conv323 x 3 / 1208 x 208 x16->208 x 208 x32 3 max2 x 2 / 2208 x 208 x32->104 x 104 x32 4 conv643 x 3 / 1104 x 104 x32->104 x 104 x64 5 max2 x 2 / 2104 x 104 x64->52 x52 x64 6 conv1283 x 3 / 152 x52 x64->52 x52 x 128 7 max2 x 2 / 252 x52 x 128->26 x26 x 128 8 conv2563 x 3 / 126 x26 x 128->26 x26 x 256 9 max2 x 2 / 226 x26 x 256->13 x13 x 256 10 conv5123 x 3 / 113 x13 x 256->13 x13 x 512 11 max2 x 2 / 113 x13 x 512->13 x13 x 512 12 conv10243 x 3 / 113 x13 x 512->13 x13 x1024 13 conv5123 x 3 / 113 x13 x1024->13 x13 x 512 14 conv4251 x 1 / 113 x13 x 512->13 x13 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 layerfilterssizeinputoutput 0 conv163 x 3 / 1416 x 416 x3->416 x 416 x16 1 max2 x 2 / 2416 x 416 x16->208 x 208 x16 2 conv323 x 3 / 1208 x 208 x16->208 x 208 x32 3 max2 x 2 / 2208 x 208 x32->104 x 104 x32 4 conv643 x 3 / 1104 x 104 x32->104 x 104 x64 5 max2 x 2 / 2104 x 104 x64->52 x52 x64 6 conv1283 x 3 / 152 x52 x64->52 x52 x 128 7 max2 x 2 / 252 x52 x 128->26 x26 x 128 8 conv2563 x 3 / 126 x26 x 128->26 x26 x 256 9 max2 x 2 / 226 x26 x 256->13 x13 x 256 10 conv5123 x 3 / 113 x13 x 256->13 x13 x 512 11 max2 x 2 / 113 x13 x 512->13 x13 x 512 12 conv10243 x 3 / 113 x13 x 512->13 x13 x1024 13 conv10243 x 3 / 113 x13 x1024->13 x13 x1024 14 conv1251 x 1 / 113 x13 x1024->13 x13 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

【YOLO算法的ZYNQ移植尝试(SDx方法、ARM部分)】能读出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 layerfilterssizeinputoutput 0 conv163 x 3 / 1416 x 416 x3->416 x 416 x16 1 max2 x 2 / 2416 x 416 x16->208 x 208 x16 2 conv323 x 3 / 1208 x 208 x16->208 x 208 x32 3 max2 x 2 / 2208 x 208 x32->104 x 104 x32 4 conv643 x 3 / 1104 x 104 x32->104 x 104 x64 5 max2 x 2 / 2104 x 104 x64->52 x52 x64 6 conv1283 x 3 / 152 x52 x64->52 x52 x 128 7 max2 x 2 / 252 x52 x 128->26 x26 x 128 8 conv2563 x 3 / 126 x26 x 128->26 x26 x 256 9 max2 x 2 / 226 x26 x 256->13 x13 x 256 10 conv5123 x 3 / 113 x13 x 256->13 x13 x 512 11 max2 x 2 / 113 x13 x 512->13 x13 x 512 12 conv10243 x 3 / 113 x13 x 512->13 x13 x1024 13 conv10243 x 3 / 113 x13 x1024->13 x13 x1024 14 conv1251 x 1 / 113 x13 x1024->13 x13 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 layerfilterssizeinputoutput 0 conv163 x 3 / 1416 x 416 x3->416 x 416 x16 1 max2 x 2 / 2416 x 416 x16->208 x 208 x16 2 conv323 x 3 / 1208 x 208 x16->208 x 208 x32 3 max2 x 2 / 2208 x 208 x32->104 x 104 x32 4 conv643 x 3 / 1104 x 104 x32->104 x 104 x64 5 max2 x 2 / 2104 x 104 x64->52 x52 x64 6 conv1283 x 3 / 152 x52 x64->52 x52 x 128 7 max2 x 2 / 252 x52 x 128->26 x26 x 128 8 conv2563 x 3 / 126 x26 x 128->26 x26 x 256 9 max2 x 2 / 226 x26 x 256->13 x13 x 256 10 conv5123 x 3 / 113 x13 x 256->13 x13 x 512 11 max2 x 2 / 113 x13 x 512->13 x13 x 512 12 conv10243 x 3 / 113 x13 x 512->13 x13 x1024 13 conv10243 x 3 / 113 x13 x1024->13 x13 x1024 14 conv1251 x 1 / 113 x13 x1024->13 x13 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 layerfilterssizeinputoutput 0 conv163 x 3 / 1224 x 224 x3->224 x 224 x16 1 max2 x 2 / 2224 x 224 x16->112 x 112 x16 2 conv323 x 3 / 1112 x 112 x16->112 x 112 x32 3 max2 x 2 / 2112 x 112 x32->56 x56 x32 4 conv643 x 3 / 156 x56 x32->56 x56 x64 5 max2 x 2 / 256 x56 x64->28 x28 x64 6 conv1283 x 3 / 128 x28 x64->28 x28 x 128 7 max2 x 2 / 228 x28 x 128->14 x14 x 128 8 conv2563 x 3 / 114 x14 x 128->14 x14 x 256 9 max2 x 2 / 214 x14 x 256->7 x7 x 256 10 conv5123 x 3 / 17 x7 x 256->7 x7 x 512 11 max2 x 2 / 27 x7 x 512->4 x4 x 512 12 conv10243 x 3 / 14 x4 x 512->4 x4 x1024 13 conv10001 x 1 / 14 x4 x1024->4 x4 x1000 14 avg4 x4 x1000->1000 15 softmax1000 16 cost1000 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


转载于:https://www.cnblogs.com/Osler/p/8780614.html

    推荐阅读