hhk7734 / tensorflow-yolov4

YOLOv4 Implemented in Tensorflow 2.
MIT License
136 stars 75 forks source link

Model and weights file do not match #64

Closed einareinarsson closed 3 years ago

einareinarsson commented 3 years ago

I tried to train a new model based on the existing yolov4.weights (257.7 MB) by the following:

yolo = YOLOv4(tiny=False)
yolo.classes = CLASSES_FILE
yolo.input_size = (416, 416)
yolo.batch_size = 16
yolo.make_model()
yolo.load_weights("yolov4.weights", weights_type="yolo")

with the following error:

ValueError: Model and weights file do not match.

I cannot figure out what could be the problem. Training started with yolo4-tiny.conv.29 works fine, however (although instantiating YOLOv4 with tiny=False this time seems no effect at all, still works).

hhk7734 commented 3 years ago

What is yolov4 version?

python3 -m pip show yolov4
einareinarsson commented 3 years ago

2.1.0 By the way, can I realistically expect better performance using the larger architecture?

hhk7734 commented 3 years ago

print(len(yolo.classes)) is it 80?

larger? did you mean yolov4 vs yolov4-tiny? and performance? FPS? accuracy? recall?

einareinarsson commented 3 years ago

len(yolo.classes)is 12. By "larger" I mean yolov4. By performance mAP for example.

hhk7734 commented 3 years ago

257,717,640 bytes weight is for 80 classes.

yolov4 mAP50 is 60~. yolov4-tiny mAP50 is 30~.

https://wiki.loliot.net/docs/lang/python/libraries/yolov4/python-yolov4-about#performance

einareinarsson commented 3 years ago

I see. But again, in case of yolo4-tiny.conv.29 changing the number of classes works just fine. Does it mean that training with len(yolo.classes) != 80 works with tiny YOLOv4, but not with large YOLOv4? Doesn't it make training option for large YOLOv4 senseless?

hhk7734 commented 3 years ago

yolov4.conv.137 is for yolov4.

anyway, the number of classes affects on neck layer.

Ex) https://github.com/hhk7734/tensorflow-yolov4/blob/4f75970d02b60960257f9f7baa091e0e6874a890/py_src/yolov4/model/neck.py#L135-L140

yolov4.conv.137 or yolo4-tiny.conv.29 is extracted only from the first layer to the part that is not affected by the number of classes.