简体   繁体   English

尝试使用 tf.saved_model.load() 加载 tensorflow 时出现“读取的字节数少于请求的字节数”错误

[英]"Read less bytes than requested" error while trying to load tensorflow using tf.saved_model.load()

I've been trying to run a web server locally that my colleague created which contains a deployed model that processes object detection requests.我一直在尝试在本地运行我的同事创建的 Web 服务器,其中包含一个处理对象检测请求的已部署模型。 There've been a lot of compatibility issues because he's on Windows and I'm on MacOS.因为他在 Windows 而我在 MacOS,所以出现了很多兼容性问题。

I've been able to resolve all the compatibility issues with the dependencies and get the web server running, but I've been running into this issue when trying to load the object detection model from the saved_model directory.我已经能够解决所有依赖项的兼容性问题并让 Web 服务器运行,但是当我尝试从 saved_model 目录加载对象检测模型时遇到了这个问题。 The structure of the directory is:目录结构为:
saved_model/保存的模型/
variables/变量/
variables.data-00000-of-00001 variables.data-00000-of-00001
variables.index变量.index
saved_model.pb saved_model.pb

I created a test script to try isolate the problem, which looks as follows:我创建了一个测试脚本来尝试隔离问题,如下所示:

import tensorflow as tf

model = tf.saved_model.load("./saved_model")

# print model summary
print("loaded model")
print(model.summary())

When I run the script, I get the following error, which is the same error that I get when running the web server.当我运行脚本时,出现以下错误,这与运行 Web 服务器时出现的错误相同。

