kaushalyap
kaushalyap

Reputation: 13597

OSError: SavedModel file does not exist, with Tensorflow Lite

I am trying to convert a Keras model found here to TFlite using following snippet

import tensorflow as tf
import os.path as path

pwd = path.dirname(__file__)
model_path = pwd+"/models/old-models/"
print("PWD: ", model_path)
converter = tf.lite.TFLiteConverter.from_saved_model(model_path)
tflite_model = converter.convert()

with open('model.tflite', 'wb') as f:
  f.write(tflite_model)

But I am getting following error

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/<PyCharm installed directory>/ch-0/211.6693.23/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/<PyCharm installed directory>/ch-0/211.6693.23/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/<Path to project>/myproject/convert_to_tflite.py", line 7, in <module>
    converter = tf.lite.TFLiteConverter.from_saved_model(model_path)
  File "/<path to miniconda>/miniconda3/envs/myproject/lib/python3.8/site-packages/tensorflow/lite/python/lite.py", line 1069, in from_saved_model
    saved_model = _load(saved_model_dir, tags)
  File "/<path to miniconda>/miniconda3/envs/myproject/lib/python3.8/site-packages/tensorflow/python/saved_model/load.py", line 859, in load
    return load_internal(export_dir, tags, options)["root"]
  File "/<path to miniconda>/miniconda3/envs/myproject/lib/python3.8/site-packages/tensorflow/python/saved_model/load.py", line 871, in load_internal
    loader_impl.parse_saved_model_with_debug_info(export_dir))
  File "/<path to miniconda>/miniconda3/envs/myproject/lib/python3.8/site-packages/tensorflow/python/saved_model/loader_impl.py", line 56, in parse_saved_model_with_debug_info
    saved_model = _parse_saved_model(export_dir)
  File "/<path to miniconda>/miniconda3/envs/myproject/lib/python3.8/site-packages/tensorflow/python/saved_model/loader_impl.py", line 111, in parse_saved_model
    raise IOError("SavedModel file does not exist at: %s/{%s|%s}" %
OSError: SavedModel file does not exist at: /<path to my project>/models/old-models/{saved_model.pbtxt|saved_model.pb}

I renamed the model file extension from .mlmodel to .pb, since it seems file extension need to be .pb or .pbtxt. I am sure that path to the model directory is correct.

I am using tensorflow~=2.4.1

Upvotes: 1

Views: 607

Answers (1)

Jae sung Chung
Jae sung Chung

Reputation: 903

According to https://apple.github.io/coremltools/coremlspecification, .mlmodel file extension represents a format of CoreML model. Renaming the file extension does not change the given model format to the other model format.

If you would like to generate TensorFlow Lite models, please take a look at the pre-trained model section at the guide page, https://www.tensorflow.org/lite/guide/get_started#1_choose_a_model.

Upvotes: 1

Related Questions