【问题标题】:How to upgrade tensorflow to 2.0 in google colab permanently如何在 google colab 中将 tensorflow 永久升级到 2.0
【发布时间】:2020-03-23 08:56:22
【问题描述】:

我正在尝试将 tensorflow 从 google colab 中的当前现有版本升级到 2.x,但每次我打开 colab 并检查其版本时,它都会回滚到以前的版本 (1.15.0)。如何将 tensorflow 永久升级到 2.x?因为每次安装都会占用大量内存。每次运行笔记本时,我都在尝试命令 !pip install tensorflow==2.1.0,因为它正在回滚到以前的版本。

【问题讨论】:

    标签: python tensorflow google-colaboratory tensorflow2.0


    【解决方案1】:

    Colab 预装了两个版本的 TensorFlow:1.x 版本和 2.x 版本。 Colab 目前默认使用 TensorFlow 1.x。

    运行 import tensorflow 将导入默认版本(当前为 1.x)。您可以通过运行带有tensorflow_version 魔法的单元格运行 import tensorflow 来使用 2.x。'

    %tensorflow_version 2.x
    

    输出:

    TensorFlow 2.x selected.
    

    一旦你通过这个魔法指定了一个版本,你就可以像往常一样运行import tensorflow 并验证导入了哪个版本,如下所示:

    import tensorflow
    print(tensorflow.__version__)
    

    输出:

    2.1.0
    

    如果您想在导入后切换 TensorFlow 版本,您需要使用 'Runtime' -> 'Restart runtime...' 重新启动运行时,然后在再次导入之前指定版本.

    %tensorflow_version 1.x
    import tensorflow as tf
    print(tf.__version__)
    

    输出:

    1.15.0
    

    【讨论】:

    • 非常感谢。这真的有助于让我免于下载大约。每次我想在 colab 中使用 tensorflow 时 500 mb
    猜你喜欢
    • 1970-01-01
    • 2020-07-12
    • 2021-12-29
    • 1970-01-01
    • 2021-01-30
    • 1970-01-01
    • 2021-08-23
    • 2020-02-02
    • 2019-04-04
    相关资源
    最近更新 更多