使用faster rcnn训练自己的数据(py-faster-rcnn )

来源:互联网 发布:mac itunes怎么下载 编辑:程序博客网 时间:2024/05/17 02:32

出于在csdn上面学到很多东西这里也帮自己的一些收获和大家分享一下    

直奔主题~~

前提是已经安装好caffe的环境 本文是在Ubuntu 15.04下做的测试 $Faster_rcnn表示py-faster-rcnn根目录

1. 修改数据接口 ($Faster_rcnn/lib/datasets

     目录下面的pascal_voc.py是主要的数据读取接口

  •      self._classes = ('__background__', # always index 0
                        'aeroplane', 'bicycle', 'bird', 'boat',
                        'bottle', 'bus', 'car', 'cat', 'chair',
                       'cow', 'diningtable', 'dog', 'horse',
                         'motorbike', 'person', 'pottedplant',
                        'sheep', 'sofa', 'train', 'tvmonitor')

            这里定义了要训练的类别,修改这里为自己需要训练数据的类标签,注意总类别包括背景

  • 如果需要使用PASCAL数据库中的个别类 需要在
         def _load_pascal_annotation(self, index):中添加一句
          if not self.config['use_diff']:
            # Exclude the samples labeled as difficult
            non_diff_objs = [
                obj for obj in objs if int(obj.find('difficult').text) == 0]
            # if len(non_diff_objs) != len(objs):
            #     print 'Removed {} difficult objects'.format(
            #         len(objs) - len(non_diff_objs))
            objs = non_diff_objs

########################################
valid_class_objs = [
               obj for obj in objs if obj.find('name').text in self._classes]
objs = valid_class_objs
########################################
        num_objs = len(objs)
        添加#两行中间部分

2. 修改模型参数($Faster_rcnn/models/pascal_voc)

    其中有三种网络模型 VGG16 ZF VGG_CNN_M_1024

    硬件需要参考RGB大神写的

  Requirements: hardware

  1.  For training smaller networks (ZF, VGG_CNN_M_1024) a good GPU (e.g., Titan, K20, K40, ...) with at least 3G of memory suffices
  2. For training Fast R-CNN with VGG16, you'll need a K40 (~11G of memory)
根据原作者博文主要有个版本的训练方法 
每种训练方法都需要对训练和测试的prototxt文件中涉及到类个数进行修改,原pascal数据库有21一个类别,一个简单的方法就是把所有文件中21编程你需要训练的类别,84变为你需要训练类别的4倍

Usage

To train and test a Faster R-CNN detector using the alternating optimization algorithm from our NIPS 2015 paper, useexperiments/scripts/faster_rcnn_alt_opt.sh. Output is written underneath $FRCN_ROOT/output.

cd $FRCN_ROOT./experiments/scripts/faster_rcnn_alt_opt.sh [GPU_ID] [NET] [--set ...]# GPU_ID is the GPU you want to train on# NET in {ZF, VGG_CNN_M_1024, VGG16} is the network arch to use# --set ... allows you to specify fast_rcnn.config options, e.g.#   --set EXP_DIR seed_rng1701 RNG_SEED 1701

("alt opt" refers to the alternating optimization training algorithm described in the NIPS paper.)

To train and test a Faster R-CNN detector using the approximate joint training method, useexperiments/scripts/faster_rcnn_end2end.sh. Output is written underneath $FRCN_ROOT/output.

cd $FRCN_ROOT./experiments/scripts/faster_rcnn_end2end.sh [GPU_ID] [NET] [--set ...]# GPU_ID is the GPU you want to train on# NET in {ZF, VGG_CNN_M_1024, VGG16} is the network arch to use# --set ... allows you to specify fast_rcnn.config options, e.g.#   --set EXP_DIR seed_rng1701 RNG_SEED 1701
参考
https://github.com/rbgirshick/py-faster-rcnn


1 0
原创粉丝点击