amir-abdi / keras_to_tensorflow

General code to convert a trained keras model into an inference tensorflow model
MIT License
1.67k stars 539 forks source link

Unable to convert .h5 file to .pb file, unknown layer BatchNormalizationV1 #74

Open Rajkiran93 opened 5 years ago

Rajkiran93 commented 5 years ago

I got this error while converting .h5 file to .pb file, but when BatchNormalizationV1 is removed while training the .h5 file is converted to .pb file successfully.

Keras version 2.2.4

Traceback (most recent call last): File "keras_to_tensorflow.py", line 165, in app.run(main) File "/anaconda3/lib/python3.7/site-packages/absl/app.py", line 300, in run _run_main(main, args) File "/anaconda3/lib/python3.7/site-packages/absl/app.py", line 251, in _run_main sys.exit(main(argv)) File "keras_to_tensorflow.py", line 111, in main model = load_model(FLAGS.input_model, FLAGS.input_model_json) File "keras_to_tensorflow.py", line 89, in load_model raise wrong_file_err File "keras_to_tensorflow.py", line 60, in load_model model = tf.keras.models.load_model(input_model_path) File "/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/saving.py", line 230, in load_model model = model_from_config(model_config, custom_objects=custom_objects) File "/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/saving.py", line 310, in model_from_config return deserialize(config, custom_objects=custom_objects) File "/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/layers/serialization.py", line 64, in deserialize printable_module_name='layer') File "/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 173, in deserialize_keras_object list(custom_objects.items()))) File "/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/engine/sequential.py", line 339, in from_config custom_objects=custom_objects) File "/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/layers/serialization.py", line 64, in deserialize printable_module_name='layer') File "/anaconda3/lib/python3.7/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 163, in deserialize_keras_object raise ValueError('Unknown ' + printable_module_name + ': ' + class_name) ValueError: Unknown layer: BatchNormalizationV1

Rajkiran93 commented 5 years ago

Never mind , got it fixed by installing "tf-nightly" Command:- "pip install tf-nightly"