Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TypeError: 'module' object is not callable when using Keras

I’ve been having lots of imports issues when it comes to TensorFlow and Keras and now I stumbled upon this error:

TypeError                                 Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_17880/703187089.py in <module>
     75 #model.compile(loss="categorical_crossentropy",optimizers.rmsprop(lr=0.0001),metrics=["accuracy"])
     76 
---> 77 model.compile(optimizers.rmsprop_v2(lr=0.0001, decay=1e-6),loss="categorical_crossentropy",metrics=["accuracy"])
     78 
     79 STEP_SIZE_TRAIN=train_generator.n//train_generator.batch_size

TypeError: 'module' object is not callable

These are the imports:

from tensorflow import keras
from keras_preprocessing.image import ImageDataGenerator
from keras.layers import Dense, Activation, Flatten, Dropout, BatchNormalization
from keras.layers import Conv2D, MaxPooling2D
from keras import regularizers, optimizers
from keras.models import Sequential
from keras import optimizers
from keras.optimizers import rmsprop_v2, adadelta_v2

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

kerns.optimizers.rmsprop_v2 and kerns.optimizers.adadelta_v2 are the modules. You want:

from keras.optimizers import RMSprop, Adadelta

And:

optimizers.RMSprop(lr=0.0001, decay=1e-6) (or just RMSprop(lr=0.0001, decay=1e-6)) instead of optimizers.rmsprop_v2(lr=0.0001, decay=1e-6)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading