Faster RCNN 训练自己的检测模型
来源:互联网 发布:c语言求绝对值的函数 编辑:程序博客网 时间:2024/04/28 07:42
Faster RCNN 训练自己的检测模型
一、准备自己的训练数据
根据pascal VOC 2007的训练数据集基本架构,第一步,当然是要准备自己的训练图片集,本文直接将自己的准备的图片集(.jpg)扔到如下文件夹下:
$(py-faster-rcnn)/data/VOCdevkit2007/VOC2007/JPEGImages
第二步,根据上述自己的要训练检测的物体图片集,标注相应的.xml文件(我是自己写了一个简单的矩形框标注工具,生成相应的xml文件,在网上找了很久也没找到相应的标注工具,后来只能自己写了),同样与VOC 2007的数据集中的xml文件放在一起,文件夹路径如下:
$(py-faster-rcnn)/data/VOCdevkit2007/VOC2007/Annotations
二、修改训练程序
file1:$(py-faster-rcnn)/models/ZF/faster_rcnn_alt_opt/stage1_fast_rcnn_train.pt
file2:$(py-faster-rcnn)/models/ZF/faster_rcnn_alt_opt/stage2_fast_rcnn_train.pt
file3:$(py-faster-rcnn)/models/ZF/faster_rcnn_alt_opt/stage1_rpn_train.pt
file4:$(py-faster-rcnn)/models/ZF/faster_rcnn_alt_opt/stage2_rpn_train.pt
上述两个pt文件,所要更改的地方基本一样,均是更改num_output的值,由于原来是21类物体检测,本文加入了自己的一类物体进行训练,故由原来的21变成22即可,下面一层相应的变为88。
name: "ZF"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': 22" }}......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: 22 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: 88 weight_filler { type: "gaussian" std: 0.001 } bias_filler { type: "constant" value: 0 } }}
file5:$(py-faster-rcnn)/lib/datasets/pascal_voc.py
在下面代码中×××处添加自己加入的类即可。
def __init__(self, image_set, year, devkit_path=None): datasets.imdb.__init__(self, 'voc_' + year + '_' + image_set) self._year = year self._image_set = image_set self._devkit_path = self._get_default_path() if devkit_path is None \ else devkit_path self._data_path = os.path.join(self._devkit_path, 'VOC' + self._year) 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','×××')
参考资料:
https://github.com/rbgirshick/py-faster-rcnn/issues/34
三、训练过程中错误
error 1:assert (boxes[:, 2] >= boxes[:, 0]).all()
Process Process-1:Traceback (most recent call last):File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrapself.run()File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in runself._target(self._args, *self._kwargs)File "./tools/train_faster_rcnn_alt_opt.py", line 123, in train_rpnroidb, imdb = get_roidb(imdb_name)File "./tools/train_faster_rcnn_alt_opt.py", line 68, in get_roidbroidb = get_training_roidb(imdb)File "/home/microway/test/pytest/py-faster-rcnn/tools/../lib/fast_rcnn/train.py", line 121, in get_training_roidbimdb.append_flipped_images()File "/home/microway/test/pytest/py-faster-rcnn/tools/../lib/datasets/imdb.py", line 108, in append_flipped_imagesassert (boxes[:, 2] >= boxes[:, 0]).all()AssertionError
error1 解决办法:
将py-faster-rcnn/lib/datasets/imdb.py中的相应代码改成如下代码即可:
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] = widths[i] - oldx2 - 1 boxes[:, 2] = widths[i] - oldx1 - 1 for b in range(len(boxes)): if boxes[b][2] < boxes[b][0]: boxes[b][0] = 0 assert (boxes[:, 2] >= boxes[:, 0]).all()
error 2:IndexError: list index out of range
File "./tools/train_net.py", line 85, in roidb = get_training_roidb(imdb)File "/usr/local/fast-rcnn/tools/../lib/fast_rcnn/train.py", line 111, in get_training_roidbrdl_roidb.prepare_roidb(imdb)File "/usr/local/fast-rcnn/tools/../lib/roi_data_layer/roidb.py", line 23, in prepare_roidbroidb[i]['image'] = imdb.image_path_at(i)IndexError: list index out of range
error2 解决办法:
删除fast-rcnn-master/data/cache/ 文件夹下的.pkl文件,或者改名备份,重新训练即可。
参考资料:
https://github.com/rbgirshick/py-faster-rcnn/issues/34
https://github.com/rbgirshick/fast-rcnn/issues/79
0 0
- Faster RCNN 训练自己的检测模型
- Faster RCNN 训练自己的检测模型
- 使用faster rcnn训练自己的模型
- 使用faster-rcnn训练自己的模型
- Faster RCNN 模型训练及检测
- Faster RCNN 模型训练及检测
- py-faster-rcnn用自己的数据训练模型
- 训练自己的数据,微调faster Rcnn模型
- py-faster-rcnn用自己的数据训练模型
- 用自己的数据训练Faster-RCNN
- faster-rcnn安装,训练自己的数据
- Faster RCNN 训练自己的数据集
- Faster-rcnn训练自己的数据库
- Faster-RCNN训练自己的数据集
- Faster-RCNN训练自己的数据集
- py-faster-rcnn训练自己的数据
- faster rcnn 训练自己的数据
- faster Rcnn训练自己的数据集
- TP:C319327B
- FPGA笔记 AS和JTAG下载方式区别
- 基于Simulink的Ziegler-Nichols PID参数经验整定法
- Windows程序设计-学习第一天
- ggplot2 保存图片 字体不协调
- Faster RCNN 训练自己的检测模型
- java下载服务器资源
- C++程序设计课后习题及解答(第一章)
- Cocos2d-x编译Android环境
- linux 下 docker NGINX+PHP+MYSQL+REDIS+Elasticsearch 开发环境搭建
- JAVA上百实例源码以及开源项目
- Eclipse - JRebel
- EA使用笔记 UML
- PHP输出二维数组