目标检测 | 配置RefineDet详细步骤及填坑笔记

配置RefineDet详细步骤及参数修改

RefineDet算法,可参考。。。。

1. Caffe安装

可参考:Caffe深度学习入门——Ubuntu16.04 + CUDA9.1+cudnn7.5 + opencv3.3.1+python3.5+caffe安装参考博客和跳坑笔记

2. RefineDet安装:

git clone https://github.com/sfzhang15/RefineDet.git
cd $RefineDet_ROOT
# Modify Makefile.config according to your Caffe installation.
# Make sure to include $RefineDet_ROOT/python to your PYTHONPATH.
cp Makefile.config.example Makefile.config

复制一份的原因是编译 RefineDet时需要的是 Makefile.config 文件,而Makefile.config.example 只是RefineDet给出的配置文件例子,不能用来编译 RefineDet。

3. 修改 Makefile.config 文件

在 RefineDet目录下打开该文件:

修改Makefile.config文件中的内容:
1.应用 cudnn 修改: USE_CUDNN := 1
2.应用 opencv 修改:OPENCV_VERSION := 3
3.使用 python 接口:修改 WITH_PYTHON_LAYER := 1
4.修改 python 路径:修改
    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
5.修改PYTHON_INCLUDE路径:
PYTHON_INCLUDE := /usr/include/python2.7 \
        /usr/local/lib/python2.7/dist-packages/numpy/core/include

4. 编译:

make all -j8
make py

5. 将RefineDet中的python路径添加到.bashrc中并生效

在~/.bashrc中将RefineDet中的python路径添加PYTHONPATH路径,
sudo gedit ~/.bashrc
export PYTHONPATH=/media/****/****/RefineDet/python:$PYTHONPATH
source ~/.bashrc

6. 整理数据

6.1 首先下载VOC2007和VOC2012数据集, 放在/data目录下:

cd data
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar

tar -xvf VOCtrainval_11-May-2012.tar
tar -xvf VOCtrainval_06-Nov-2007.tar
tar -xvf VOCtest_06-Nov-2007.tar

6.2 生成需要的数据文件

注意修改data/voc0712/create_list.sh文件中data_root_dir路径
#root_dir=$HOME/data/VOCdevkit/
root_dir=/media/****/****/data/VOCdevkit

修改create_data.sh文件中data_root_dir路径
#data_root_dir="$HOME/data/VOCdevkit/"
data_root_dir="/media/****/****/data/VOCdevkit/"

cd RefineDet
bash ./data/VOC0712/create_list.sh
bash ./data/VOC0712/create_data.sh

7. 训练模型

python examples/refinedet/VGG16_VOC2007_320.py

8. 估算精度值

RefineDet/test/lib
make -j

修改 test/lib/datasets/pasal_voc.py中数据集的存放路径

#self._devkit_path = os.environ['HOME'] + '/data/Object_Detection/pascal/VOCdevkit'
self._devkit_path ='/media/xxxxxx/8013xxxxxx8-b070-19fc662a5236/data/VOCdevkit'

开始测试,并将测试结果保存下来。mAP为79.62.

 python test/refinedet_test.py 2>1 | tee test_model_120000.log
Writing tvmonitor VOC results file
VOC07 metric? Yes
AP for aeroplane = 0.8341
AP for bicycle = 0.8591
AP for bird = 0.8097
AP for boat = 0.7189
AP for bottle = 0.5977
AP for bus = 0.8678
AP for car = 0.8777
AP for cat = 0.8853
AP for chair = 0.6298
AP for cow = 0.8338
AP for diningtable = 0.7691
AP for dog = 0.8513
AP for horse = 0.8681
AP for motorbike = 0.8531
AP for person = 0.8282
AP for pottedplant = 0.5553
AP for sheep = 0.8163
AP for sofa = 0.7996
AP for train = 0.8658
AP for tvmonitor = 0.8033
Mean AP = 0.7962
~~~~~~~~
Results:
0.834
0.859
0.810
0.719
0.598
0.868
0.878
0.885
0.630
0.834
0.769
0.851
0.868
0.853
0.828
0.555
0.816
0.800
0.866
0.803
0.796
~~~~~~~~
#########################################################################################################
#########################################################################################################
120000	0.7962

9. 检测单张图片

修改est/refinedet_demo.py中模型的存放路径

#model_weights = 'models/VGGNet/VOC0712/refinedet_vgg16_320x320/VOC0712_refinedet_vgg16_320x320_iter_final.caffemodel'
model_weights = 'models/VGGNet/VOC0712/refinedet_vgg16_320x320/VOC0712_refinedet_vgg16_320x320_iter_120000.caffemodel'
python test/refinedet_demo.py

