david8862 / keras-YOLOv3-model-set

end-to-end YOLOv4/v3/v2 object detection pipeline, implemented on tf.keras with different technologies
MIT License
640 stars 222 forks source link

model_body.load_weights(weights_path, by_name=True) is not taking properly yolov3.h5 weights. #166

Closed chulminkw closed 3 years ago

chulminkw commented 3 years ago

Hello,

It seems like yolov3.h5 weights is not loaded into the model_body if model_body.load_weights() doesn't have skip_mismatch=True parameter value.

yolov3.h5 was made by python tools/model_converter/convert.py cfg/yolov3.cfg weights/yolov3.weights weights/yolov3.h5

In line 239~240 from yolo3.model.py if weights_path: model_body.load_weights(weights_path, by_name=True) #, skip_mismatch=True)

after I changed into skip_mismatch=True it was successfully loaded.

vse-motec commented 3 years ago

Hello chulminkw, are you using the setup with 80 classes? The yolov3.h5 is created from yolov3.weights (as you did) which is trained on COCO with 80 classes as output. If you change the number of classes in your model then you need to use skip_mismatch=True. Otherwise (i.e. with 80 classes) the model should be loaded correctly. Please check this in your setup and report your findings.

chulminkw commented 3 years ago

Hello vse-motec Thanks for the info. I thought skip_masmatch should be True to work with yolo models which don't have 80 classes. That way, layers other than prediction layers would have weights with yolov3.h5. Currently, it gives an error message without loading weights if the model doesn't have 80 classes.

vse-motec commented 3 years ago

I thought skip_masmatch should be True to work with yolo models which don't have 80 classes. That way, layers other than prediction layers would have weights with yolov3.h5.

This is correct. Maybe my answer was not that clear.

If you have a model with 80 classes your model should load correctly even without skip_mismatch=True. If you change the number of classes e.g. for transfer learning, then use skip_mismatch=True. In this case the prediction layers will not be loaded, which is not bad, since you will transfer learn them anyway.

vse-motec commented 3 years ago

@chulminkw please close this issue if you feel that your issues have been resolved

chulminkw commented 3 years ago

Thanks vse-motec