简体   繁体   English

如何在 Google colab 中更改 Keras/tensorflow 版本?

[英]How to change Keras/tensorflow version in Google colab?

I'm using keras/tensorflow on google colaboratory and I need to go back to previous versions of them.我在 google colaboratory 上使用 keras/tensorflow,我需要回到它们的以前版本。

The problem is when I run !pip install q keras==1.2.2 , the kernel shows keras 1.2.2 installed but when I check it using keras.__version_ it shows 2.1.6 .问题是当我运行!pip install q keras==1.2.2 ,内核显示安装了 keras 1.2.2 但是当我使用keras.__version_检查它时它显示 2.1.6 。 And same case is with tensorflow. tensorflow 也是同样的情况。

How do I fix this?我该如何解决?

I had this issue yesterday.我昨天有这个问题。 I was rather surprised that installing packages did not have an effect.我很惊讶安装软件包没有效果。 But I realised then that I needed to restart the kernel.但是我意识到我需要重新启动内核。 In Colab this is called Restart runtime .在 Colab 中,这称为Restart runtime After restart the new version should be available for you.重新启动后,新版本应该可供您使用。

Here you find the restart:在这里你可以找到重启:

在此处输入图片说明

Your command !pip install q keras==1.2.2 for Keras is okay, just you need to restart runtime as other answers mentioned.您的命令!pip install q keras==1.2.2 for Keras 没问题,只是您需要像其他答案提到的那样重新启动运行时。
but for tensorflow you should use %tensorflow_version 1.x .但是对于 tensorflow 你应该使用%tensorflow_version 1.x
as they said here :正如他们在这里所说:

Avoid Using pip install with GPUs and TPUs We recommend against using pip install to specify a particular TensorFlow version for both GPU and TPU backends.避免对 GPU 和 TPU 使用 pip install 我们建议不要使用 pip install 为 GPU 和 TPU 后端指定特定的 TensorFlow 版本。 Colab builds TensorFlow from source to ensure compatibility with our fleet of accelerators. Colab 从源代码构建 TensorFlow,以确保与我们的加速器组兼容。 Versions of TensorFlow fetched from PyPI by pip may suffer from performance problems or may not work at all.通过 pip 从 PyPI 获取的 TensorFlow 版本可能会遇到性能问题或根本无法工作。

and as it says, when I tried to downgrade my TensorFlow to 1.5 with pip, it does not recognize GPU and just trained my model with cpu.正如它所说,当我尝试用 pip 将我的 TensorFlow 降级到 1.5 时,它无法识别 GPU,只是用 cpu 训练了我的模型。

In the latest colab, when you upgrade or downgrade a module, in the output cell you will automatically see the statement:在最新的 colab 中,当您升级或降级模块时,您会在输出单元格中自动看到以下语句:

"WARNING: The following packages were previously imported in this runtime: [scipy] You must restart the runtime in order to use newly installed versions. “警告:以前在此运行时中导入了以下包:[scipy] 您必须重新启动运行时才能使用新安装的版本。

" asking you to restart the runtime along with a button for it. " 要求您重新启动运行时及其按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM