下载程序,
git clone https://github.com/Orpine/py-R-FCN.git
打开py-R-FCN,下载caffe
git clone https://github.com/Microsoft/caffe.git
编译Cython模块
cd lib
make
结果如下图所示:
编译caffe和pycaffe
cd caffe
cp Makefile.config.example MAkefile.config
然后配置Makefile.config文件,可参考我的Makefile.config
[plain] view plaincopy
  1. ## Refer to http://caffe.berkeleyvision.org/installation.html
  2. # Contributions simplifying and improving our build system are welcome!
  3. # cuDNN acceleration switch (uncomment to build with cuDNN).
  4. USE_CUDNN := 1
  5. # CPU-only switch (uncomment to build without GPU support).
  6. # CPU_ONLY := 1
  7. # uncomment to disable IO dependencies and corresponding data layers
  8. # USE_OPENCV := 0
  9. # USE_LEVELDB := 0
  10. # USE_LMDB := 0
  11. # uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
  12. #   You should not set this flag if you will be reading LMDBs with any
  13. #   possibility of simultaneous read and write
  14. # ALLOW_LMDB_NOLOCK := 1
  15. # Uncomment if you're using OpenCV 3
  16. # OPENCV_VERSION := 3
  17. # To customize your choice of compiler, uncomment and set the following.
  18. # N.B. the default for Linux is g++ and the default for OSX is clang++
  19. # CUSTOM_CXX := g++
  20. # CUDA directory contains bin/ and lib/ directories that we need.
  21. CUDA_DIR := /usr/local/cuda
  22. # On Ubuntu 14.04, if cuda tools are installed via
  23. # "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
  24. # CUDA_DIR := /usr
  25. # CUDA architecture setting: going with all of them.
  26. # For CUDA < 6.0, comment the *_50 lines for compatibility.
  27. CUDA_ARCH := -gencode arch=compute_30,code=sm_30 \
  28. -gencode arch=compute_35,code=sm_35 \
  29. -gencode arch=compute_50,code=sm_50 \
  30. -gencode arch=compute_50,code=compute_50 \
  31. -gencode arch=compute_53,code=compute_53 \
  32. -gencode arch=compute_61,code=compute_61
  33. # BLAS choice:
  34. # atlas for ATLAS (default)
  35. # mkl for MKL
  36. # open for OpenBlas
  37. BLAS := open
  38. # Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
  39. # Leave commented to accept the defaults for your choice of BLAS
  40. # (which should work)!
  41. # BLAS_INCLUDE := /path/to/your/blas
  42. # BLAS_LIB := /path/to/your/blas
  43. # Homebrew puts openblas in a directory that is not on the standard search path
  44. # BLAS_INCLUDE := $(shell brew --prefix openblas)/include
  45. # BLAS_LIB := $(shell brew --prefix openblas)/lib
  46. # This is required only if you will compile the matlab interface.
  47. # MATLAB directory should contain the mex binary in /bin.
  48. MATLAB_DIR := /usr/local/MATLAB/R2013b
  49. # MATLAB_DIR := /Applications/MATLAB_R2012b.app
  50. # NOTE: this is required only if you will compile the python interface.
  51. # We need to be able to find Python.h and numpy/arrayobject.h.
  52. PYTHON_INCLUDE := /usr/include/python2.7 \
  53. /usr/lib64/python2.7/site-packages/numpy/core/include \
  54. /usr/lib/python2.7/dist-packages/numpy/core/include
  55. # Anaconda Python distribution is quite popular. Include path:
  56. # Verify anaconda location, sometimes it's in root.
  57. # ANACONDA_HOME := $(HOME)/anaconda
  58. # PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
  59. # $(ANACONDA_HOME)/include/python2.7 \
  60. # $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \
  61. # Uncomment to use Python 3 (default is Python 2)
  62. # PYTHON_LIBRARIES := boost_python3 python3.5m
  63. # PYTHON_INCLUDE := /usr/include/python3.5m \
  64. #                 /usr/lib/python3.5/dist-packages/numpy/core/include
  65. # We need to be able to find libpythonX.X.so or .dylib.
  66. PYTHON_LIB := /usr/lib
  67. # PYTHON_LIB := $(ANACONDA_HOME)/lib
  68. # Homebrew installs numpy in a non standard path (keg only)
  69. # PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
  70. # PYTHON_LIB += $(shell brew --prefix numpy)/lib
  71. # Uncomment to support layers written in Python (will link against Python libs)
  72. WITH_PYTHON_LAYER := 1
  73. # Whatever else you find you need goes here.
  74. INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
  75. LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
  76. # If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
  77. INCLUDE_DIRS += /usr/local/hdf5/include
  78. LIBRARY_DIRS += /usr/local/hdf5/lib
  79. # Uncomment to use `pkg-config` to specify OpenCV library paths.
  80. # (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
  81. # USE_PKG_CONFIG := 1
  82. # N.B. both build and distribute dirs are cleared on `make clean`
  83. BUILD_DIR := build
  84. DISTRIBUTE_DIR := distribute
  85. # Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
  86. # DEBUG := 1
  87. # The ID of the GPU that 'make runtest' will use to run unit tests.
  88. TEST_GPUID := 0
  89. # enable pretty build (comment to see full commands)
  90. Q ?= @
