user8232146
user8232146

Reputation: 3

How to upgrade tensorflow to 2.0 in google colab permanently

I am trying to upgrade tensorflow to 2.x from the current existing version in google colab but each time i open the colab and check for its version it rolls back to the previous version (1.15.0). How to permanently upgrade the tensorflow to 2.x? since its taking lot of memory for installing each time. I have been trying the command !pip install tensorflow==2.1.0 each time the notebook is run since it is getting rollback to previous version.

Upvotes: 0

Views: 1381

Answers (1)

bsquare
bsquare

Reputation: 986

Colab has two versions of TensorFlow pre-installed: a 1.x version and a 2.x version. Colab currently uses TensorFlow 1.x by default.

Running import tensorflow will import the default version (currently 1.x). You can use 2.x by running a cell with the tensorflow_version magic before you run import tensorflow.'

%tensorflow_version 2.x

Output:

TensorFlow 2.x selected.

Once you have specified a version via this magic, you can run import tensorflow as normal and verify which version was imported as follows:

import tensorflow
print(tensorflow.__version__)

Output:

2.1.0

If you want to switch TensorFlow versions after import, you will need to restart your runtime with 'Runtime' -> 'Restart runtime...' and then specify the version before you import it again.

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

Output:

1.15.0

Upvotes: 1

Related Questions