hunglc007 / tensorflow-yolov4-tflite

YOLOv4, YOLOv4-tiny, YOLOv3, YOLOv3-tiny Implemented in Tensorflow 2.0, Android. Convert YOLO v4 .weights tensorflow, tensorrt and tflite
https://github.com/hunglc007/tensorflow-yolov4-tflite
MIT License
2.23k stars 1.24k forks source link

yolov4-tiny structure does not match darknet cfg. #437

Closed ryotaro137 closed 2 years ago

ryotaro137 commented 2 years ago

When I tried to convert the yolov4-tiny model to tflite, I guessed that the arguments in yolov4.py were different. The real yolov4-tiny model is as follows

image

ref

In the diagram above, the part to be concatted is taken from the second CSPBlock in CSPdarknet53-tiny. On the other hand, . route_1 of def YOLOv4_tiny in /core/yolov4.py is after going through all of CSPdarknet53-tiny in the above figure.

def YOLOv4_tiny(input_layer, NUM_CLASS):
    route_1, conv = backbone.cspdarknet53_tiny(input_layer)

    conv = common.convolutional(conv, (1, 1, 512, 256))

    conv_lobj_branch = common.convolutional(conv, (3, 3, 256, 512))
    conv_lbbox = common.convolutional(conv_lobj_branch, (1, 1, 512, 3 * (NUM_CLASS + 5)), activate=False, bn=False)

    conv = common.convolutional(conv, (1, 1, 256, 128))
    conv = common.upsample(conv)
    conv = tf.concat([conv, route_1], axis=-1) # this route1 sholud indicate second CSPBlocks 

    conv_mobj_branch = common.convolutional(conv, (3, 3, 128, 256))
    conv_mbbox = common.convolutional(conv_mobj_branch, (1, 1, 256, 3 * (NUM_CLASS + 5)), activate=False, bn=False)

    return [conv_mbbox, conv_lbbox]

This leads me to believe that the point where tf.concat is done may be wrong.

I just don't understand it very well, but I would appreciate it if you could let me know. Thank you in advance.

ryotaro137 commented 2 years ago

I was mistaken. I am very sorry.