在这里插入图片描述
可以看出,上图中的司机都检测出来了。
在这里插入图片描述

在这里插入图片描述
远处的人检测的效果也挺好,但是下面坐卧的狗狗检测成了马。

10.配置流程中遇到的错误及解决方案

报错1:

collect2: error: ld returned 1 exit status
Makefile:619: recipe for target ‘.build_release/tools/compute_image_mean.bin’ failed
make: *** [.build_release/tools/compute_image_mean.bin] Error 1

解决方案:按照要求修改Makefile.config文件中的内容,再重新MAKE即可。

报错2:

Makefile:501: recipe for target ‘python/caffe/_caffe.so’ failed
make: *** [python/caffe/_caffe.so] Error 1

解决方案:python的路径没有配置对.
在Makefile.config找到PYTHON_INCLUDE,发现有点不同:
PYTHON_INCLUDE := /usr/include/python2.7 \
        /usr/lib/python2.7/dist-packages/numpy/core/include
要加一个local,变成:
PYTHON_INCLUDE := /usr/include/python2.7 \
        /usr/local/lib/python2.7/dist-packages/numpy/core/include
再make py就ok了

报错3:

运行python examples/refinedet/VGG16_VOC2007_320.py时报错:

   db_lmdb.hpp:15] Check failed: mdb_status == 0 (2 vs. 0) No such file or directory
    *** Check failure stack trace: ***
    解决方案:数据集没有整理好,按照整理数据的步骤整理

报错4:

运行sh ./data/VOC0712/create_list.sh时报错:

VOC0712/create_list.sh: 6: ./data/VOC0712/create_list.sh: Bad substitution
解决方案:修改create_list.sh create_data.sh中的data_root路径,重新运行这两个文件。

报错5:

运行python examples/refinedet/VGG16_VOC2007_320.py时报错
Check failed: fd != -1 (-1 vs. -1) File not found: models/VGGNet/VGG_ILSVRC_16_layers_fc_reduced.caffemodel
*** Check failure stack trace: ***
@ 0x7f7d4b214e3d google::LogMessage::Fail()
@ 0x7f7d4b216bc0 google::LogMessage::SendToLog()
@ 0x7f7d4b214a23 google::LogMessage::Flush()
@ 0x7f7d4b21758e google::LogMessageFatal::~LogMessageFatal()
@ 0x7f7d4b97a99c caffe::ReadProtoFromBinaryFile()
@ 0x7f7d4b932b56 caffe::ReadNetParamsFromBinaryFileOrDie()
@ 0x7f7d4b8f273a caffe::Net<>::CopyTrainedLayersFromBinaryProto()
@ 0x7f7d4b8f27de caffe::Net<>::CopyTrainedLayersFrom()
@ 0x40a809 CopyLayers()
@ 0x40bbb9 train()
@ 0x407818 main
@ 0x7f7d499a7830 (unknown)
@ 0x408229 _start
Aborted (core dumped)

解决方案:下载VGG_ILSVRC_16_layers_fc_reduced.caffemodel,放在RefineDet/models/VGGNet/目录下

报错6:

运行python examples/refinedet/VGG16_VOC2007_320.py时报错
F1212 16:32:07.843426 53472 parallel.cpp:130] Check failed: error == cudaSuccess (10 vs. 0) invalid device ordinal
*** Check failure stack trace: ***
@ 0x7fe3328c4e3d google::LogMessage::Fail()
@ 0x7fe3328c6bc0 google::LogMessage::SendToLog()
@ 0x7fe3328c4a23 google::LogMessage::Flush()
@ 0x7fe3328c758e google::LogMessageFatal::~LogMessageFatal()
@ 0x7fe3331ed9cd caffe::DevicePair::compute()
@ 0x7fe3331f3750 caffe::P2PSync<>::Prepare()
@ 0x7fe3331f425e caffe::P2PSync<>::Run()
@ 0x40b090 train()
@ 0x407818 main
@ 0x7fe331057830 (unknown)
@ 0x408229 _start
Aborted (core dumped)

解决方案:
这是由于GPU数量不匹配造成的,需要根据自己的硬件条件加以修正。由于博主只有一块GPU且电脑运行内存有限,还需要将VGG16_VOC2007_320.py文件中的339行batch_size = 32和340行accum_batch_size = 32都改小一倍,即更改批量大小,不然会出现“Check failed: error == cudaSuccess (10 vs. 0)  invalid device ordinal”的错误。

将VGG16_VOC2007_320.py中
#gpus = "0,1,2,3"
gpus = "0"

#batch_size = 32
#accum_batch_size = 32
batch_size = 8
accum_batch_size = 8

参考:https://github.com/sfzhang15/RefineDet

评论 49
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值