您的位置:首页 > 其它

【目标检测大集合】R-FCN、SSD、YOLO2、faster-rcnn和labelImg实验笔记

2016-12-29 00:04 615 查看


R-FCN、SSD、YOLO2、faster-rcnn和labelImg实验笔记

转自:https://ask.julyedu.com/question/7490

R-FCN

paper:https://arxiv.org/abs/1605.06409

作者代码:https://github.com/daijifeng001/R-FCN #matlab版本

这里使用python版本的代码:https://github.com/Orpine/py-R-FCN

1.下载代码

git clone https://github.com/Orpine/py-R-FCN.git

2.克隆caffe

cd py-R-FCN

git clone https://github.com/Microsoft/caffe.git #Microsoft的源

[可选]

cd caffe

git reset --hard 1a2be8e

3.编译Cython模块

cd py-R-FCN/lib

make

4.编译caffe和pycaffe


这里Makefile.config要支持Python layers!


In your Makefile.config, make sure to have this line uncommented

WITH_PYTHON_LAYER := 1

cd py-R-FCN/caffe

cp Makefile.config.example Makefile.config 

make -j8 && make pycaffe

5.下载resnet caffemodel

从OneDriver下载rfcn_models https://1drv.ms/u/s!AoN7vygOjLIQqUWHpY67oaC7mopf

解压到:py-R-FCN/data下

解压后的目录:

py-R-FCN/data/rfcn_models/resnet50_rfcn_final.caffemodel

py-R-FCN/data/rfcn_models/resnet101_rfcn_final.caffemodel

6.运行demo

python py-R-FCN/tools/demo_rfcn.py --net ResNet-50

python py-R-FCN/tools/demo_rfcn.py --net ResNet-101

ResNet-50效果图:









ResNet-101效果图:









7.准备训练和测试

笔者这里简单使用VOC2007,并且修改名称VOC0712,笔者把数据集直接放在py-R-FCN/data下

官网使用VOC2007和VOC2012,使用的时候要合并数据集,具体参考官网的Preparation for Training & Testing 第四点

8.下载ImageNet 与预训练的ResNet-50和ResNet-100

