tensorflow-yolo-v3 icon indicating copy to clipboard operation
tensorflow-yolo-v3 copied to clipboard

Wrong height and width order in _upsample(inputs, out_shape, data_format='NCHW')

Open onion233 opened this issue 5 years ago • 5 comments

Hi, I first convert darknet weights to .pb with 416x416 input size, which is successful. However, when I tried to convert weights with (None, 224, 320, 3 ), which is NHWC format, convert_weights_pb.py reports error: tensorflow.python.framework.errors_impl.InvalidArgumentError: Dimension 1 in both shapes must be equal, but are 20 and 14. Shapes are [?,20,14] and [?,14,20]. for 'detector/yolo-v3-tiny/concat_3' (op: 'ConcatV2') with input shapes: [?,20,14,128], [?,14,20,256], [] and with computed input tensors: input[2] = <3>.

This error happens when the feature map data format is changed after upsampling. So I took a look at function _upsample(inputs, out_shape, data_format='NCHW'). I believe for NHWC format, the output shape is: new_height = out_shape[1] new_width = out_shape[2] instead of your oder. After this change, the weights can be successfully converted.

Please point out if I make any mistakes.

onion233 avatar Apr 22 '19 09:04 onion233

However, in this way, it produces a lot of false positives. :(

onion233 avatar Apr 22 '19 10:04 onion233

However, in this way, it produces a lot of false positives. :(

hello , I have met this same pro, my input is (608,416), have u fixed this pro,? if yes please tell me , help the children!

yurui777 avatar Jan 08 '20 10:01 yurui777

Hi is there any update on this issue? thanks!

dickyadrian avatar Apr 09 '20 02:04 dickyadrian

Hi, Try to patch _upsample function (yolo_v3.py file), it seems there is a bug with the indexes

    if data_format == 'NCHW':
        new_height = out_shape[2]
        new_width = out_shape[3]
    else:
        new_height = out_shape[1]
        new_width = out_shape[2]

c-carrasco avatar May 19 '20 17:05 c-carrasco

Hi, I first convert darknet weights to .pb with 416x416 input size, which is successful. However, when I tried to convert weights with (None, 224, 320, 3 ), which is NHWC format, convert_weights_pb.py reports error: tensorflow.python.framework.errors_impl.InvalidArgumentError: Dimension 1 in both shapes must be equal, but are 20 and 14. Shapes are [?,20,14] and [?,14,20]. for 'detector/yolo-v3-tiny/concat_3' (op: 'ConcatV2') with input shapes: [?,20,14,128], [?,14,20,256], [] and with computed input tensors: input[2] = <3>.

This error happens when the feature map data format is changed after upsampling. So I took a look at function _upsample(inputs, out_shape, data_format='NCHW'). I believe for NHWC format, the output shape is: new_height = out_shape[1] new_width = out_shape[2] instead of your oder. After this change, the weights can be successfully converted.

Please point out if I make any mistakes.

Hi, I have sent an email to you about this question. Can you help me? tks

KuoEuran avatar Jun 13 '21 03:06 KuoEuran