keras_to_tensorflow icon indicating copy to clipboard operation
keras_to_tensorflow copied to clipboard

Error: ('Keyword argument not understood:', 'freeze') while trying to convert RetinaNet (.h5) --> (.pb)

Open rajanksin opened this issue 7 years ago • 7 comments

I downloaded a pre trained Keras model from: https://github.com/fizyr/keras-retinanet/releases/download/0.4.1/resnet50_coco_best_v2.1.0.h5

Keras and Tensorflow version:

>>> import keras as k
Using TensorFlow backend.
>>> k.__version__
'2.2.0'

>>> import tensorflow as tf
>>> tf.__version__
'1.8.0'
>>>

I tried with keras version 2.1.0 too, get the same error.

I get the error with command: python keras_to_tensorflow.py -input_model_file resnet50_coco_best_v2.1.0.h5

Traceback (most recent call last):
  File "keras_to_tensorflow.py", line 114, in <module>
    net_model = load_model(weight_file_path)
  File "/Users/srajanku/anaconda2/envs/retina-test/lib/python3.6/site-packages/keras/engine/saving.py", line 261, in load_model
    model = model_from_config(model_config, custom_objects=custom_objects)
  File "/Users/srajanku/anaconda2/envs/retina-test/lib/python3.6/site-packages/keras/engine/saving.py", line 335, in model_from_config
    return deserialize(config, custom_objects=custom_objects)
  File "/Users/srajanku/anaconda2/envs/retina-test/lib/python3.6/site-packages/keras/layers/__init__.py", line 55, in deserialize
    printable_module_name='layer')
  File "/Users/srajanku/anaconda2/envs/retina-test/lib/python3.6/site-packages/keras/utils/generic_utils.py", line 145, in deserialize_keras_object
    list(custom_objects.items())))
  File "/Users/srajanku/anaconda2/envs/retina-test/lib/python3.6/site-packages/keras/engine/network.py", line 1036, in from_config
    process_layer(layer_data)
  File "/Users/srajanku/anaconda2/envs/retina-test/lib/python3.6/site-packages/keras/engine/network.py", line 1022, in process_layer
    custom_objects=custom_objects)
  File "/Users/srajanku/anaconda2/envs/retina-test/lib/python3.6/site-packages/keras/layers/__init__.py", line 55, in deserialize
    printable_module_name='layer')
  File "/Users/srajanku/anaconda2/envs/retina-test/lib/python3.6/site-packages/keras/utils/generic_utils.py", line 147, in deserialize_keras_object
    return cls.from_config(config['config'])
  File "/Users/srajanku/anaconda2/envs/retina-test/lib/python3.6/site-packages/keras/engine/base_layer.py", line 1124, in from_config
    return cls(**config)
  File "/Users/srajanku/anaconda2/envs/retina-test/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "/Users/srajanku/anaconda2/envs/retina-test/lib/python3.6/site-packages/keras/layers/normalization.py", line 75, in __init__
    super(BatchNormalization, self).__init__(**kwargs)
  File "/Users/srajanku/anaconda2/envs/retina-test/lib/python3.6/site-packages/keras/engine/base_layer.py", line 128, in __init__
    raise TypeError('Keyword argument not understood:', kwarg)
TypeError: ('Keyword argument not understood:', 'freeze')

rajanksin avatar Aug 02 '18 20:08 rajanksin

Have the same error. Does any one have the idea to fix?

zhoushuai123 avatar Oct 22 '18 20:10 zhoushuai123

Your model has custom layers. You need to pass the custom objects to the load_model command. Check this issue: https://github.com/fizyr/keras-retinanet/issues/86

amir-abdi avatar Oct 22 '18 20:10 amir-abdi

Thanks a lot! I will try and let you know:-)

zhoushuai123 avatar Oct 24 '18 08:10 zhoushuai123

Thanks:-) It works

Your model has custom layers. You need to pass the custom objects to the load_model command. Check this issue: fizyr/keras-retinanet#86

zhoushuai123 avatar Oct 24 '18 08:10 zhoushuai123

I am facing the same issue, where should I pass this and how?

zubairahmed-ai avatar Nov 22 '18 07:11 zubairahmed-ai

I figured in out, this is how its done

in keras_to_tensorflow.py Add from keras_retinanet import models

Then comment line 62 # model = keras.models.load_model(input_model_path)

and add the following like this model = models.load_model(input_model_path, backbone_name="resnet50")

zubairahmed-ai avatar Nov 22 '18 07:11 zubairahmed-ai

I figured in out, this is how its done in keras_to_tensorflow.py Add from keras_retinanet import models Then comment line 62

model = keras.models.load_model(input_model_path)

and add the following like this model = models.load_model(input_model_path, backbone_name="resnet50")

It works!!! thanks!!!!

wnov avatar Mar 06 '19 06:03 wnov