简体   繁体   中英

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.

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 . And same case is with 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 . 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.
but for tensorflow you should use %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. Colab builds TensorFlow from source to ensure compatibility with our fleet of accelerators. Versions of TensorFlow fetched from PyPI by pip may suffer from performance problems or may not work at all.

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.

In the latest colab, when you upgrade or downgrade a module, in the output cell you will automatically see the statement:

"WARNING: The following packages were previously imported in this runtime: [scipy] You must restart the runtime in order to use newly installed versions.

" asking you to restart the runtime along with a button for it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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