yolo-darknet的配置问题(MacOS/CPU only)

最近需要用上yolo,没有找到好的训练方式,想试试darknet。
然后因为坑爹的官网文档 + mac下相关问题的解决方法太少,于是找了一晚上的错(哭

相关环境

MacOS
无CUDA(CPU only)
OpenCV 2.4

安装

根据 官网 文档进行安装即可

配置问题

Makefile的基本配置

根据系统环境:
GPU=0
CUDA=0
OPENCV=1
DEBUG=0

重新 make 即可


遇到的坑

1.测试opencv报错

执行

./darknet imtest data/eagle.jpg

报错

尝试在python中,

>>> import cv2  

报错:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named cv2

site-packages路径设置问题
输入命令:

export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH    

2.Segmentation fault: 11

按照官网上使用yolo的步骤,执行

./darknet detect cfg/yolo.cfg yolo.weights data/dog.jpg

输出:

layer filters size input output 0 conv 32 3 x 3 / 1 608 x 608 x 3 -> 608 x 608 x 32 1 max 2 x 2 / 2 608 x 608 x 32 -> 304 x 304 x 32 2 conv 64 3 x 3 / 1 304 x 304 x 32 -> 304 x 304 x 64 3 max 2 x 2 / 2 304 x 304 x 64 -> 152 x 152 x 64 4 conv 128 3 x 3 / 1 152 x 152 x 64 -> 152 x 152 x 128 5 conv 64 1 x 1 / 1 152 x 152 x 128 -> 152 x 152 x 64 6 conv 128 3 x 3 / 1 152 x 152 x 64 -> 152 x 152 x 128 7 max 2 x 2 / 2 152 x 152 x 128 -> 76 x 76 x 128 8 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 9 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 10 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 11 max 2 x 2 / 2 76 x 76 x 256 -> 38 x 38 x 256 12 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 13 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 14 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 15 conv 256 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 256 16 conv 512 3 x 3 / 1 38 x 38 x 256 -> 38 x 38 x 512 17 max 2 x 2 / 2 38 x 38 x 512 -> 19 x 19 x 512 18 conv 1024 3 x 3 / 1 19 x 19 x 512 -> 19 x 19 x1024 19 conv 512 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 512 20 conv 1024 3 x 3 / 1 19 x 19 x 512 -> 19 x 19 x1024 21 conv 512 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 512 22 conv 1024 3 x 3 / 1 19 x 19 x 512 -> 19 x 19 x1024 23 conv 1024 3 x 3 / 1 19 x 19 x1024 -> 19 x 19 x1024 24 conv 1024 3 x 3 / 1 19 x 19 x1024 -> 19 x 19 x1024 25 route 16 26 conv 64 1 x 1 / 1 38 x 38 x 512 -> 38 x 38 x 64 27 reorg / 2 38 x 38 x 64 -> 19 x 19 x 256 28 route 27 24 29 conv 1024 3 x 3 / 1 19 x 19 x1280 -> 19 x 19 x1024 30 conv 425 1 x 1 / 1 19 x 19 x1024 -> 19 x 19 x 425 31 detection Loading weights from yolo.weights…Done! data/dog.jpg: Predicted in 12.558990 seconds. dog: 82% truck: 65% bicycle: 85% Segmentation fault: 11

报错: Segmentation fault: 11
并且在目录中未出现已识别的图片

解决办法:

1.更改Makefile:

将opencv部分修改为如下代码:(分别修改COMMON/LDFLAGS)

ifeq ($(OPENCV), 1) 
COMMON+= -DOPENCV -I/usr/local/include
CFLAGS+= -DOPENCV
LDFLAGS+= `pkg-config --libs opencv` -L/usr/local/lib -lopencv_core -lopencv_highgui -lopencv_imgproc
COMMON+= `pkg-config --cflags opencv` 
endif
save   
make  

2.用官网提供的另一种命令方式:

注意到一个很坑的地方,

The detect command is shorthand for a more general version of the command. It is equivalent to the command: ./darknet detector test cfg/coco.data cfg/yolo.cfg yolo.weights data/dog.jpg

晚上在我试过各种各样解决segmentation fault 11的方法,快要崩溃的时候,试了这个所谓的等价的命令,发现成功了

(我:???????有一万句mmp要说


以上
如有错误,欢迎指正