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
相關文章
相關標籤/搜索