Yolo搭建Darknet问题汇总

 

1. 安装

1、使用darknet最好不要使用opencv3.4.1,最好使用3.4.0及以下,目前使用3.4.1bug还是不少。

解决方案:ubuntu16.04,重新安装opencv3.4.0,由于之前已经安装opencv3.4.1,没有卸载直接安装3.4.0就可以,暂时没有发现问题。

(之前已经安装了opencv3.4.1,按照下面方法进行解决,发现后期会出现一些其他问题。)

opencv3.4.0 ---链接:https://pan.baidu.com/s/18pOfhAGge_XZne9xNrthwg 密码:9xmh

(注:使用GPU时,只把GPU=1,cudnn=0,不要把cudnn设为1,后面可能会出现错误。在做官方给的分类时出现错误)

2、opencv3.4.1解决方法:

前提:已安装cuda、cudnn、显卡驱动,支持gpu加速。

git clone https://github.com/pjreddie/darknet.git
cd darknet

修改makefile 

GPU=1

CUDNN=0

OPENCV=1

make

make之后出现

问题一:

gcc -Iinclude/ -Isrc/ -DOPENCV `pkg-config --cflags opencv`  -Wall -Wno-unknown-pragmas -Wfatal-```
errors -fPIC -Ofast -DOPENCV -c ./src/gemm.c -o obj/gemm.o
In file included from /usr/local/include/opencv2/core/types_c.h:59:0,
                 from /usr/local/include/opencv2/core/core_c.h:48,
                 from /usr/local/include/opencv2/highgui/highgui_c.h:45,
                 from include/darknet.h:25,
                 from ./src/utils.h:5,
                 from ./src/gemm.c:2:
/usr/local/include/opencv2/core/cvdef.h:485:1: error: unknown type name ‘namespace’
 namespace cv {
 ^~~~~~~~~
compilation terminated due to -Wfatal-errors.
Makefile:85: recipe for target 'obj/gemm.o' failed
make: *** [obj/gemm.o] Error 1

解决:修改两个文件(原因:OpenCV3.4.1存在bug,换成3.4.0就不会出现这个问题)

(1)在 如下目录下,修改485行左右内容

/usr/local/include/opencv2/core/cvdef.h

 修改485行左右内容

#else
#include <stdint.h>
namespace cv {
typedef ::int8_t int8_t;
typedef ::uint8_t uint8_t;
typedef ::int16_t int16_t;
typedef ::uint16_t uint16_t;
typedef ::int32_t int32_t;
typedef ::uint32_t uint32_t;
typedef ::int64_t int64_t;
typedef ::uint64_t uint64_t;
}
#endif

 把这段注释掉:

#else
#include <stdint.h>
//namespace cv {
//typedef ::int8_t int8_t;
//typedef ::uint8_t uint8_t;
//typedef ::int16_t int16_t;
//typedef ::uint16_t uint16_t;
//typedef ::int32_t int32_t;
//typedef ::uint32_t uint32_t;
//typedef ::int64_t int64_t;
//typedef ::uint64_t uint64_t;
//}
#endif

 (2)修改第二个文件

/usr/local/include/opencv2/highgui/highgui_c.h

 修改139行左右的代码

CVAPI(cv::Rect)cvGetWindowImageRect(const char* name);

修改类型CvRect为(注意C大写): 

CVAPI(CvRect)cvGetWindowImageRect(const char* name);

 (最后,把修改的最好改过来,网上查的资料建议改回来,说有可能不知道什么时候会用到)

 

问题二:使用yolov3检测时出现问题

# 下载权重
wget https://pjreddie.com/media/files/yolov3.weights

# 执行检测
./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg

 出现问题:

OpenCV(3.4.1-dev) Error: Assertion failed ((flags & FIXED_TYPE) != 0) in type, file /opt/opencv/modules/core/src/matrix_wrap.cpp, line 807
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(3.4.1-dev) /opt/opencv/modules/core/src/matrix_wrap.cpp:807: error: (-215) Assertion failed: (flags & FIXED_TYPE) != 0 in function type

 解决:

修改如下文件:

darknet/examples/detector.c

 这个文件的610行,给注释掉:

// save_image(im, "predictions"); 

 上述语句的意思是要把图片im存下来。

把这句话注释掉,然后重新make一次,再执行检测代码,就能够用OpenCV的GUI界面去显示检测结果以及包围盒。


参考链接:YOLOv3的Darknet在OpenCV下编译出错填坑


时间:2018/08/14 持续更新


猜你喜欢

转载自blog.csdn.net/hhhuua/article/details/81661508