偶得片刻闲暇,将之前学习及训练SSD网络的记录整理如下,部分问题的解决方法来源于网络。
源代码:https://github.com/weiliu89/caffe/tree/ssd
protobuf版本不一致
.build_release/src/caffe/proto/caffe.pb.h:23:35: fatal error: google/protobuf/arena.h: 没有那个文件或目录 compilation terminated. Makefile:575: recipe for target ‘.build_release/src/caffe/util/blocking_queue.o’ failed make: *** [.build_release/src/caffe/u
解决方法
https://blog.csdn.net/m0_38082419/article/details/80117132
注意修改Makefile文件后先make clean一下再重新make。
hdf5错误
In file included from src/caffe/util/hdf5.cpp:1:0: ./include/caffe/util/hdf5.hpp:6:18: fatal error: hdf5.h: 没有那个文件或目录 compilation terminated. Makefile:575: recipe for target ‘.build_release/src/caffe/util/hdf5.o’ failed make: *** [.build_release/
解决方法
修改Makefile.config文件,将libhdf5-serial-dev的位置添加在你的配置文件中。
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial
cv中的变量或函数未定义
.build_release/lib/libcaffe.so:对‘cv::VideoCapture::set(int, double)’未定义的引用。
解决方法
在Makefile.config文件中取消对OPENCV_VERSION := 3的注释。
解释器错误
-bash: ./windyjunfeng/caffe/data/VOC0712/create_list.sh: /bin/bash^M: 解释器错误: 没有那个文件或目录。
解决方法
linux下的文件在windows下面编辑过常会出现此错误。因为windows下的换行结尾是\n\r ,而在linux下的换行结尾是\n。将\r替换为空即可。
sed -i 's/\r$//' create_list.sh
missing separator
Makefile.config:77: *** missing separator
解决方法
修改Makefile.config文件时使用了空格或者有中文字符,复制文件中其他地方的语句进行修改。
python版本不是2.7导致的一系列问题
caffe模块出错
Traceback (most recent call last):
File “/home/f523/windyjunfeng/caffe/data/VOC0712/…/…/scripts/create_annoset.py”, line 7, in
from caffe.proto import caffe_pb2
ImportError: No module named ‘caffe’
解决方法
在create_annoset.py中import sys后面添加如下代码:
sys.path.insert(0,'/home/f523/windyjunfeng/caffe/python')
接着出现如下错误:
Traceback (most recent call last):
File “/home/f523/windyjunfeng/caffe/data/VOC0712/…/…/scripts/create_annoset.py”, line 8, in
from caffe.proto import caffe_pb2
File “/home/f523/windyjunfeng/caffe/python/caffe/init.py”, line 1, in
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver
File “/home/f523/windyjunfeng/caffe/python/caffe/pycaffe.py”, line 13, in
from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver,
ImportError: dynamic module does not define module export function (PyInit__caffe)
解决方法
cd caffe/python
export PYTHONPATH=/home/f523/windyjunfeng/caffe/python/:$PYTHONPATH
echo $PYTHONPATH
虽然有些博客上说该方法有效,但在实验室的服务器上测试无效,分析可能是默认的python路径不是python2.7。要将默认的python路径改为python2.7,用which python查看默认的python。试验过多种修改默认python的方法均以失败告终,最终一个简单且有效的方法悄然出现,即用anaconda创建一个自己的环境。
conda create --name your_env_name python=2.7
利用conda activate your_env_name指令激活并进入该环境,利用conda deactivate退出该环境。
如果数据集下载和解压路径不是根路径下的data文件夹,需要修改create_data.sh文件中的data_root_dir和create_list.sh文件中的root_dir,同时修改ssd_pascal.py文件中的output_result_dir。
源代码:https://github.com/amdegroot/ssd.pytorch
训练时参考博客:https://blog.csdn.net/dingkm666/article/details/88775428
维度不匹配
RuntimeError: The shape of the mask [32, 8732] at index 0 does not match the shape of the indexed tensor [279424, 1] at index 0
解决方法
参考:https://github.com/amdegroot/ssd.pytorch/issues/173
修改multibox_loss.py中的程序
autograd function问题
RuntimeError: Legacy autograd function with non-static forward method is deprecated. Please use new-style autograd function with static forward method.
解决方法
https://github.com/amdegroot/ssd.pytorch/issues/444
pytorch版本的问题,修改detection.py和ssd.py即可。
detection.py修改方法:https://github.com/miyamotok0105/pytorch_handbook/blob/master/chapter7/layers/functions/detection.py
ssd.py修改方法:
https://github.com/miyamotok0105/pytorch_handbook/blob/master/chapter7/ssd.py
如果仅下载了VOC数据集而没有下载COCO数据集,需要注释掉__init__.py中该行代码:
from .coco import COCODetection, COCOAnnotationTransform, COCO_CLASSES, COCO_ROOT, get_label_map
同时,将train.py中第84行的COCO_ROOT改为VOC_ROOT,==改为!=
第一个链接对SSD网络解析得十分透彻详尽,适合自己研读完SSD: Single Shot MultiBox Detector后进一步理解SSD网络;第二个链接中的base、extra和head部分的配置结构表有助于更直观地理解SSD网络结构,对理解后续相关SSD改进有极大帮助。
由于在学习SSD网络之前,自己研究过YOLO系列网络,尤其是YOLOv3,因此将SSD网络和YOLOv3网络进行对比,两者主要有以下不同:
SSD | YOLOv3 | |
---|---|---|
特征提取器 | VGG16 | Darknet53 |
先验锚点框 | 人工设定的尺寸和形状 | K-means聚类得到 |
损失 | Softmax损失 | Logistic损失 |
边界框预测 | 直接计算相对于先验框的偏移量 | 使用了sigmoid函数 |
适合目标 | 有利于大目标检测 | 有利于小目标检测 |
输入图像尺寸 | 固定 | 可随机缩放 |
前两篇论文都可看作对SSD网络的backbone进行改进,尤其是MoblieNetv2_SSDLite轻量化效果甚好;第三篇论文提出的RFB模块可以置换到SSD网络的head部分,提高检测准确率,检测速度仅略有降低。