ValueError: Dimension 0 in both shapes must be equal, but are 1 and 60. Shapes are [1,1,512,40] and [60,512,1,1]. for ‘Assign_55’ (op: ‘Assign’) with input shapes: [1,1,512,40], [60,512,1,1].
在网上查到遇到这个问题时大都说的是路径问题,但其实还有一个原因是,你使用的yolov3是tiny版本,导致框的个数和yolov3正式版框的个数计算方法不同
tiny版框的个数
10,14, 23,27, 37,58, 81,82, 135,169, 344,319
正式版框的个数
10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
因此在加载模型时,注意更改框的代码
tiny的num_anchors要除以2
正式版num_anchors要除以3
try:
self.yolo_model = load_model(model_path, compile=False)
except:
print('1:',model_path)
self.yolo_model = tiny_yolo_body(Input(shape=(None,None,3)), num_anchors//2, num_classes) \ # tiny的num_anchors要除以2
if is_tiny_version else yolo_body(Input(shape=(None,None,3)), num_anchors//3, num_classes) # 正式版num_anchors要除以3
self.yolo_model.load_weights(model_path)
else:
assert self.yolo_model.layers[-1].output_shape[-1] == \
num_anchors/len(self.yolo_model.output) * (num_classes + 5), \
'Mismatch between model and given anchor and class sizes'
yolo其他版本遇到该问题时应该也同上理。