训练和测试 Faster R-CNN 模型中遇到的问题

最近使用自己标注的数据集用 Faster R-CNN 训练了两个模型:VGG16 和 ResNet-50 ,在训练和测试的时候还是踩了很多坑,把遇到的问题及解决方法总结了一下,以供以后回顾。


一、训练

1.错误:./tools/train_faster_rcnn_end2end.py is not found
执行文件的位置不正确,注意所有的命令最好都在 faster rcnn 的根目录中执行。

2.错误:’module’ object has no attribute ‘text_format’
./lib/fast_rcnn/train.py 文件里添加 import google.protobuf.text_format

3.错误:TypeError: ‘numpy.float64’ object cannot be interpreted as an index
这个错误有人说可以降低 numpy 的版本来解决,本人试了,但还会报其他的错误,所以并不能算解决。
因为新版的 numpy 不能使用 float 类型来进行索引了,解决方法:转换类型
1./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)

2./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)

3./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)

4./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)
# 在123行起:
    for ind in inds:
        cls = clss[ind]
        start = 4 * cls
        end = start + 4
# 修改为:
    for ind in inds:
        ind = int(ind)
        cls = clss[ind]
        start = int(4 * cls)
        end = int(start + 4)

猜你喜欢

转载自blog.csdn.net/weixin_39679367/article/details/80941624