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 index

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_WEIGHTS

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

 解決完上一個問題后,又出現 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行:

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 類型,這種類型的數據不能作為索引,所以必須對其進行強制類型轉換,轉化結果如下:

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM