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

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()


Solution 1:[1]

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

Solution 2:[2]

I also faced this problem when working on google Colab. It seemed, my Colab lose the directory path data where the model is located. Simply run these two lines again and try again. Hopefully, that'll solve the problem :

import os
os.chdir("/content/drive/My Drive/path/to/your/model")

Solution 3:[3]

you have to specify just the directory name where metedata.pb and model.pb is automatically stored for its successful run it not just model.pb but also metadata.pb

Solution 4:[4]

I faced this problem with tensorflow installation under conda environment. Uninstalling h5py installed from pip and reinstall it using conda solve my problem.

pip uninstall h5py
conda install h5py

Solution 5:[5]

The directory path should end with saved_model. For example, In your case it should be C:/Users/Munib/New folder/saved_model

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mahmoud Youssef
Solution 2 Mohammed Jafar Sadik
Solution 3
Solution 4 kdebugging
Solution 5 Vicky