如何在Tensorflow 2.8上使用多个模型

发布于 2025-01-24 08:02:47 字数 2159 浏览 0 评论 0原文

您是否推荐如何在

Tensorflow 1.14上使用多个型号进行Tensorflow 2.8。我可以按范围进行特定的模型

with graph.as_default():
    K.set_session(session)
    model.predict(input)

,但是在Tensorflow 2.8上,我不知道如何使用多个型号

更新 我的问题很困惑,

我通过功能性api tensorflow和load_weights创建模型来建模 当我具体的模型预测时会有一些错误

File "/opt/homebrew/Caskroom/miniforge/base/envs/myenv/lib/python3.8/site-packages/keras/engine/training_v1.py", line 970, in predict
    return func.predict(
  File "/opt/homebrew/Caskroom/miniforge/base/envs/myenv/lib/python3.8/site-packages/keras/engine/training_arrays_v1.py", line 700, in predict
    return predict_loop(
  File "/opt/homebrew/Caskroom/miniforge/base/envs/myenv/lib/python3.8/site-packages/keras/engine/training_arrays_v1.py", line 377, in model_iteration
    batch_outs = f(ins_batch)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/myenv/lib/python3.8/site-packages/keras/backend.py", line 4275, in __call__
    fetched = self._callable_fn(*array_vals,
  File "/opt/homebrew/Caskroom/miniforge/base/envs/myenv/lib/python3.8/site-packages/tensorflow/python/client/session.py", line 1480, in __call__
    ret = tf_session.TF_SessionRunCallable(self._session._session,
tensorflow.python.framework.errors_impl.FailedPreconditionError: 2 root error(s) found.
  (0) FAILED_PRECONDITION: Could not find variable conv2d_3/kernel. This could mean that the variable has been deleted. In TF1, it can also mean the variable is uninitialized. Debug info: container=localhost, status error message=Container localhost does not exist. (Could not find resource: localhost/conv2d_3/kernel)
         [[{{node conv2d_3/Conv2D/ReadVariableOp}}]]
         [[conv2d_7/Conv2D/ReadVariableOp/_19]]
  (1) FAILED_PRECONDITION: Could not find variable conv2d_3/kernel. This could mean that the variable has been deleted. In TF1, it can also mean the variable is uninitialized. Debug info: container=localhost, status error message=Container localhost does not exist. (Could not find resource: localhost/conv2d_3/kernel)
         [[{{node conv2d_3/Conv2D/ReadVariableOp}}]]
0 successful operations.
0 derived errors ignored.

do you recommend how to use multiple model for Tensorflow 2.8

I used to on Tensorflow 1.14. it i can specific model by scope

with graph.as_default():
    K.set_session(session)
    model.predict(input)

but on tensorflow 2.8 i don't know how to use multiple model

do you recommend it.

update
my question is confused

i create model by functional API tensorflow and load_weights to model
and when i specific model to predict i got some error

File "/opt/homebrew/Caskroom/miniforge/base/envs/myenv/lib/python3.8/site-packages/keras/engine/training_v1.py", line 970, in predict
    return func.predict(
  File "/opt/homebrew/Caskroom/miniforge/base/envs/myenv/lib/python3.8/site-packages/keras/engine/training_arrays_v1.py", line 700, in predict
    return predict_loop(
  File "/opt/homebrew/Caskroom/miniforge/base/envs/myenv/lib/python3.8/site-packages/keras/engine/training_arrays_v1.py", line 377, in model_iteration
    batch_outs = f(ins_batch)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/myenv/lib/python3.8/site-packages/keras/backend.py", line 4275, in __call__
    fetched = self._callable_fn(*array_vals,
  File "/opt/homebrew/Caskroom/miniforge/base/envs/myenv/lib/python3.8/site-packages/tensorflow/python/client/session.py", line 1480, in __call__
    ret = tf_session.TF_SessionRunCallable(self._session._session,
tensorflow.python.framework.errors_impl.FailedPreconditionError: 2 root error(s) found.
  (0) FAILED_PRECONDITION: Could not find variable conv2d_3/kernel. This could mean that the variable has been deleted. In TF1, it can also mean the variable is uninitialized. Debug info: container=localhost, status error message=Container localhost does not exist. (Could not find resource: localhost/conv2d_3/kernel)
         [[{{node conv2d_3/Conv2D/ReadVariableOp}}]]
         [[conv2d_7/Conv2D/ReadVariableOp/_19]]
  (1) FAILED_PRECONDITION: Could not find variable conv2d_3/kernel. This could mean that the variable has been deleted. In TF1, it can also mean the variable is uninitialized. Debug info: container=localhost, status error message=Container localhost does not exist. (Could not find resource: localhost/conv2d_3/kernel)
         [[{{node conv2d_3/Conv2D/ReadVariableOp}}]]
0 successful operations.
0 derived errors ignored.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぃ双果 2025-01-31 08:02:47

我通过从MacBook(M1芯片)上的Run Run Conn在我的PC上进行的更改解决了我的

问题

i solved my problem by change from run on macbook (m1 chip) to run on my pc

thanks for everyone view and comments my question

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文