ValueError: total size of new array must be unchanged

   在对数据增强后的faster rcnn中进行训练时,出现这个错误,原因是在lib/roi_data_layer/layer.py中,会出现

inds = np.reshape(inds, (-1,2))
因此有效的roidb需为偶数。
参考https://github.com/rbgirshick/py-faster-rcnn/issues/61可处理数据奇偶问题
#inds = np.reshape(inds, (-1, 2))
    #row_perm = np.random.permutation(np.arange(inds.shape[0]))
    #inds = np.reshape(inds[row_perm, :], (-1,))

    # consider the case when len(inds) is odd
    isodd = len(inds) % 2
    if not isodd:
        inds = np.reshape(inds, (-1,2))
    else:
        tail = inds[-1]
        inds = np.reshape(inds[:-1], (-1,2))
    row_perm = np.random.permutation(np.arange(inds.shape[0]))
    inds = np.reshape(inds[row_perm, :], (-1,))
    if isodd:
        inds = np.append(inds, tail)
    self._perm = inds

 

 
posted @ 2017-08-16 11:47  牧马人夏峥  阅读(1784)  评论(0编辑  收藏  举报