Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 286
Sheril Dev Avatar asked Aug 23 '18 08:08

Sheril Dev


2 Answers

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:

enter image description here

like image 105
MBT Avatar answered Sep 20 '22 12:09

MBT


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.

like image 29
hossein hayati Avatar answered Sep 22 '22 12:09

hossein hayati