【问题标题】:OSError: SavedModel file does not exist, with Tensorflow LiteOSError:SavedModel 文件不存在,使用 Tensorflow Lite
【发布时间】:2021-03-29 11:46:52
【问题描述】:

我正在尝试使用以下 sn-p 将找到的 Keras 模型 here 转换为 TFlite

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)

但我收到以下错误

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}

我将模型文件扩展名从.mlmodel 重命名为.pb,因为文件扩展名似乎需要为.pb.pbtxt。我确信模型目录的路径是正确的。

我正在使用tensorflow~=2.4.1

【问题讨论】:

    标签: tensorflow tensorflow2.0 tensorflow-lite


    【解决方案1】:

    根据https://apple.github.io/coremltools/coremlspecification,.mlmodel 文件扩展名代表CoreML 模型的一种格式。重命名文件扩展名不会将给定的模型格式更改为其他模型格式。

    如果您想生成 TensorFlow Lite 模型,请查看指南页面上的预训练模型部分,https://www.tensorflow.org/lite/guide/get_started#1_choose_a_model

    【讨论】:

      猜你喜欢
      • 2022-08-02
      • 2020-08-25
      • 2020-01-31
      • 2020-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-09
      • 1970-01-01
      相关资源
      最近更新 更多