ValueError: Dimension 0 in both shapes must be equal, but are 1 and 60. Shapes are [1,1,512,40]可能的解法

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其他版本遇到该问题时应该也同上理。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值