make -j8
结果如下图所示:
make pycaffe
结果如下图所示:
下载预训练模型(https://1drv.ms/u/s!AoN7vygOjLIQqUWHpY67oaC7mopf),放到data数据集下,如图所示(第二个是我自己训练的模型):
运行演示脚本:
./tools/demo_rfcn.py

结果如下图所示:

下载训练,测试,验证数据集:
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
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCdevkit_08-Jun-2007.tar
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar
解压到VOCdevkit文件夹中:
tar xvf VOCtrainval_06-Nov-2007.tar
tar xvf VOCtest_06-Nov-2007.tar
tar xvf VOCdevkit_08-Jun-2007.tar
tar xvf VOCtrainval_11-May-2012.tar
VOCdevkit文件夹的结构如下图所示:
由于py-faster-rcnn不支持多个训练集,我们创造一个新的文件夹叫做VOC0712,把VOC2007和VOC2012里的JPEGImage和Annonation融合到一个单独的文件夹JPEGImage和Annonation里,用下面的程序生成新的ImageSets文件夹:
[plain] view plaincopy
  1. %writetxt.m
  2. file = dir('F:\VOC0712\Annotations\*.xml');
  3. len = length(file);
  4. num_trainval=sort(randperm(len, floor(9*len/10)));%trainval集占所有数据的9/10,可以根据需要设置
  5. num_train=sort(num_trainval(randperm(length(num_trainval), floor(5*length(num_trainval)/6))));%train集占trainval集的5/6,可以根据需要设置
  6. num_val=setdiff(num_trainval,num_train);%trainval集剩下的作为val集
  7. num_test=setdiff(1:len,num_trainval);%所有数据中剩下的作为test集
  8. path = 'F:\VOC0712\ImageSets\Main\';
  9. fid=fopen(strcat(path, 'trainval.txt'),'a+');
  10. for i=1:length(num_trainval)
  11. s = sprintf('%s',file(num_trainval(i)).name);
  12. fprintf(fid,[s(1:length(s)-4) '\n']);
  13. end
  14. fclose(fid);
  15. fid=fopen(strcat(path, 'train.txt'),'a+');
  16. for i=1:length(num_train)
  17. s = sprintf('%s',file(num_train(i)).name);
  18. fprintf(fid,[s(1:length(s)-4) '\n']);
  19. end
  20. fclose(fid);
  21. fid=fopen(strcat(path, 'val.txt'),'a+');
  22. for i=1:length(num_val)
  23. s = sprintf('%s',file(num_val(i)).name);
  24. fprintf(fid,[s(1:length(s)-4) '\n']);
  25. end
  26. fclose(fid);
  27. fid=fopen(strcat(path, 'test.txt'),'a+');
  28. for i=1:length(num_test)
  29. s = sprintf('%s',file(num_test(i)).name);
  30. if ~isempty(strfind(s,'plain'))
  31. fprintf(fid,[s(1:length(s)-4) '\n']);
  32. end
  33. end
  34. fclose(fid);
为VOCdevkit创造新的超链接:VOCdevkit0712,如下图所示
下载在ImageNet上预训练好的模型,放到./data/imagenet_models里,如下图所示:
下面开始用VOC0712训练:
experiments/scripts/rfcn_end2end.sh 使用联合近似训练
experiments/scripts/rfcn_end2end_ohem.sh 使用联合近似训练+OHEM
experiments/scripts/rfcn_alt_opt_5stage_ohem.sh 使用分布训练+OHEM
./experiments/scripts/rfcn_end2end[_ohem].sh [GPU_ID] [NET] [DATASET] [--set ...]
下面开始用py-rfcn来训练自己的数据集:(我的数据集是标准pascal voc数据集,名字叫做VOC5000)
首先修改网络模型:
1.修改/py-R-FCN/models/pascal_voc/ResNet-50/rfcn_end2end/class-aware/train_ohem.prototxt
[plain] view plaincopy
  1. name: "ResNet-50"
  2. layer {
  3. name: 'input-data'
  4. type: 'Python'
  5. top: 'data'
  6. top: 'im_info'
  7. top: 'gt_boxes'
  8. python_param {
  9. module: 'roi_data_layer.layer'
  10. layer: 'RoIDataLayer'
  11. param_str: "'num_classes': 2" #改为你的数据集的类别数+1
  12. }
  13. }
  14. layer {
  15. name: 'roi-data'
  16. type: 'Python'
  17. bottom: 'rpn_rois'
  18. bottom: 'gt_boxes'
  19. top: 'rois'
  20. top: 'labels'
  21. top: 'bbox_targets'
  22. top: 'bbox_inside_weights'
  23. top: 'bbox_outside_weights'
  24. python_param {
  25. module: 'rpn.proposal_target_layer'
  26. layer: 'ProposalTargetLayer'
  27. param_str: "'num_classes': 2"#改为你的数据集的类别数+1
  28. }
  29. }
  30. layer {
  31. bottom: "conv_new_1"
  32. top: "rfcn_cls"
  33. name: "rfcn_cls"
  34. type: "Convolution"
  35. convolution_param {
  36. num_output: 98 #2*(7^2) cls_num*(score_maps_size^2)(类别数+1)*49
  37. kernel_size: 1
  38. pad: 0
  39. weight_filler {
  40. type: "gaussian"
  41. std: 0.01
  42. }
  43. bias_filler {
  44. type: "constant"
  45. value: 0
  46. }
  47. }
  48. param {
  49. lr_mult: 1.0
  50. }
  51. param {
  52. lr_mult: 2.0
  53. }
  54. }
  55. layer {
  56. bottom: "conv_new_1"
  57. top: "rfcn_bbox"
  58. name: "rfcn_bbox"
  59. type: "Convolution"
  60. convolution_param {
  61. num_output: 392 #8*(7^2) cls_num*(score_maps_size^2)(类别数+1)*49*4
  62. kernel_size: 1
  63. pad: 0
  64. weight_filler {
  65. type: "gaussian"
  66. std: 0.01
  67. }
  68. bias_filler {
  69. type: "constant"
  70. value: 0
  71. }
  72. }
  73. param {
  74. lr_mult: 1.0
  75. }
  76. param {
  77. lr_mult: 2.0
  78. }
  79. }
  80. layer {
  81. bottom: "rfcn_cls"
  82. bottom: "rois"
  83. top: "psroipooled_cls_rois"
  84. name: "psroipooled_cls_rois"
  85. type: "PSROIPooling"
  86. psroi_pooling_param {
  87. spatial_scale: 0.0625
  88. output_dim: 2  #类别数+1
  89. group_size: 7
  90. }
  91. }
  92. layer {
  93. bottom: "rfcn_bbox"
  94. bottom: "rois"
  95. top: "psroipooled_loc_rois"
  96. name: "psroipooled_loc_rois"
  97. type: "PSROIPooling"
  98. psroi_pooling_param {
  99. spatial_scale: 0.0625
  100. output_dim: 8#类别数*4
  101. group_size: 7
  102. }
  103. }
2.修改/py-R-FCN/models/pascal_voc/ResNet-50/rfcn_end2end/class-aware/test.prototxt
[plain] view plaincopy
  1. layer {
  2. bottom: "conv_new_1"
  3. top: "rfcn_cls"
  4. name: "rfcn_cls"
  5. type: "Convolution"
  6. convolution_param {
  7. num_output: 98 #21*(7^2) cls_num*(score_maps_size^2)(类别数+1)*2
  8. kernel_size: 1
  9. pad: 0
  10. weight_filler {
  11. type: "gaussian"
  12. std: 0.01
  13. }
  14. bias_filler {
  15. type: "constant"
  16. value: 0
  17. }
  18. }
  19. param {
  20. lr_mult: 1.0
  21. }
  22. param {
  23. lr_mult: 2.0
  24. }
  25. }
  26. layer {
  27. bottom: "conv_new_1"
  28. top: "rfcn_bbox"
  29. name: "rfcn_bbox"
  30. type: "Convolution"
  31. convolution_param {
  32. num_output: 392 #8*(7^2) cls_num*(score_maps_size^2)(类别数+1)*49*4
  33. kernel_size: 1
  34. pad: 0
  35. weight_filler {
  36. type: "gaussian"
  37. std: 0.01
  38. }
  39. bias_filler {
  40. type: "constant"
  41. value: 0
  42. }
  43. }
  44. param {
  45. lr_mult: 1.0
  46. }
  47. param {
  48. lr_mult: 2.0
  49. }
  50. }
  51. layer {
  52. bottom: "rfcn_cls"
  53. bottom: "rois"
  54. top: "psroipooled_cls_rois"
  55. name: "psroipooled_cls_rois"
  56. type: "PSROIPooling"
  57. psroi_pooling_param {
  58. spatial_scale: 0.0625
  59. output_dim: 2 #(类别数+1)
  60. group_size: 7
  61. }
  62. }
  63. layer {
  64. bottom: "rfcn_bbox"
  65. bottom: "rois"
  66. top: "psroipooled_loc_rois"
  67. name: "psroipooled_loc_rois"
  68. type: "PSROIPooling"
  69. psroi_pooling_param {
  70. spatial_scale: 0.0625
  71. output_dim: 8 #(类别数+1)*4
  72. group_size: 7
  73. }
  74. }
  75. layer {
  76. name: "cls_prob_reshape"
  77. type: "Reshape"
  78. bottom: "cls_prob_pre"
  79. top: "cls_prob"
  80. reshape_param {
  81. shape {
  82. dim: -1
  83. dim: 2 #(类别数+1)
  84. }
  85. }
  86. }
  87. layer {
  88. name: "bbox_pred_reshape"
  89. type: "Reshape"
  90. bottom: "bbox_pred_pre"
  91. top: "bbox_pred"
  92. reshape_param {
  93. shape {
  94. dim: -1
  95. dim: 8 #(类别数+1)*4
  96. }
  97. }
  98. }
3.修改/py-R-FCN/lib/datasets/pascal_voc.py
[plain] view plaincopy
  1. class pascal_voc(imdb):
  2. def __init__(self, image_set, year, devkit_path=None):
  3. imdb.__init__(self, 'voc_' + year + '_' + image_set)
  4. self._year = year
  5. self._image_set = image_set
  6. self._devkit_path = self._get_default_path() if devkit_path is None \
  7. else devkit_path
  8. self._data_path = os.path.join(self._devkit_path, 'VOC' + self._year)
  9. self._classes = ('__background__', # always index 0
  10. 'aeroplane')
  11. self._class_to_ind = dict(zip(self.classes, xrange(self.num_classes)))
  12. self._image_ext = '.jpg'
  13. 修改self._classes为你的类别加背景。
4./py-R-FCN/lib/datasets/factory.py修改
[plain] view plaincopy
  1. for year in ['2007', '2012','2001','2002','2006','5000']:
  2. for split in ['train', 'val', 'trainval', 'test']:
  3. name = 'voc_{}_{}'.format(year, split)
  4. __sets[name] = (lambda split=split, year=year: pascal_voc(split, year))
  5. 我的数据集叫:VOC5000,所以把5000加到年份当中。
5/py-R-FCN/experiments/scripts/rfcn_end2end_ohem.sh修改
[plain] view plaincopy
  1. case $DATASET in
  2. pascal_voc)
  3. TRAIN_IMDB="voc_5000_trainval"
  4. TEST_IMDB="voc_5000_test"
  5. PT_DIR="pascal_voc"
  6. ITERS=4000
  7. ;;
  8. 把训练数据集和测试数据集改为你的数据集,迭代次数改为4000。
