mystic123 / tensorflow-yolo-v3

Implementation of YOLO v3 object detector in Tensorflow (TF-Slim)
https://medium.com/@pawekapica_31302/implementing-yolo-v3-in-tensorflow-tf-slim-c3c55ff59dbe
Apache License 2.0
893 stars 353 forks source link

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

Open onion233 opened 5 years ago

onion233 commented 5 years ago

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 commented 5 years ago

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

yurui777 commented 4 years ago

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!

dickyadrian commented 4 years ago

Hi is there any update on this issue? thanks!

c-carrasco commented 4 years ago

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]
KuoEuran commented 3 years ago

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