fizyr / keras-retinanet

Keras implementation of RetinaNet object detection.
Apache License 2.0
4.38k stars 1.96k forks source link

Add compatibility for Keras 2.4 #1422

Closed cbodenst closed 4 years ago

cbodenst commented 4 years ago

@hgaiser I also experienced that loading old models will not work with this version. I had a look into the h5 files and in my older models the anchors does not seem to have any weights while models created with this PR have:

Old model:

...
b'C6_relu' []
b'P3' [b'P3/kernel:0' b'P3/bias:0']
b'P4' [b'P4/kernel:0' b'P4/bias:0']
b'P5' [b'P5/kernel:0' b'P5/bias:0']
b'P7' [b'P7/kernel:0' b'P7/bias:0']
b'anchors_0' []
b'anchors_1' []
b'anchors_2' []
b'anchors_3' []
b'anchors_4' []
b'regression_submodel' [b'pyramid_regression_0/kernel:0' b'pyramid_regression_0/bias:0'
 b'pyramid_regression_1/kernel:0' b'pyramid_regression_1/bias:0'
 b'pyramid_regression_2/kernel:0' b'pyramid_regression_2/bias:0'
 b'pyramid_regression_3/kernel:0' b'pyramid_regression_3/bias:0'
 b'pyramid_regression/kernel:0' b'pyramid_regression/bias:0']
b'anchors' []
b'regression' []
b'boxes' []
b'classification_submodel' [b'pyramid_classification_0/kernel:0' b'pyramid_classification_0/bias:0'
...

new_model

...
b'C6_relu' []
b'P3' [b'P3/kernel:0' b'P3/bias:0']
b'P4' [b'P4/kernel:0' b'P4/bias:0']
b'P5' [b'P5/kernel:0' b'P5/bias:0']
b'P7' [b'P7/kernel:0' b'P7/bias:0']
b'anchors_0' [b'Variable:0']
b'anchors_1' [b'Variable:0']
b'anchors_2' [b'Variable:0']
b'anchors_3' [b'Variable:0']
b'anchors_4' [b'Variable:0']
b'regression_submodel' [b'pyramid_regression_0/kernel:0' b'pyramid_regression_0/bias:0'
 b'pyramid_regression_1/kernel:0' b'pyramid_regression_1/bias:0'
 b'pyramid_regression_2/kernel:0' b'pyramid_regression_2/bias:0'
 b'pyramid_regression_3/kernel:0' b'pyramid_regression_3/bias:0'
 b'pyramid_regression/kernel:0' b'pyramid_regression/bias:0']
b'anchors' []
b'regression' []
b'boxes' []
b'classification_submodel' [b'pyramid_classification_0/kernel:0' b'pyramid_classification_0/bias:0'
...

I thing this is somehow related to the newer keras/tensorflow version. Can you explain where these weights comes from?

hgaiser commented 4 years ago

I think that's because tensorflow / keras started identifying the self.anchors as weights that it must save, which it shouldn't. Maybe there is a better workaround, but I have done this in a different project to circumvent this issue: https://github.com/fizyr/tf-retinanet/commit/d86be7591b7aa2d17ddb1fb7025aa709b4e441f0

hgaiser commented 4 years ago

Considering the checks seem to pass, I say let's merge this. Thank you for the effort @cbodenst .