OSError: SavedModel file does not exist at: C:\Users\Munib\New folder/{saved_model.pbtxt|saved_model.pb}

Mirza Munib picture Mirza Munib · Jun 13, 2020 · Viewed 12.1k times · Source

I wanted to use my keras trained model in android studio. I got this code on internet to convert my code from keras to tensorflow-lite. But when i tried code i got this error:

OSError: SavedModel file does not exist at: C:\Users\Munib\New folder/{saved_model.pbtxt|saved_model.pb}

The code i used from converting from keras to tensorflow-lite:

import tensorflow as tf
# Converting a SavedModel to a TensorFlow Lite model.
saved_model_dir = r"C:\Users\Munib\New folder"
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
tflite_model = converter.convert()

# Converting a tf.Keras model to a TensorFlow Lite model.
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()

# Converting ConcreteFunctions to a TensorFlow Lite model.
converter = tf.lite.TFLiteConverter.from_concrete_functions([func])
tflite_model = converter.convert()

Answer

Mahmoud Youssef picture Mahmoud Youssef · Jun 13, 2020

First of all it's best to use relative path instead of absolute path. second, if you use model.save('my_model') then keras will create a directory for you with the name my_model in which you should find a file with the pb or pbtxt extension, this is the directory you should use for tflite converter