Faster RCNN 训练中的一些问题及解决办法
今天使用Faster RCNN訓練自己的數據的時候,出現了一些因為boost或者是numpy版本不兼容導致的問題,經過各種查資料和求助大神,總算是順利把網絡跑起來了。下面內容都是今天親測出現的問題并與其對應的解決方案,和大家一起分享,也便于我以后查看。
訓練方法:在配置好Faster RCNN之后,準備好自己的數據,修改網絡的配置文件和相應的訓練腳本滿,使用end to end 的訓練方法,在$py-faster-rcnn的根目錄下執行:./experiments/scripts/faster_rcnn_end2end.sh 0 VGG16 pascal_voc 。以下都是執行該腳本后出現的問題。
Problem 1
AttributeError: 'module' object has no attribute ‘text_format'- 1
- 1
解決方法:在/home/xxx/py-faster-rcnn/lib/fast_rcnn/train.py的頭文件導入部分加上 :import google.protobuf.text_format
Problem 2
TypeError: 'numpy.float64' object cannot be interpreted as an index- 1
- 1
這里是因為numpy版本不兼容導致的問題,最好的解決辦法是卸載你的numpy,安裝numpy1.11.0。如果你和筆者一樣不是服務器的網管,沒有權限的話,就只能自己想辦法解決了。
修改如下幾個地方的code:
1) /home/xxx/py-faster-rcnn/lib/roi_data_layer/minibatch.py
將第26行:fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image) 改為:fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image).astype(np.int)- 1
- 2
- 1
- 2
2) /home/xxx/py-faster-rcnn/lib/datasets/ds_utils.py
將第12行:hashes = np.round(boxes * scale).dot(v) 改為:hashes = np.round(boxes * scale).dot(v).astype(np.int)- 1
- 2
- 1
- 2
3) /home/xxx/py-faster-rcnn/lib/fast_rcnn/test.py
將第129行: hashes = np.round(blobs['rois'] * cfg.DEDUP_BOXES).dot(v) 改為: hashes = np.round(blobs['rois'] * cfg.DEDUP_BOXES).dot(v).astype(np.int)- 1
- 2
- 1
- 2
4) /home/xxx/py-faster-rcnn/lib/rpn/proposal_target_layer.py
將第60行:fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image) 改為:fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image).astype(np.int)- 1
- 2
- 1
- 2
Problem3
TypeError: slice indices must be integers or None or have an __index__ method- 1
- 1
這里還是因為numpy版本的原因,最好的解決辦法還是換numpy版本(見problem2),但同樣也有其他的解決辦法。
修改 /home/lzx/py-faster-rcnn/lib/rpn/proposal_target_layer.py,轉到123行:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
這里的ind,start,end都是 numpy.int 類型,這種類型的數據不能作為索引,所以必須對其進行強制類型轉換,轉化結果如下:
for ind in inds:ind = int(ind)cls = clss[ind]start = int(4 * cos)end = int(start + 4)bbox_targets[ind, start:end] = bbox_target_data[ind, 1:]bbox_inside_weights[ind, start:end] = cfg.TRAIN.BBOX_INSIDE_WEIGHTSreturn bbox_targets, bbox_inside_weights- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
以上內容是筆者在訓練自己的datasets時候出現的一些問題,大部分還是因為Faster RCNN 發布的時候使用的一些庫現在都升級了,所以需要對代碼中一些細節進行修改!
總結
以上是生活随笔為你收集整理的Faster RCNN 训练中的一些问题及解决办法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CNN几种经典模型比较
- 下一篇: 深度学习Caffe实战笔记(19)Win