OlafenwaMoses / ImageAI

A python library built to empower developers to build applications and systems with self-contained Computer Vision capabilities
https://www.genxr.co/#products
MIT License
8.55k stars 2.19k forks source link

Trying to convert .h5 file to .pb #190

Closed Nathnael-Belay closed 5 years ago

Nathnael-Belay commented 5 years ago

I just fininshed training my custom model and would like to convert it to .pb for use in tensorflow. I found help online on how to make the conversion, but it is giving me an error(below) on this particular .h5 model file. works for other .h5 models not trained using imageai.

Using TensorFlow backend. E0414 18:47:01.275491 23212 h5_to_pb.py:84] 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. Check the keras documentation for more details (https://keras.io/getting-started/faq/) Traceback (most recent call last): File "h5_to_pb.py", line 171, in app.run(main) File "D:\Programs\Anaconda3\envs\dl-env\lib\site-packages\absl\app.py", line 300, in run _run_main(main, args) File "D:\Programs\Anaconda3\envs\dl-env\lib\site-packages\absl\app.py", line 251, in _run_main sys.exit(main(argv)) File "h5_to_pb.py", line 117, in main model = load_model(FLAGS.input_model, FLAGS.input_model_json, FLAGS.input_model_yaml) File "h5_to_pb.py", line 95, in load_model raise wrong_file_err File "h5_to_pb.py", line 52, in load_model model = keras.models.load_model(input_model_path) File "D:\Programs\Anaconda3\envs\dl-env\lib\site-packages\keras\engine\saving.py", line 419, in load_model model = _deserialize_model(f, custom_objects, compile) File "D:\Programs\Anaconda3\envs\dl-env\lib\site-packages\keras\engine\saving.py", line 221, in _deserialize_model model_config = f['model_config'] File "D:\Programs\Anaconda3\envs\dl-env\lib\site-packages\keras\utils\io_utils.py", line 302, in getitem raise ValueError('Cannot create group in read only mode.') ValueError: Cannot create group in read only mode.

OlafenwaMoses commented 5 years ago

We will release a new version soon that will allow you to easily convert your custom model to Tensorflow's .pb in a single function call.

OlafenwaMoses commented 5 years ago

Hello @Nathnael-Belay , thanks for your patience. We have released a new version (v2.0.3) that allows you to convert your Keras models to Tensorflow's .pb format. See the link below.

https://github.com/OlafenwaMoses/ImageAI/blob/master/imageai/Prediction/CUSTOMPREDICTION.md#converttensorflow

Also, visit https://github.com/OlafenwaMoses/ImageAI for all the new features in this release.