Description: This blog post assumes that you have made your own dataset, and that the dataset is formatted the same as VOC2007. Here are some pre-training changes.
(The process of doing a dataset can be seen here.)
FASTER-RCNN Source:
MATLAB version: HTTPS://GITHUB.COM/SHAOQINGREN/FASTER_RCNN
Python version: HTTPS://GITHUB.COM/RBGIRSHICK/PY-FASTER-RCNN
This article uses the Python version, which runs under Linux .
Preparatory work:
1. Configure Caffe
This does not say much, online tutorials a lot.
2. Other considerations
This is very detailed here, take a look at it carefully. Address: https://github.com/rbgirshick/py-faster-rcnn (main content below)
Here is about to translate the contents of the above URL.
(1) Installing the Cython, python-opencv
easydict
Pip Install cythonpip install easydictapt-get install PYTHON-OPENCV
(2) Download py-faster-rcnn
# Make sure to clone with--recursivegit clone--recursive Https://github.com/rbgirshick/py-faster-rcnn.git
(3) Enter Py-faster-rcnn/lib
Execute make
(4) Enter PY-FASTER-RCNN\CAFFE-FAST-RCNN
Execute CP Makefile.config.example Makefile.config
Then, configure the Makefile.config file to refer to my configuration: Makefile.config file
After configuring the Makefile.config file, execute:
Make-j8 && make Pycaffe
(5) Download VOC2007 data set
Provide a Baidu cloud address: http://yun.baidu.com/s/1hr5SfK4
Unzip, then, place the dataset under Py-faster-rcnn\data and replace the VOC2007 DataSet with your dataset.
(6) Download the pre-trained model parameters under the Imagenet data set (for initialization)
Provide a Baidu cloud address: Http://pan.baidu.com/s/1hsxx8OW
Unzip, and then place the file under Py-faster-rcnn\data
Here are some pre-training changes.
1.py-faster-rcnn/models/pascal_voc/zf/faster_rcnn_alt_opt/stage1_fast_rcnn_train.pt modification
Layer { name: ' Data ' type: ' Python ' top: ' Data ' top: ' Rois ' top: ' labels ' top: ' Bbox_targets ' top: ' bbox_inside_weights ' top: ' bbox_outside_weights ' python_param { module: ' Roi_data_ Layer.layer ' layer: ' Roidatalayer ' param_str: ' num_classes ': #按训练集类别改, changed to category +1 }}
Layer { name: "Cls_score" type: "Innerproduct" Bottom: "fc7" Top: "Cls_score" param {lr_ mult:1.0} param {lr_mult:2.0} inner_product_param { num_output:16 #按训练集类别改, changed to class number +1 weight_ Filler { type: ' Gaussian ' std:0.01 } bias_filler { type: ' Constant ' value:0 } }}
Layer { name: "bbox_pred" type: "Innerproduct" Bottom: "fc7" Top: "bbox_pred" param {lr_mult:1.0 } param {lr_mult:2.0} inner_product_param { num_output:64 #按训练集类别改, the value is (category number +1), Weight_filler { type: "Gaussian" std:0.001 } bias_filler { type: "Constant" value:0 }}}
2.py-faster-rcnn/models/pascal_voc/zf/faster_rcnn_alt_opt/stage1_rpn_train.pt modification
Layer { name: ' Input-data ' type: ' Python ' top: ' Data ' top: ' Im_info ' top: ' gt_boxes ' python_ param { module: ' Roi_data_layer.layer ' layer: ' Roidatalayer ' param_str: ' num_classes ': + ' #按训练集类别改, The value is the number of categories +1 }}
3.py-faster-rcnn/models/pascal_voc/zf/faster_rcnn_alt_opt/stage2_fast_rcnn_train.pt modification
Layer { name: ' Data ' type: ' Python ' top: ' Data ' top: ' Rois ' top: ' labels ' top: ' Bbox_ Targets ' top: ' bbox_inside_weights ' top: ' bbox_outside_weights ' python_param { module: ' Roi_ Data_layer.layer ' layer: ' Roidatalayer ' param_str: ' num_classes ': #按训练集类别改, changed to category +1 }}
Layer { name: "Cls_score" type: "Innerproduct" Bottom: "fc7" Top: "Cls_score" param {lr_mult:1.0 } param {lr_mult:2.0} inner_product_param { num_output:16 #按训练集类别改, this value is the number of categories +1 Weight_filler { Type: "Gaussian" std:0.01 } bias_filler { type: "Constant" value:0 }}}
Layer { name: "bbox_pred" type: "Innerproduct" Bottom: "fc7" Top: "bbox_pred" param {lr_ mult:1.0} param {lr_mult:2.0} inner_product_param { num_output:64 #按训练集类别改, this value is (category number +1) Weight_filler { type: ' Gaussian ' std:0.001 } bias_filler { type: ' Constant ' value:0 } }}
4.py-faster-rcnn/models/pascal_voc/zf/faster_rcnn_alt_opt/stage2_rpn_train.pt modification
Layer { name: ' Input-data ' type: ' Python ' top: ' Data ' top: ' Im_info ' top: ' gt_boxes ' python_ param { module: ' Roi_data_layer.layer ' layer: ' Roidatalayer ' param_str: ' num_classes ': + ' #按训练集类别改, The value is the number of categories +1 }}
5.py-faster-rcnn/models/pascal_voc/zf/faster_rcnn_alt_opt/faster_rcnn_test.pt modification
Layer { name: "Cls_score" type: "Innerproduct" Bottom: "fc7" Top: "Cls_score" inner_ Product_param { num_output:16 #按训练集类别改, this value is the number of categories +1 }}
Layer { name: "bbox_pred" type: "Innerproduct" Bottom: "fc7" Top: "bbox_pred" inner_product_ param { num_output:64 #按训练集类别改, the value is (number of categories +1)} }
6.py-faster-rcnn/lib/datasets/pascal_voc.py modification
Class Pascal_voc (IMDb): def __init__ (self, image_set, year, Devkit_path=none): imdb.__init__ (Self, ' voc_ ' + yea R + image_set) self._year = year Self._image_set = Image_set Self._devkit_path = Self._get_default_pa Th () If Devkit_path is None else devkit_path Self._data_path = Os.path.join (Self._devki T_path, ' VOC ' +self._year) self._classes = (' __background__ ', # always index 0 ' your label 1 ', ' your label 2 ', ' your tag 3 ', ' Your label 4 ', )
The place to change is
To modify the training set folder:
Self._data_path = Os.path.join (Self._devkit_path, ' VOC ' +self._year)
Replace the annotations,imagesets and Jpegimages in the original VOC2007 with your data set directly.
To modify a label:
self._classes = (' __background__ ', # always index 0 ' your label 1 ', ' your label 2 ', ' your tag 3 ', ' your tag 4 ', )
Modify the label on your dataset to be OK.
7.py-faster-rcnn/lib/datasets/imdb.py modify the file by modifying the append_flipped_images (self) function to:
def append_flipped_images (self): num_images = self.num_images widths = [PIL. Image.open (Self.image_path_at (i)). Size[0] for i in Xrange (num_images)] for i in Xrange (num_images): boxes = self.roidb[i][' boxes '].copy () oldx1 = boxes[:, 0].copy () oldx2 = boxes[:, 2].copy () boxes[:, 0] = wid Ths[i]-oldx2-1 print boxes[:, 0] boxes[:, 2] = widths[i]-oldx1-1 print boxes[:, 0] assert (boxes [:, 2] >= boxes[:, 0]). All () entry = {' boxes ': boxes, ' gt_overlaps ': self.roidb[i][' gt_overlaps '], ' Gt_classes ': self.roidb[i][' gt_classes ', ' flipped ': True} self.roidb.append (entry) Self._image_ index = Self._image_index * 2
!!! To prevent mixing with the previous model, delete the output folder (or change another name) before training, and delete the files in the Py-faster-rcnn\data\cache (if any)
For settings such as the learning rate, you can set the solve file in py-faster-rcnn/models/pascal_voc/zf/faster_rcnn_alt_opt.
8. Start training
Enter PY-FASTER-RCNN, execute:
experiments/scripts/faster_rcnn_alt_opt.sh 0 ZF Pascal_voc
In this way, we start training.
9. Testing
Copy the Py-faster-rcnn\output\faster_rcnn_alt_opt\***_trainval ZF Caffemodel from the training to Py-faster-rcnn\data\faster_rcnn_ Models, and then, modify:
py-faster-rcnn\tools\demo.py, main changes:
CLASSES = (' __background__ ', ' your label 1 ', ' Your label 2 ', ' Your label 3 ', ' your Tag 4 ')
Change to your data set label;
NETS = {' Vgg16 ': (' VGG16 ', ' Vgg16_faster_rcnn_final.caffemodel '), ' ZF ': (' ZF ', ' zf_faster_rcnn_ Final.caffemodel ')}
The Caffemodel of the above ZF changed to your Caffemodel.
10. Results
Under the PY-FASTER-RCNN,
Perform:
./tools/demo.py--net ZF
FASTER-RCNN+ZF training model with its own data set (Python version)