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

Bounding boxes larger than expected with yolov4-tiny #174

Closed vinorth-v closed 4 years ago

vinorth-v commented 4 years ago

Hello,

I don't understand, the results are perfect with my darknet model but after converting to TF, the detection results are two times bigger for the bounding boxes. Do I need to change something in your code?

Thanks

terminate25 commented 4 years ago

i think your anchor box may be difference, please check your config file (trained by darknet) and your config (when convert to saved model). They must be the same

vinorth-v commented 4 years ago

Thank you for your answer, I am using this config file https://github.com/AlexeyAB/darknet/blob/master/cfg/yolov4-tiny-custom.cfg which is a bit different from the default one: https://github.com/AlexeyAB/darknet/blob/master/cfg/yolov4-tiny.cfg

The anchor parameter is same as default one (anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319). However, the mask parameter is different, so how can I change it?

In fact, mask = 0,1,2 (instead of mask = 1,2,3)

Also, I only have 4 classes so filters=27 (instead of filters=255 before the 2-yolo layers).

vinorth-v commented 4 years ago

Should I change something here or somewhere else?

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] 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] C.YOLO.ANCHOR_PER_SCALE = 3 C.YOLO.IOU_LOSS_THRESH = 0.5

terminate25 commented 4 years ago

Please try to change this parameter: __C.YOLO.ANCHORS_TINY = [23,27, 37,58, 81,82, 81,82, 135,169, 344,319] to __C.YOLO.ANCHORS_TINY = [10,14, 23,27, 37,58, 81,82, 135,169, 344,319] and re-convert your saved model Hope this help !

vinorth-v commented 4 years ago

Thank you very much for your help @terminate25 , it works properly now!

Do you also have an idea on how to modify config.py in order to use this config file : https://github.com/AlexeyAB/darknet/blob/master/cfg/yolov4-tiny-3l.cfg

In fact, with 3 yolo-layers, the detection results are two times smaller for the bounding boxes now.

Thank you in advance!