R-FCN + ResNet + Python + 训练自己的模型

来源:互联网 发布:行尸走肉网络剧仓库 编辑:程序博客网 时间:2024/05/19 13:25

  • 安装MS Caffe
  • 测试Demo
  • 训练自己的模型的准备工作
  • 训练
  • 参考链接

安装MS Caffe

假设你已经装好了CUDA,cudnn,caffe等等。 这一步感觉和faster rcnn很像,都需要独特版本的caffe。这里的版本就是Microsoft的caffe。

pip install cython pip install easydict apt-get install
python-opencv
git clone https://github.com/Orpine/py-R-FCN.git
cd py-R-FCN

进入lib文件夹,然后:

make

接着进入caffe目录:(32核用起来果然很爽)

make -j32 && make pycaffe

这里的Makefile.config需要注意一下,每个人的都有一点点不一样,比如我就没有加入opencv。这里没写好的话就会有不少错误。

## Refer to http://caffe.berkeleyvision.org/installation.html# Contributions simplifying and improving our build system are welcome!# cuDNN acceleration switch (uncomment to build with cuDNN).USE_CUDNN := 1# CPU-only switch (uncomment to build without GPU support).# CPU_ONLY := 1# uncomment to disable IO dependencies and corresponding data layers# USE_OPENCV := 0# USE_LEVELDB := 0# USE_LMDB := 0# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)#       You should not set this flag if you will be reading LMDBs with any#       possibility of simultaneous read and write# ALLOW_LMDB_NOLOCK := 1# Uncomment if you're using OpenCV 3# OPENCV_VERSION := 3# To customize your choice of compiler, uncomment and set the following.# CUDA directory contains bin/ and lib/ directories that we need.CUDA_DIR := /usr/local/cuda# On Ubuntu 14.04, if cuda tools are installed via# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:# CUDA_DIR := /usr# CUDA architecture setting: going with all of them.# For CUDA < 6.0, comment the *_50 lines for compatibility.CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \                -gencode arch=compute_20,code=sm_21 \                -gencode arch=compute_30,code=sm_30 \                -gencode arch=compute_35,code=sm_35 \                -gencode arch=compute_50,code=sm_50 \                -gencode arch=compute_50,code=compute_50# BLAS choice:# atlas for ATLAS (default)# mkl for MKL# open for OpenBlasBLAS := atlas# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.# Leave commented to accept the defaults for your choice of BLAS# open for OpenBlasBLAS := atlas# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.# Leave commented to accept the defaults for your choice of BLAS# (which should work)!# BLAS_INCLUDE := /path/to/your/blas# BLAS_LIB := /path/to/your/blas# Homebrew puts openblas in a directory that is not on the standard search path# BLAS_INCLUDE := $(shell brew --prefix openblas)/include# BLAS_LIB := $(shell brew --prefix openblas)/lib# This is required only if you will compile the matlab interface.# MATLAB directory should contain the mex binary in /bin.# MATLAB_DIR := /usr/local# MATLAB_DIR := /Applications/MATLAB_R2012b.app# NOTE: this is required only if you will compile the python interface.# We need to be able to find Python.h and numpy/arrayobject.h.PYTHON_INCLUDE := /usr/include/python2.7 \                /usr/lib/python2.7/dist-packages/numpy/core/include# Anaconda Python distribution is quite popular. Include path:# Uncomment to support layers written in Python (will link against Python libs)WITH_PYTHON_LAYER := 1# Whatever else you find you need goes here.INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/lib/x86_64-linux-gnu/hdf5/serial/includeLIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies# INCLUDE_DIRS += $(shell brew --prefix)/include# LIBRARY_DIRS += $(shell brew --prefix)/lib# Uncomment to use `pkg-config` to specify OpenCV library paths.# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)# USE_PKG_CONFIG := 1# N.B. both build and distribute dirs are cleared on `make clean`BUILD_DIR := buildDISTRIBUTE_DIR := distribute# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171# DEBUG := 1# The ID of the GPU that 'make runtest' will use to run unit tests.TEST_GPUID := 0# enable pretty build (comment to see full commands)Q ?= @       

测试Demo

下载已经训练好的模型。
点击这里: https://1drv.ms/u/s!AoN7vygOjLIQqUWHpY67oaC7mopf

然后下载之后放进去:

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

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

运行:

./tools/demo_rfcn.py –net ResNet-50

效果就是:
这里写图片描述

这里写图片描述

训练自己的模型的准备工作

在data目录下,下载VOC的数据集。
1、下载

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

