我有一个在 Google Colab 上训练过的 tf.keras lstm 模型,我想将它加载到我的笔记本电脑上,以便可以运行它进行推理。我在我的笔记本电脑上创建了一个具有相同版本的 Python 虚拟环境......
我有一个在 Google Colab 上训练过的 tf.keras lstm 模型,我想将它加载到我的笔记本电脑上,以便可以运行它进行推理。我在我的笔记本电脑上创建了一个 Python 虚拟环境,其中 Tensorflow/Keras 版本与 Google Colab 相同(2.15),Python 版本也相同(3.10)。尽管如此,当我加载模型时,我收到以下错误:
2024-07-03 15:01:12.725137: W tensorflow/core/common_runtime/graph_constructor.cc:840] Node 'cond/while' has 13 outputs but the _output_shapes attribute specifies shapes for 42 outputs. Output shapes may be inaccurate.
2024-07-03 15:01:13.713773: W tensorflow/core/common_runtime/graph_constructor.cc:840] Node 'cond/while' has 13 outputs but the _output_shapes attribute specifies shapes for 42 outputs. Output shapes may be inaccurate.
2024-07-03 15:01:14.703037: W tensorflow/core/common_runtime/graph_constructor.cc:840] Node 'cond' has 5 outputs but the _output_shapes attribute specifies shapes for 42 outputs. Output shapes may be inaccurate.
2024-07-03 15:01:14.887920: W tensorflow/core/common_runtime/graph_constructor.cc:840] Node 'cond' has 5 outputs but the _output_shapes attribute specifies shapes for 42 outputs. Output shapes may be inaccurate.
2024-07-03 15:01:15.375012: W tensorflow/core/common_runtime/graph_constructor.cc:840] Node 'cond/while' has 13 outputs but the _output_shapes attribute specifies shapes for 42 outputs. Output shapes may be inaccurate.
2024-07-03 15:01:15.841333: W tensorflow/core/common_runtime/graph_constructor.cc:840] Node 'cond/while' has 13 outputs but the _output_shapes attribute specifies shapes for 42 outputs. Output shapes may be inaccurate.
2024-07-03 15:01:15.884074: W tensorflow/core/common_runtime/graph_constructor.cc:840] Node 'cond' has 5 outputs but the _output_shapes attribute specifies shapes for 42 outputs. Output shapes may be inaccurate.
2024-07-03 15:01:17.601834: W tensorflow/core/common_runtime/graph_constructor.cc:840] Node 'cond/while' has 13 outputs but the _output_shapes attribute specifies shapes for 42 outputs. Output shapes may be inaccurate.
2024-07-03 15:01:17.638458: W tensorflow/core/common_runtime/graph_constructor.cc:840] Node 'cond' has 5 outputs but the _output_shapes attribute specifies shapes for 42 outputs. Output shapes may be inaccurate.
2024-07-03 15:01:18.121723: W tensorflow/core/common_runtime/graph_constructor.cc:840] Node 'cond' has 5 outputs but the _output_shapes attribute specifies shapes for 42 outputs. Output shapes may be inaccurate.
模型是 tf.keras.Sequential
使用其 save
方法保存并使用该 tf.keras.models.load_model
方法加载的模型。查找此问题时,我发现这主要是由于模型保存环境和加载环境之间的 tensorflow/keras 版本不同造成的,但这不是我的情况。唯一的区别是操作系统(Linux vs Windows)。我还发现了一个线程指示 compile=False
在 tf.keras.models.load_model
方法中添加,但这对我的情况没有任何改变。
你对如何解决这个问题有什么建议吗?我希望有一个可以移植到不同设备的模型,只要使用相同的 Python 虚拟环境。