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

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

深度学习班和视觉班寒老师和李老师讲过图像检测与识别,这篇笔记主要记录R-FCN、SSD、YOLO2、faster-rcnn和labelImg实验。

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效果图:

resnet50.png


resnet50-2.png


ResNet-101效果图:

R-FCN101.png


R-FCN101-2.png


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

R-FCN_training.png


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

ssd-final.png


8.测试模型
python examples/ssd/ssd_pascal_webcam.py #笔者这步忽略
贴几张youtube的SSD实时检测效果,视频地址: https://www.youtube.com/watch?v=6q-DBCPROA8

youtube_ssd_1.png


youtubeaas1.png


youtubess3.png


youtubessd5.png


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

ssd-example.png


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

效果图:

mxnet-ssd1.png


mxnetssd3.png


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
效果图

yolo1.png


yolo2.png


其他效果图

yolo3.png


yolo4.png


4.所有检测
./darknet detect cfg/yolo.cfg yolo.weights data/dog.jpg -thresh 0

yolo5.png


5.在视频上检测
./darknet detector demo cfg/coco.data cfg/yolo.cfg yolo.weights <video file>

yolo2.png


yolo2-2.png


yolo3.png


yolo2-v3.png


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

效果图:

faster-rcnn1.png


faster-rcnn.png


faster-rcnn4.png


faster-rcnn5.png


faster-rcnn6.png


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 定义标注类别

labelImage.png
    • 0
      点赞
    • 1
      收藏
      觉得还不错? 一键收藏
    • 0
      评论
    Faster R-CNN、R-FCNSSD、FPN、RetinaNet和YOLOv3 MobileNet都是目标检测算法,用于在图像或视频中检测和定位物体。 Faster R-CNN是一种先进的目标检测算法。它由两个主要组件组成:区域提取网络(Region Proposal Network,RPN)和分类网络。RPN负责生成潜在的物体候选框,分类网络用于对候选框进行分类和定位。 R-FCN(Region-based Fully Convolutional Networks)通过引入ROI池化操作来消除Faster R-CNN中的全连接层,使网络可以端到端地进行训练,从而提高了计算效率和准确性。 SSD(Single Shot MultiBox Detector)是一种单阶段目标检测算法,通过在不同尺度的特征图上同时进行预测,实现了更快的检测速度。SSD通过多个不同大小和宽高比的锚框进行物体检测和分类。 FPN(Feature Pyramid Networks)是一种用于解决多尺度物体检测的算法。它通过构建金字塔式的特征图,使得网络在不同尺度的信息都能得到有效的利用,提高了检测的准确性。 RetinaNet是一种基于金字塔结构的目标检测算法。它使用了一种特殊的损失函数(Focal Loss),能够有效地解决正负样本极度不平衡的问题,同时保持了高度的检测准确性。 YOLOv3 MobileNet是YOLO(You Only Look Once)系列目标检测算法的一种轻量级版本。它通过使用MobileNet作为主干网络,实现了更小的模型体积和更快的检测速度,适用于在资源受限的设备上进行实时目标检测。 综上所述,这些目标检测算法各有特点,适用于不同的场景和应用需求。根据具体的要求和实际情况选择适合的算法可以达到更好的检测效果。

    “相关推荐”对你有帮助么?

    • 非常没帮助
    • 没帮助
    • 一般
    • 有帮助
    • 非常有帮助
    提交
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

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

    抵扣说明:

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

    余额充值