TL-SSD: Detecting Traffic Lights by Single Shot Detection 论文复现

 

1.按照我上一篇博客安装caffe-ssd;

2.安装开源网站提供的文档替换caffe-ssd,并重新编译caffe。

2.1.安装pycaffe

cd caffe-master/python
source activate caffe_py35 #如果用anaconda环境
for req in $(cat requirements.txt); do pip install $req; done
cd ..
make pycaffe -j8

2.2在python中执行import caffe报错,没有这个模块:

sudo gedit ~/.bashrc
在文档最后加上:
export PYTHONPATH=/home/wds/tool/Caffe/Caffe-ssd/caffe/python:$PYTHONPATH

2.3在python中执行import caffe出错

ImportError: /usr/local/lib/libcudart.so.9.0: version `libcublas.so.9.0' not found (required by /home/wds/tool/Caffe/Caffe-ssd/caffe/python/caffe/../../build/lib/libcaffe.so.1.0.0-rc3)

然后,我查看了libcaffe的依赖:

ldd libcaffe.so.1.0.0-rc3 
./libcaffe.so.1.0.0-rc3: /usr/local/lib/libcudart.so.9.0: version `libcublas.so.9.0' not found (required by ./libcaffe.so.1.0.0-rc3)
./libcaffe.so.1.0.0-rc3: /lib/x86_64-linux-gnu/libz.so.1: version `ZLIB_1.2.9' not found (required by /home/wds/anaconda3/lib/libpng16.so.16)

我们先看zlib:

wds@wds:/usr/local/cuda/lib64$ find /usr/ -name zlib.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/zlib.pc
wds@wds:/usr/local/cuda/lib64$ cat /usr/lib/x86_64-linux-gnu/pkgconfig/zlib.pc 
prefix=/usr
exec_prefix=${prefix}
libdir=${prefix}/lib/x86_64-linux-gnu
sharedlibdir=${libdir}
includedir=${prefix}/include

Name: zlib
Description: zlib compression library
Version: 1.2.8

Requires:
Libs: -L${libdir} -L${sharedlibdir} -lz
Cflags: -I${includedir}

可以看到系统中zlib版本是1.2.8,所以我们升级到1.2.9,先下载,然后配置:

tar -xvf ~/Downloads/zlib-1.2.9.tar.gz
cd zlib-1.2.9
sudo -s
./configure; make; make install
cd /lib/x86_64-linux-gnu
ln -s -f /usr/local/lib/libz.so.1.2.9/lib libz.so.1
cd ~
rm -rf zlib-1.2.9

然后我们解决另外一个报错,重新建立软链接:

wds@wds:/usr/local/cuda/lib64$ sudo ln -s -f libcublas.so.9.0 /usr/local/lib/libcublas.so.9.0
wds@wds:/usr/local/cuda/lib64$ sudo ln -s -f libcudart.so.9.0 /usr/local/lib/libcudart.so.9.0

2.4 在python中执行import caffe出错

from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
ImportError: /home/wds/tool/Caffe/Caffe-ssd/caffe/python/caffe/_caffe.so: undefined symbol: _ZN5boost6python6detail11init_moduleER11PyModuleDefPFvvE

 

Google该错误,发现原因是boost_python的版本不匹配,默认python版本为3.5,而boost_python为2.7。
解决方法:
先在系统的/usr/lib/x86_64-linux-gnu/路径下查找boost_python文件的版本是否与python版本匹配,我的电脑中文件名为:

wds@wds:/usr/lib/x86_64-linux-gnu$ ls libboost_python*
libboost_python.a               libboost_python-py35.a
libboost_python-py27.a          libboost_python-py35.so
libboost_python-py27.so         libboost_python-py35.so.1.58.0
libboost_python-py27.so.1.58.0  libboost_python.so

原因: libboost_python.so的版本不匹配,默认python版本为3.5,而boost_python为2.7。
解决方法:修改make.config文件, 将PYTHON_LIBRARIES := boost_python3 python3.5m注释去掉,并修改为PYTHON_LIBRARIES := boost_python-py35 python3.5m. 重新编译即可。
注意: python3.5m一定要带上,否则会出现如下错误


CXX/LD -o .build_release/tools/upgrade_net_proto_binary.bin
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyNumber_InPlaceRemainder'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyLong_FromLong'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyUnicode_AsUTF8String'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyUnicode_FromFormat'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyExc_ValueError'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyModule_Create2'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyNumber_And'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PySlice_New'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyList_Sort'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyImport_ImportModule'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyExc_OverflowError'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyType_IsSubtype'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyLong_Type'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyObject_SetAttrString'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyList_Insert'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyRun_FileExFlags'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyExc_RuntimeError'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyComplex_Type'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyDict_Type'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyDict_Copy'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyObject_CallFunction'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyUnicode_Type'
/usr/lib/x86_64-linux-gnu/libboost_python-py35.so: undefined reference to `PyDict_Size'

至此可以import caffe

3. 因为要在python3.5上使用,所以把load_dtld.py和ssd_dtld_test.py中print XXX 改为 print(XXX), xrange改为range。

4.执行

