ValueError: could not broadcast input array from shape (300,2,300,1) into shape (300,2,1,1)


用inception-V4做RFCN的网络来训练目标检测模型,遇到的问题如下:

_### File "./tools/demo_inception.py", line 378, in 
= im_detect(net, im)
File "/home/hytz/Downloads/DB-R-FCN_scale_4/tools/../lib/fast_rcnn/test.py", line 173, in im_detect
pred_boxes = bbox_transform_inv(boxes, box_deltas)
File "/home/hytz/Downloads/DB-R-FCN_scale_4/tools/../lib/fast_rcnn/bbox_transform.py", line 53, in./lib/fast_rcnn/bbox_transform.py
pred_boxes[:, 0::4] = pred_ctr_x - 0.5 * pred
w
ValueError: could not broadcast input array from shape (300,2,300,1) into shape (300,2,1,1)


box_deltas应该为二维numpy,但实际是四维的,打印box_deltas.shape为(300,8,1,1),由于3/4维度都是1,所以把数组转至二维就可以了

解决:

./lib/fast_rcnn/bbox_transform.py 的 bbox_transform.py函数中,添加如下:

def bbox_transform_inv(boxes, deltas):
    deltas = np.squeeze(deltas) ######ADD
    if boxes.shape[0] == 0:
        return np.zeros((0, deltas.shape[1]), dtype=deltas.dtype)
    boxes = boxes.astype(deltas.dtype, copy=False)
并且im_detect()返回的scores也要做同样处理。

你可能感兴趣的:(深度学习;目标检测)