keras.optimizers.Adam "not found module" error when running code form GPU in Colab

Viewed 347

I'm trying to run a code importing keras.optimizers Adam. I want to do it from GPU as I need to make a long training. If I run normally it works, but every time I change the runtime enviroment to GPU, it doesn't find the module "Adam" and gives me the error below. I'm using keras 2.2.4 due to compatibilities with other libraries:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-12-ca97e5a6925a> in <module>()
      8 from keras.models import Sequential
      9 from keras.layers import Dense, Activation, Flatten, Convolution2D, Permute
---> 10 from keras.optimizers import Adam
     11 import keras.backend as K
     12 

ImportError: cannot import name 'Adam' from 'keras.optimizers' (/usr/local/lib/python3.7/dist-packages/keras/optimizers.py)


NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
1 Answers

Change the line:

from keras.optimizers import Adam

to:

from tensorflow.keras.optimizers import Adam

and it'll work.

Related