python test_on_dtld/ssd_dtld_test.py --predictionmap_file /home/wds/tool/Caffe/Caffe-ssd/caffe/test_on_dtld/prediction_map_ssd_states.json --confidence 0.2 --deploy_file /home/wds/tool/Caffe/Caffe-ssd/caffe/prototxt/deploy.prototxt --caffemodel_file /home/wds/tool/Caffe/Caffe-ssd/caffe/caffemodel/SSD_DTLD_iter_90000.caffemodel --test_file /home/wds/tool/Caffe/Caffe-ssd/caffe/Berlin_all.yml 

 报错:

  bar = progressbar.ProgressBar(widgets=widgets, max_value=len(database.images)).start()
TypeError: __init__() got an unexpected keyword argument 'max_value'

把progressbar换成tqdm,即:

for idx,img in tqdm(enumerate(database.images)):

注意:Python导入模块的方法有两种:import module 和 from module import,区别是前者所有导入的东西使用时需加上模块名的限定,而后者不要,加载tqdm时要通过from tqdm import  tqdm的形式。

5.接着执行程序。

报错:

Going through all images
WARNING: Logging before InitGoogleLogging() is written to STDERR
F0815 09:11:31.164649  7690 syncedmem.cpp:56] Check failed: error == cudaSuccess (2 vs. 0)  out of memory
*** Check failure stack trace: ***

该报错原因是GPU显存不够,我目前是在具有2G显存GTX1050的笔记本上跑的程序。

法一:修改deploy.protxt和ssd_dtld_test.py中,输入图像的尺寸改为1024x256,可以正常运行,消耗的显存为1.2G因此原有显存需4.8G。但这里有个问题是修改了输入图像尺寸预测的结果就不对了。

法二:用CPU做测试,进行以下操作。

将ssd_dtld_test.py中
            det_label = detections[0,0,:,1]
            det_conf = detections[0,0,:,2]
            det_states = detections[0,0,:,3:3 + num_states +1]
            det_xmin = detections[0,0,:,3 + num_states + 1]
            det_ymin = detections[0,0,:,3 + num_states + 2]
            det_xmax = detections[0,0,:,3 + num_states + 3]
            det_ymax = detections[0,0,:,3 + num_states + 4]
            det_states[:, 0] = 0.0
改为
            #label+confidence+states+bbox*4
            det_label = detections[0,0,:,0]
            det_conf = detections[0,0,:,2]
            det_states = detections[0,0,:,1:1 + num_states +1]
            det_xmin = detections[0,0,:,2 + num_states + 1]
            det_ymin = detections[0,0,:,2 + num_states + 2]
            det_xmax = detections[0,0,:,2 + num_states + 3]
            det_ymax = detections[0,0,:,2 + num_states + 4]
            det_states[:, 0] = 0.0

将:
            tags.extend(self.class_vec_to_tags(det_states[i]))
改为:
            tags.extend(str(self.classes[0][int(det_states[i])]))

将:
            caffe.set_device(gpu_id)
            caffe.set_mode_gpu()
改为:
            caffe.set_mode_cpu()

运行

python test_on_dtld/ssd_dtld_test.py --gpu_id 0 --predictionmap_file /home/wds/tool/Caffe/Caffe-ssd/caffe/test_on_dtld/prediction_map_ssd_states.json --confidence 0.2 --deploy_file /home/wds/tool/Caffe/Caffe-ssd/caffe/prototxt/deploy.prototxt --caffemodel_file /home/wds/tool/Caffe/Caffe-ssd/caffe/caffemodel/SSD_DTLD_iter_90000.caffemodel --test_file /home/wds/tool/Caffe/Caffe-ssd/caffe/Bochum_all.yml

即可成功执行,不过CPU模式不支持交通灯状态的检测,只能检测边界框,检测结果如下。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
MSFT-YOLO是基于Transformer模型改进的Yolov5用于检测SE(电子元器件)缺陷的方法。 Transformer是一种先进的神经网络架构,主要用于自然语言处理任务,但在计算机视觉领域也得到了广泛应用。Yolov5则是一种经典的目标检测算法,通过将图像分成多个网格单元并预测每个单元中的物体,实现了实时目标检测。 在MSFT-YOLO中,我们将Transformer应用于Yolov5的特征提取阶段,以提高对SE缺陷的检测能力。传统的Yolov5使用的是卷积神经网络作为特征提取器,但这种方法在处理复杂的缺陷图像时可能会存在一定的局限性。 通过引入Transformer,我们可以将图像中的每个像素看作是一组序列数据,并利用Transformer的自注意力机制来捕捉不同位置之间的依赖关系。这种方式可以提取出更具语义信息的特征表示,从而有效地检测SE缺陷。 在训练过程中,我们使用大量带有标注的SE缺陷图像来优化网络参数。通过进行端到端的训练,我们可以不断调整网络权重以提高检测精度。此外,我们还可以使用数据增强技术来扩增数据集,从而提升模型的鲁棒性和泛化能力。 实验结果表明,MSFT-YOLO相较于传统的Yolov5在SE缺陷检测方面取得了更好的性能。它能够识别出更多的缺陷类型,同时还具备较低的误检率。这使得它在工业制造等领域中有着广泛的应用前景,能够提高产品质量和生产效率。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值