OneDriver:https://onedrive.live.com/%3Fa
... FF777(在KaimingHe的github https://github.com/KaimingHe/d ... works )

mkdir py-R-FCN/data/imagenet_models

将model放到该目录

9.可自己修改模型,类别,修改相应的py-r-fcn/py-R-FCN/models/pascal_voc/目录下对应的文件和py-r-fcn/lib/datasets/pascal_voc.py。笔者这里还是使用默认的。

10.修改迭代次数

vi py-r-fcn/experiments/scripts/rfcn_end2end_ohem.sh

把pascal_voc的ITERS 调小

11.训练

./py-r-fcn/experiments/scripts/rfcn_end2end_ohem.sh 0 ResNet-50 pascal_voc 

其他训练方式请自行参考官网Usage





12.测试

将训练好的模型py-r-fcn/py-R-FCN/output/rfcn_end2end_ohem/voc_0712_trainval/resnet50_rfcn_ohem_iter_x.caffemodel,放到 py-r-fcn/py-R-FCN/data/rfcn_models 下,修改 py-R-FCN/tools/demo_rfcn.py的NETS,运行

SSD

paper:https://arxiv.org/abs/1512.02325

作者代码:https://github.com/weiliu89/caffe/tree/ssd

1.下载代码:

git clone https://github.com/weiliu89/caffe.git

cd caffe

git checkout ssd

2.编译代码

cp Makefile.config.example Makefile.config

make -j8

make py

make test -j8

make runtest -j8

3.准备

1.下载caffemodel和prototxt 
https://gist.github.com/weiliu ... f81d6

从上边地址下载完放到/models/VGGNET/

4.下载VOC2007和VOC2012

cd /root/data

wget http://host.robots.ox.ac.uk/pa ... 2.tar

wget http://host.robots.ox.ac.uk/pa ... 7.tar

wget http://host.robots.ox.ac.uk/pa ... 7.tar

tar -xvf VOCtrainval_11-May-2012.tar

tar -xvf VOCtrainval_06-Nov-2007.tar

tar -xvf VOCtest_06-Nov-2007.tar

5.创建LMDB文件

cd $CAFFE_ROOT

./data/VOC0712/create_list.sh

./data/VOC0712/create_data.sh

6.训练模型

python examples/ssd/ssd_pascal.py 

也可以从这里http://www.cs.unc.edu/%257Ewli ... ar.gz 下训练好的模型。

7.评估模型

python examples/ssd/score_ssd_pascal.py





8.测试模型

python examples/ssd/ssd_pascal_webcam.py #笔者这步忽略

贴几张youtube的SSD实时检测效果,视频地址:https://www.youtube.com/watch?v=6q-DBCPROA8

















直接用ssd_detect.ipynb(examples/ssd_detect.ipynb)测试





9.训练其他数据集忽略

mxnet 版本的ssd

代码地址:https://github.com/zhreshold/mxnet-ssd

1.下载代码

git clone --recursive https://github.com/zhreshold/mxnet-ssd.git

2.编译mxnet

cd mxnet-ssd/mxnet

cp make/config.mk ./config.mk #自行修改配置文件

make -j8

3.下载预训练模型

地址:https://dl.dropboxusercontent. ... 2.zip。下载后解压到model下

4.测试demo

python demo.py --epoch 0 --images ./data/demo/dog.jpg --thresh 0.5

效果图:









5.其他的训练数据忽略

YOLO2

paper:https://arxiv.org/abs/1506.02640

官网:http://pjreddie.com/darknet/yolo/

1.下载代码

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

cd darknet

make

2.下载模型

wget http://pjreddie.com/media/files/yolo.weights

3.检测

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

效果图









其他效果图









4.所有检测

./darknet detect cfg/yolo.cfg yolo.weights data/dog.jpg -thresh 0





5.在视频上检测

./darknet detector demo cfg/coco.data cfg/yolo.cfg yolo.weights <video file>

















faster-rcnn

paper:https://arxiv.org/abs/1506.01497

官方版本:https://github.com/ShaoqingRen/faster_rcnn #matlab

这里使用python版本:https://github.com/rbgirshick/py-faster-rcnn

1.下载代码

git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git

笔者这里换了官方的源,没问题的同学可忽略

cd caffe-fast-rcnn

git remote add caffe https://github.com/BVLC/caffe.gitX86Xgit fetch caffe

git merge caffe/master 

2.编译Cython模块

cd $FRCN_ROOT/lib

make

3.编译caffe和pycaffe


这里Makefile.config要支持Python layers!


In your Makefile.config, make sure to have this line uncommented

WITH_PYTHON_LAYER := 1

cd $FRCN_ROOT/caffe-fast-rcnn

make -j8 && make pycaffe

4.下载预训练模型

cd $FRCN_ROOT

./data/scripts/fetch_faster_rcnn_models.sh

5.测试demo

cd $FRCN_ROOT

./tools/demo.py

效果图:





















6.其他数据集训练的此处忽略

labelImg

笔者使用的图像标注工具是labelImg,制作的格式和PASCAL VOC一样,可在windows、linux和Mac使用。

代码地址:https://github.com/tzutalin/labelImg

1.环境依赖

至少python2.6和PyQt 4.8

2.Linux/Ubuntu/Mac 安装

sudo apt-get install pyqt4-dev-tools

sudo pip install lxml

make all

./labelImg.py

Windows

在文件目录下执行

pyrcc4 -o resources.py resources.qrc

python labelImg.py

3.常规使用步骤

python labelImg.py

在File菜单选Change default saved annotation folder

点击Open Dir,打开图片路径

点击Create RectBox,画标注

4.常用快捷键

Ctrl + r 选择annotation的默认存放路径

Ctrl + n 新建一个标注

Ctrl + s 保存图片

n:下张图片

p:上一张图片

5.预先可以在 labelImg/data/predefined_classes.txt 定义标注类别



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: