日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Faster RCNN 训练自己的检测模型

發布時間:2024/9/21 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Faster RCNN 训练自己的检测模型 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Faster RCNN 訓練自己的檢測模型

一、準備自己的訓練數據

根據pascal VOC 2007的訓練數據集基本架構,第一步,當然是要準備自己的訓練圖片集,本文直接將自己的準備的圖片集(.jpg)扔到如下文件夾下:

$(py-faster-rcnn)/data/VOCdevkit2007/VOC2007/JPEGImages
  • 1
  • 1

第二步,根據上述自己的要訓練檢測的物體圖片集,標注相應的.xml文件(我是自己寫了一個簡單的矩形框標注工具,生成相應的xml文件,在網上找了很久也沒找到相應的標注工具,后來只能自己寫了),同樣與VOC 2007的數據集中的xml文件放在一起,文件夾路徑如下:

$(py-faster-rcnn)/data/VOCdevkit2007/VOC2007/Annotations
  • 1
  • 1

二、修改訓練程序

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: 22weight_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: 88weight_filler {type: "gaussian"std: 0.001}bias_filler {type: "constant"value: 0}} }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57

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 = yearself._image_set = image_setself._devkit_path = self._get_default_path() if devkit_path is None \else devkit_pathself._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','×××')
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

參考資料:
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 _bootstrap self.run() File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run self._target(self._args, *self._kwargs) File "./tools/train_faster_rcnn_alt_opt.py", line 123, in train_rpn roidb, imdb = get_roidb(imdb_name) File "./tools/train_faster_rcnn_alt_opt.py", line 68, in get_roidb roidb = get_training_roidb(imdb) File "/home/microway/test/pytest/py-faster-rcnn/tools/../lib/fast_rcnn/train.py", line 121, in get_training_roidb imdb.append_flipped_images() File "/home/microway/test/pytest/py-faster-rcnn/tools/../lib/datasets/imdb.py", line 108, in append_flipped_images assert (boxes[:, 2] >= boxes[:, 0]).all() AssertionError
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

error1 解決辦法:

將py-faster-rcnn/lib/datasets/imdb.py中的相應代碼改成如下代碼即可:

def append_flipped_images(self):num_images = self.num_imageswidths = [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 - 1boxes[:, 2] = widths[i] - oldx1 - 1for b in range(len(boxes)):if boxes[b][2] < boxes[b][0]:boxes[b][0] = 0assert (boxes[:, 2] >= boxes[:, 0]).all()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

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_roidb rdl_roidb.prepare_roidb(imdb) File "/usr/local/fast-rcnn/tools/../lib/roi_data_layer/roidb.py", line 23, in prepare_roidb roidb[i]['image'] = imdb.image_path_at(i) IndexError: list index out of range
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

error2 解決辦法:

刪除fast-rcnn-master/data/cache/ 文件夾下的.pkl文件,或者改名備份,重新訓練即可。

參考資料:
https://github.com/rbgirshick/py-faster-rcnn/issues/34
https://github.com/rbgirshick/fast-rcnn/issues/79

總結

以上是生活随笔為你收集整理的Faster RCNN 训练自己的检测模型的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。