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

Feature-request: YOLOv4-tiny #111

Open AlexeyAB opened 4 years ago

AlexeyAB commented 4 years ago

Feature-request: YOLOv4-tiny (detector)

There is required only 1 feature:

  1. Add groups= and group_id= to the [route] layer.
    [route]
    layers=-1
    groups=2
    group_id=1

So if input is WxHxC, it divides input into 2 groups WxHx(C/2) (there are 2 groups: 0 and 1), and loads the 2nd group_1 WxHx(C/2).

If there are many layers specified in layers= parameter, then this will be done for each of the input layers specified in layer=, then results will be concatenated across channels.

cmp

hunglc007 commented 4 years ago

@AlexeyAB Thanks for support. I have implemented Yolov4-tiny, but results are slighly different, sizes of boxes in my results are approximately 1.5 to 2 times smaller than that of you. I see in yolov4-tiny.cfg there is a 'resize' parameter = 1.5 in [yolo] layer. What is this mean ?

AlexeyAB commented 4 years ago

@hunglc007

Note, that both yolov3-tiny and yolov4-tiny don't use anchor 0, so they use only anchors 1-7: 1st [yolo] layer - mask = 3,4,5 2nd [yolo] layer - mask = 1,2,3

So: 1st [yolo] - layer uses anchors: 81,82, 135,169, 344,319 2nd [yolo] - layer uses anchors: 23,27, 37,58, 81,82

vinorth-v commented 3 years ago

@AlexeyAB

How should we change these parameters to make this repo work with yolov4-tiny-3l ?(https://github.com/AlexeyAB/darknet/blob/master/cfg/yolov4-tiny-3l.cfg)

config.py

#YOLO options
__C.YOLO                      = edict()

__C.YOLO.CLASSES              = "./data/classes/obj_old.names"
__C.YOLO.ANCHORS              = [12,16, 19,36, 40,28, 36,75, 76,55, 72,146, 142,110, 192,243, 459,401]
__C.YOLO.ANCHORS_V3           = [10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326]
__C.YOLO.ANCHORS_TINY         = [23,27, 37,58, 81,82, 81,82, 135,169, 344,319] # yolov4-tiny-2l.cfg (mask = 1,2,3)
#__C.YOLO.ANCHORS_TINY         = [10,14, 23,27, 37,58, 81,82, 135,169, 344,319] # yolov4-tiny-2l-custom.cfg (mask = 0,1,2)
#__C.YOLO.ANCHORS_TINY         = [12,16, 19,36, 40,28, 36,75, 76,55, 72,146, 142,110, 192,243, 459,401] # yolov4-tiny-3l-custom.cfg (mask = 0,1,2) -> not working
__C.YOLO.STRIDES              = [8, 16, 32]
__C.YOLO.STRIDES_TINY         = [16, 32]
__C.YOLO.XYSCALE              = [1.2, 1.1, 1.05]
__C.YOLO.XYSCALE_TINY         = [1.05, 1.05] #yolov4-tiny-2l
#__C.YOLO.XYSCALE_TINY         = [1.05, 1.05, 1.05] #yolov4-tiny-3l-custom.cfg -> not working
__C.YOLO.ANCHOR_PER_SCALE     = 3
__C.YOLO.IOU_LOSS_THRESH      = 0.5

yolov4.py

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)

    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]

Thank you!