开始训练:./experiments/scripts/rfcn_end2end_ohem.sh 0 ResNet-50 pascal_voc
迭代4000次,取得了81.2%的精度。

py-rfcn算法caffe配置,训练及应用到自己的数据集相关推荐

  1. 【caffe-matlab】目标检测R-FCN算法于Windows下配置

    前言 首先谢谢好友推荐的这篇论文及代码,前面学习的caffe可能比较浅显,想要深入caffe就可以从这个代码下手了,配置方法还是挺简单的,但是可能会出现部分问题.在作者的论文中有github的地址.注 ...

  2. FastMaskRCNN算法TensorFlow配置,训练

    git clonehttps://github.com/CharlesShang/FastMaskRCNN.git 打开./libs/datasets/pycocotools,执行make 下载COC ...

  3. redhat配置caffe多核训练

    参考网站: http://blog.csdn.net/10km/article/details/52723306 http://stackoverflow.com/questions/31395729 ...

  4. [2] SSD配置+训练VOC0712+训练自己的数据集

    GitHub https://github.com/weiliu89/caffe/tree/ssd http://blog.csdn.net/u010733679/article/details/52 ...

  5. SSD配置+训练VOC0712+训练自己的数据集

    GitHub https://github.com/weiliu89/caffe/tree/ssd http://blog.csdn.net/u010733679/article/details/52 ...

  6. caffe学习(二):利用mnist数据集训练并进行手写数字识别(windows)

    准备数据集 http://yann.lecun.com/exdb/mnist/提供了训练集与测试集数据的下载. 但是caffe并不是直接处理这些数据,而是要转换成lmdb或leveldb格式进行读取. ...

  7. DL之R-FCN:R-FCN算法的简介(论文介绍)、架构详解、案例应用等配图集合之详细攻略

    DL之R-FCN:R-FCN算法的简介(论文介绍).架构详解.案例应用等配图集合之详细攻略 目录 R-FCN算法的简介(论文介绍) 1.Motivation: Sharing is Caring 7. ...

  8. 【非原创】Ubuntu14.04+cuda6.5+opencv2.4.9+caffe配置记录

    Ubuntu14.04+cuda6.5+opencv2.4.9+caffe配置记录 从4月5日差不多开始安装,到今天4月15日,快两个星期了.如果加上之前自己看点Linux的时间,这折腾的有两个星期( ...

  9. NVIDIA-TLT训练行人检测模型(一)----算法模型的训练(finetuning)

    前言 在博客阅读前需要说明,本博文为系列文章,通过阅读文章,您将会学习到如下内容: 使用NVIDIA Transfer Learning Toolkit 工具训练(finetuning)出一个行人检测 ...

最新文章

  1. 怎样删除usb计算机连接网络打印机驱动,惠普激光打印机安装驱动时报“跟这台计算机连接的一个 USB 设备运行不正...
  2. 『网站升级』PHPWind8.0至8.3升级过程及问题种种回顾录
  3. 如何(以及为什么需要)创建一个好的验证集
  4. 一加6升级android p,一加6手机升级安卓P攻略 教你怎么更新安卓P Beta版
  5. SDOI2018IIIDX
  6. 程序员的10条黄金法则,你懂?
  7. 打开 谷歌浏览器exe_python使用selenium调用谷歌浏览器打开指定网页
  8. java编译器API——使用编译工具
  9. System.Net.Mail和System.Web.Mail
  10. Cordic的学习之硬件实现
  11. mysql innodb排他锁_mysql 中innoDB引擎的事务喝共享锁喝排他锁
  12. 转:12种JavaScript MVC框架之比较
  13. pcs7组态虚拟机中的服务器,PCS7冗余服务器配置
  14. SD卡--摄像头中扩容卡原理及检测机制
  15. 网站提示HTTP503Service Unavailable的处理办法
  16. 向大家推荐Ubuntu下九大最佳绘图程序
  17. centos 批量替换文件内容
  18. linux压缩命令-----zip
  19. 在macOS上交叉编译arm64的程序并在IOS上运行
  20. 【增加苏宁】2020双十一淘宝领喵币+京东全名营业+支付宝+苏宁の自动化任务

热门文章

  1. boost::math::quadrature::sinh_sinh用法的测试程序
  2. boost::fusion::flatten_view用法的测试程序
  3. boost::gregorian模块实现以天为单位显示到新年的时间量的测试程序
  4. GDCM:gdcm::PixelFormat的测试程序
  5. DCMTK:I2DBmpSource类的测试程序
  6. VTK:Video之MPEG2
  7. VTK:Snippets之ReadPolyData
  8. PolyData之DataBounds
  9. OpenCV相机运动估计
  10. C语言结构体对齐的不足