2、解压:

tar xvf VOCtrainval_06-Nov-2007.tartar xvf VOCtest_06-Nov-2007.tartar xvf VOCdevkit_08-Jun-2007.tartar xvf VOCtrainval_11-May-2012.tar

3、整理:
把下面的情况:

$VOCdevkit/                           # development kit$VOCdevkit/VOCcode/                   # VOC utility code$VOCdevkit/VOC2007                    # image sets, annotations, etc.$VOCdevkit/VOC2012                    # image sets, annotations, etc.

弄成: 多一个0712

$VOCdevkit/                           # development kit  $VOCdevkit/VOCcode/                   # VOC utility code  $VOCdevkit/VOC2007                    # image sets, annotations, etc.  $VOCdevkit/VOC2012                    # image sets, annotations, etc.  $VOCdevkit/VOC0712                    # you just created this folder

PS:在这里需要注意把训练的train.sh里面的TRAIN_IMDB改成如下形式。

case $DATASET in    pascal_voc)      TRAIN_IMDB="voc_0712_trainval"      TEST_IMDB="voc_0712_test"      PT_DIR="pascal_voc"      ITERS=110000  

4、链接:

cd $RFCN_ROOT/dataln -s $VOCdevkit VOCdevkit0712

5、下载事先训练好的imageNet的rest50,100的模型。

ImageNet-pre-trained ResNet-50 and ResNet-100 model 

下载地址:链接:http://pan.baidu.com/s/1slRHD0L 密码:r3ki

下载之后放在:/data/imagenet_models目录下。

训练

需要修改网络接口,我的输出是4类,那么在需要改不少东西。具体修改参考: http://blog.csdn.net/sinat_30071459/article/details/53202977
http://blog.csdn.net/xzzppp/article/details/52036794
这篇博客已经写得非常详细。

接着就使用 ./experiments/scripts/rfcn_end2end_ohem.sh 0 ResNet-50 pascal_voc 训练。

$RFCN_ROOT/experiments/scripts里还有一些其他的训练方法,也可以测试一下(经过上面的修改,无ohem的end2end训练也改好了,其他训练方法修改的过程差不多)。

将训练得到的模型

($RFCN_ROOT/output/rfcn_end2end_ohem/voc_0712_trainval

里最后的caffemodel)拷贝到

$RFCN_ROOT/data/rfcn_models

下,然后打开

$RFCN_ROOT/tools/demo_rfcn.py

,将CLASSES修改成你的标签,NETS修改成你的model,im_names修改成你的测试图片(放在data/demo下),最后:

./tools/demo_rfcn.py –net ResNet-50

看一下最后的结果:
这里写图片描述

这里写图片描述

参考链接

1、http://blog.csdn.net/sinat_30071459/article/details/53202977
2、https://github.com/Orpine/py-R-FCN

1 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 我有外遇了老婆不离婚怎么办 套了牙套的牙疼怎么办 我鼻子上有很多螨虫和黑头怎么办 鱼刺卡在喉咙怎么办最有效的办法 脚被蚊子咬了很痒怎么办 好压7z密码忘了怎么办 4g卡显示2g网络怎么办 过塑机把纸吞了怎么办 红米1s开不了机怎么办 跟老婆吵架闹的要离婚该怎么办 充了q币没有到账怎么办 9个月宝宝吃了盐怎么办 红米4x开不了机怎么办 鱼身上有红斑像出血了怎么办 草鱼身上有红斑像出血了怎么办 宝宝屁眼红的破皮了怎么办 孩子身上起红疙瘩很痒怎么办 久而不射,但软了怎么办 盆底综合肌力1级怎么办 头发掉的厉害怎么办吃什么好 给蜂蛰了肿了痒怎么办 小米手环2没电了怎么办 小米手环2不亮了怎么办 红米3s无限重启怎么办 乐视手机1s卡顿怎么办 老公出轨了怎么办你会选择离婚吗 c盘和d盘换换了怎么办 晚上2点到3点醒怎么办 红米3s变砖了怎么办 6s锁屏密码忘了怎么办 怀孕9个月了胃疼怎么办 怀孕6个月了胃疼怎么办 孕妇胃疼怎么办4个月了 25岁欠了5万块钱怎么办 感冒嗓子疼怎么办最简单的方法 和老婆离婚了我的心好痛怎么办 4s店不给退定金怎么办 教你闪腰了后该怎么办 coolpad酷派手机开不了机怎么办 苹果5s黑屏开不了机怎么办 苹果4s的屏坏了怎么办