OSError: SavedModel file does not exist, with Tensorflow Lite
OSError: SavedModel file does not exist, with Tensorflow Lite
我正在尝试使用以下代码段
将 here 找到的 Keras 模型转换为 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
根据https://apple.github.io/coremltools/coremlspecification,.mlmodel文件扩展名表示CoreML模型的一种格式。重命名文件扩展名不会将给定模型格式更改为其他模型格式。
如果您想生成 TensorFlow Lite 模型,请查看指南页面中的预训练模型部分,https://www.tensorflow.org/lite/guide/get_started#1_choose_a_model。
我正在尝试使用以下代码段
将 here 找到的 Keras 模型转换为 TFliteimport 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
根据https://apple.github.io/coremltools/coremlspecification,.mlmodel文件扩展名表示CoreML模型的一种格式。重命名文件扩展名不会将给定模型格式更改为其他模型格式。
如果您想生成 TensorFlow Lite 模型,请查看指南页面中的预训练模型部分,https://www.tensorflow.org/lite/guide/get_started#1_choose_a_model。