keras_to_tensorflow
keras_to_tensorflow copied to clipboard
unknown initializer: GlorotUniform
I saved a tensorflow keras sequential model, and then tried the keras_to_tensorflow and got: Unknown initializer: GlorotUniform
@ndvbd how did you fix this issue?
It just means that the installed keras library doesn't know a particular layer. Add something like before loading the model:
custom_objects={"GlorotUniform": tf.keras.initializers.glorot_uniform}
Check this thread: https://github.com/tensorflow/tfjs/issues/798
Hello, I have the same issue:
Using TensorFlow backend. WARNING: Logging before flag parsing goes to stderr. W0717 11:32:34.720095 139954044680064 module_wrapper.py:136] From /usr/local/lib/python3.6/dist-packages/tensorflow_core/python/util/module_wrapper.py:163: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.
E0717 11:32:34.724069 139954044680064 keras_to_tensorflow.py:96] Input file specified only holds the weights, and not the model definition. Save the model using model.save(filename.h5) which will contain the network architecture as well as its weights. If the model is saved using the model.save_weights(filename) function, either input_model_json or input_model_yaml flags should be set to to import the network architecture prior to loading the weights.
ValueError: Unknown initializer: GlorotUniform
Where I have to add custom_objects={"GlorotUniform": tf.keras.initializers.glorot_uniform} ?
Because, I don't load the model: I execute model.save and I use keras_to_tensorflow to convert the saved .h5 Do I miss a step? It seems keras_to_tensorflow tool doesn't properly read the .h5: " ..Save the model using model.save(filename.h5).."
Any other suggestions to solve the problem?
I modified line 19 to 21 in keras_to_tensorflow.py file
# import keras
# from keras import backend as K
# from keras.models import model_from_json, model_from_yaml
from tensorflow import keras
from tensorflow.keras import backend as K
from tensorflow.keras.models import model_from_json, model_from_yaml
It worked with tensorflow keras file
I modified line 19 to 21 in keras_to_tensorflow.py file
# import keras# from keras import backend as K# from keras.models import model_from_json, model_from_yamlfrom tensorflow import kerasfrom tensorflow.keras import backend as Kfrom tensorflow.keras.models import model_from_json, model_from_yamlIt worked with tensorflow keras file
Thank you for the suggestion. How do you see this change be helpful to users?
`from keras.utils import CustomObjectScope from keras.initializers import glorot_uniform
with CustomObjectScope({'GlorotUniform': glorot_uniform()}): model = keras.models.load_model('saved_gen.h5')`
This may help you!