【问题标题】:using a tensorflow model trained on google colab on my PC在我的 PC 上使用在 google colab 上训练的 tensorflow 模型
【发布时间】:2021-12-05 02:28:07
【问题描述】:

我正在使用 colab 训练一个 tensorflow 模型。我看到google colab默认安装的是以下版本:

import tensorflow
tensorflow.__version__
2.6.0
...
[train model]
...

model.save('mymodel.h5')

但是,当我将模型下载到我的 Windows 电脑并尝试使用 tensorflow/keras 加载它时,出现错误

import keras
import tensorflow
model = keras.models.load_model(r"mymodel.h5")

    model_config = json.loads(model_config.decode('utf-8'))
AttributeError: 'str' object has no attribute 'decode'

在网上搜索后,似乎这是由于 tensorflow 版本不同(colab 与我的 PC)。

tensorflow.__version__
Out[4]: '2.1.0'

问题是当我用conda install tensorflow-gpu 安装tensorflow 时,这是我得到的版本。即使试图强制conda install tensorflow-gpu==2.6 也不会安装任何东西。

我该怎么办? 谢谢!

【问题讨论】:

  • 您可以先卸载旧版本的TensorFlow,然后再安装其他版本(2.6)
  • 你试过用 pip 代替 conda 吗?看到这个stackoverflow.com/questions/46840496/…
  • @abdou_dev 谢谢,但是用哪个命令? conda 无论如何都会安装旧的 tf2 版本,对吧?我需要 conda 安装附带的 cuda 东西...
  • 试试这个:pip install tensorflow-gpu==2.6 --upgrade
  • 谢谢@abdou_dev,我现在就试试。但这会考虑到 2.6 可能的不同 CUDA 版本吗?

标签: python tensorflow conda


【解决方案1】:

暂时的解决方案......

  1. 使用conda install tensorflow-gpu下载tensorflow 2.1 + CUDA和CuDNN
  2. 使用pip install tensorflow-gpu==2.6 --upgrade --force-reinstall升级

GPU 不工作(可能是因为 CUDA 版本不正确)但至少我可以使用 CPU 运行 tf 2.6 脚本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-31
    • 2021-12-13
    • 2022-01-08
    • 2021-06-06
    • 2021-05-17
    • 2021-06-22
    相关资源
    最近更新 更多