TypeError: 'numpy.float64' object cannot be interpreted as an index

在训练stage1 rpn时,出现'numpy.float64' object cannot be interpreted as an index 的提示错误,几乎全部的博客中都指出,须要更换numpy 的版本,照作以后,出现ImportError: numpy.core.multiarray failed to import,这个问题又是numpy不匹配形成的,这样就造成了恶性循环,因此,能够考虑从根源上解决'numpy.float64' object cannot be interpreted as an indexide

TypeError: 'numpy.float64' object cannot be interpreted as an index 

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)
第174,175行改成:

for ind in inds:
cls = clss[ind]
start =int( 4 * cls)
end = int(start + 4)
bbox_targets[ind, start:end] = bbox_target_data[ind, 1:]
bbox_inside_weights[ind, start:end] = cfg.TRAIN.BBOX_INSIDE_WEIGHTSget

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)

3) /home/xxx/py-faster-rcnn/lib/fast_rcnn/test.pyhash

将第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) /home/xxx/py-faster-rcnn/lib/rpn/proposal_target_layer.pyast

将第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)

 解决完上一个问题后,又出现 TypeError: slice indices must be integers or None or have an __index__ method的问题,若是没有改变numpy的版本,
修改 /home/XXX/py-faster-rcnn/lib/rpn/proposal_target_layer.py,转到123行:test

for ind in inds:
        cls = clss[ind]
        start = 4 * cls
        end = start + 4
        bbox_targets[ind, start:end] = bbox_target_data[ind, 1:]
        bbox_inside_weights[ind, start:end] = cfg.TRAIN.BBOX_INSIDE_WEIGHTS
    return bbox_targets, bbox_inside_weights

这里的ind,start,end都是 numpy.int 类型,这种类型的数据不能做为索引,因此必须对其进行强制类型转换,转化结果以下:import

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_WEIGHTS
    return bbox_targets, bbox_inside_weight
相关文章
相关标签/搜索