【问题标题】:How switch tensorflow versions between 2.0 and 1.x?如何在 2.0 和 1.x 之间切换 tensorflow 版本?
【发布时间】:2020-01-03 18:07:27
【问题描述】:

有没有办法切换 tensorflow 的版本?当我使用 conda 安装 tensorflow 2.0 时,它更新了很多东西,甚至是 python。在运行conda list 时,它显示了两个版本;

张量流 2.0.0 mkl_py37h66b46cc_0
张量流 1.13.1

为了使用 1.x 版本,建议将 here 替换为以下内容:

import tensorflow.compat.v1 as tf tf.disable_v2_behavior()

使用此方法是安全的,只需添加这些行?,在我的情况下,它显示一个警告:

WARNING:tensorflow:From /home/common/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/compat/v2_compat.py:65: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version. Instructions for updating: non-resource variables are not supported in the long term

【问题讨论】:

    标签: python tensorflow anaconda


    【解决方案1】:

    我个人会在这里使用两种不同的虚拟环境。这将确保您在使用 2.0 与 1.x 时没有依赖性问题。 Conda 环境非常易于使用。例如:

    创造环境

    conda create --tensorflow1
    

    激活环境

    conda activate tensorflow1
    

    激活环境后,您可以 conda/pip 安装 TensorFlow 1.x,所有依赖项都将包含在环境中。你可以用 TensorFlow 2.0 做同样的事情。

    我无法评论您发布的上述解决方案,但在这些情况下,虚拟环境非常有用。

    这里有完整的文档:

    https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html

    【讨论】:

    • 谢谢,我可以在那个虚拟环境中运行 jupyter notebook 吗?
    • 是的,激活环境,然后启动 Jupyter Notebook。我总是从命令行执行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 2023-01-13
    • 1970-01-01
    • 1970-01-01
    • 2019-02-15
    • 2012-04-24
    • 1970-01-01
    相关资源
    最近更新 更多