Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I ran this piece of code in Google Colab to convert my Keras hdf5 file to a Tflite file:
import tensorflow as tf
keras_model = tf.keras.models.load_model("/content/best_model_11class.hdf5")
converter = tf.lite.TFLiteConverter.from_keras_model(keras_model)
tfmodel = converter.convert()
open ('model.tflite' , "wb") .write(tfmodel)
I get this error when I run the code:
ValueError Traceback (most recent call last)
<ipython-input-2-0804f3b57a48> in <module>()
2 keras_model = tf.keras.models.load_model("/content/best_model_11class.hdf5")
3 converter = tf.lite.TFLiteConverter.from_keras_model(keras_model)
----> 4 tfmodel = converter.convert()
5 open ('model.tflite' , "wb") .write(tfmodel)
/usr/local/lib/python3.6/dist-packages/tensorflow/lite/python/lite.py in convert(self)
481 "None is only supported in the 1st dimension. Tensor '{0}' has "
482 "invalid shape '{1}'.".format(
--> 483 _get_tensor_name(tensor), shape_list))
484 elif shape_list and shape_list[0] is None:
485 # Set the batch size to 1 if undefined.
ValueError: None is only supported in the 1st dimension. Tensor 'input_1' has invalid shape '[None, None, None, 3]'.
Can someone tell me how do I fix this?
Use this Google Colab notebook to convert. Upload the .hdf5 file and it will convert it .tflite file.
Link to notebook
https://colab.research.google.com/drive/1E0dqzDYszsG2BfyzVWUOdKLElqvMn4oo?usp=sharing
After the final code executes, go to files( the leftmost side ) then you will find the .tflite model there
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.