Traceback (most recent call last): File "/Users/alexandrospouroullis/programming-projects/elevat3d/backend/workspace/training_demo/exported-models/my_model_1024/testFile.py", line 4, in model = tf.saved_model.load("./saved_model") File "/Users/alexandrospouroullis/opt/miniconda3/envs/elevat3d-api/lib/python3.10/site-packages/tensorflow/python/saved_model/load.py", line 782, in load result = load_partial(export_dir, None, tags, options)["root"] File "/Users/alexandrospouroullis/opt/miniconda3/envs/elevat3d-api/lib/python3.10/site-packages/tensorflow/python/saved_model/load.py", line 912, in load_partial loader = Loader(object_graph_proto, saved_model_proto, export_dir, File "/Users/alexandrospouroullis/opt/miniconda3/envs/elevat3d-api/lib/python3.10/site-packages/tensorflow/python/saved_model/load.py", line 189, in init self._restore_checkpoint() File "/Users/alexandrospouroullis/opt/miniconda3/envs/elevat3d-api/lib/python3.10/site-packages/tensorflow/python/saved_model/load.py", line 5回溯(最近一次通话最后一次):文件“/Users/alexandrospourullis/programming-projects/elevat3d/backend/workspace/training_demo/exported-models/my_model_1024/testFile.py”,第 4 行,在 model = tf.saved_model.load( “./saved_model”)文件“/Users/alexandrospourullis/opt/miniconda3/envs/elevat3d-api/lib/python3.10/site-packages/tensorflow/python/saved_model/load.py”,第 782 行,加载结果= load_partial(export_dir, None, tags, options)["root"] 文件 "/Users/alexandrospourullis/opt/miniconda3/envs/elevat3d-api/lib/python3.10/site-packages/tensorflow/python/saved_model/load .py", line 912, in load_partial loader = Loader(object_graph_proto, saved_model_proto, export_dir, File "/Users/alexandrospourullis/opt/miniconda3/envs/elevat3d-api/lib/python3.10/site-packages/tensorflow/python/ saved_model/load.py”,第 189 行,在init self._restore_checkpoint() 文件中“/Users/alexandrospourullis/opt/miniconda3/envs/elevat3d-api/lib/python3.10/site-packages/tensorflow/python/saved_model/加载.py”,第 5 行07, in _restore_checkpoint load_status = saver.restore(variables_path, self._checkpoint_options) File "/Users/alexandrospouroullis/opt/miniconda3/envs/elevat3d-api/lib/python3.10/site-packages/tensorflow/python/training/tracking/util.py", line 1430, in restore object_graph_string = reader.get_tensor(base.OBJECT_GRAPH_PROTO_KEY) File "/Users/alexandrospouroullis/opt/miniconda3/envs/elevat3d-api/lib/python3.10/site-packages/tensorflow/python/training/py_checkpoint_reader.py", line 66, in get_tensor return CheckpointReader.CheckpointReader_GetTensor( IndexError: Read less bytes than requested 07、在_restore_checkpoint load_status = saver.restore(variables_path, self._checkpoint_options) 文件"/Users/alexandrospourullis/opt/miniconda3/envs/elevat3d-api/lib/python3.10/site-packages/tensorflow/python/training/tracking /util.py", line 1430, in restore object_graph_string = reader.get_tensor(base.OBJECT_GRAPH_PROTO_KEY) File "/Users/alexandrospouroullis/opt/miniconda3/envs/elevat3d-api/lib/python3.10/site-packages/tensorflow/ python/training/py_checkpoint_reader.py”,第 66 行,在 get_tensor 中 return CheckpointReader.CheckpointReader_GetTensor( IndexError: Read less bytes than requested

I understand that things like Docker were made for this;我知道像 Docker 这样的东西就是为此而生的; I actually created a docker-compose.yaml file that I managed to get up and running as well, but it faced this exact same issue.我实际上创建了一个 docker-compose.yaml 文件,我也设法启动并运行它,但它面临着完全相同的问题。

I've looked around on the web, but this doesn't seem to be a common issue and no remedy, as far as I know, exists.我在网上四处张望,但这似乎不是一个常见问题,据我所知,不存在任何补救措施。

What could be going wrong?可能出了什么问题?

There are two things you will have to check:您必须检查两件事:

  1. Make sure your weights file(under the variables folder) is properly loaded in your docker environment(check the size of the file).确保您的权重文件(在变量文件夹下)已正确加载到您的 docker 环境中(检查文件的大小)。 At times, the files is not properly loaded and in just 2 Kb whereas the actual file will be atleast 0.5 GB and upwards.有时,文件未正确加载且只有 2 Kb,而实际文件至少为 0.5 GB 或更大。
  2. Enough memory while loading the model.加载模型时有足够的内存。 TF models take up considerable infra juice and atleast 16GB RAM is recommended. TF 模型占用相当大的基础设施,建议至少 16GB RAM。 I faced a similar issue.我遇到了类似的问题。 Mine was because of a corrupt weights file - point1.我的是因为权重文件损坏 - point1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法加载 tensorflow(tf-agent)保存的模型 - Can't load tensorflow (tf-agent) saved model Tensorflow:加载保存的模型:UnicodeDecodeError - Tensorflow : load saved model : UnicodeDecodeError 如何编写一个 tfrecord 文件并读取它? 错误是:0' 处的截断记录失败,读取的字节数少于请求的 [Op:IteratorGetNext] - How to write a tfrecord file and read it? The error is: truncated record at 0' failed with Read less bytes than requested [Op:IteratorGetNext] 如何加载已保存的 Tensorflow 模型并对其进行评估 - How to load a saved Tensorflow model and evaluate it 如何加载和测试特定的TensorFlow保存的模型? - How to load and test a specific TensorFlow saved model? Tensorflow saved_model.load 问题 - Tensorflow saved_model.load issue Tensorflow 2.0:如何在使用 tf.saved_model 时更改输出签名 - Tensorflow 2.0: How to change the output signature while using tf.saved_model 尝试使用 pyspark 加载保存的 Spark 模型时出现“空集合”错误 - “empty collection” error when trying to load a saved Spark model using pyspark 尝试加载已保存的 Tensorflow ELMO model 但在加载时得到“TypeError:'str' object is not callable” - Trying to load a saved Tensorflow ELMO model but get "TypeError: 'str' object is not callable" when loading TF 估计器:无法从保存的模型加载 *.pb - TF Estimator: Can't Load *.pb from Saved Model
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM