How to fix: AttributeError: module 'tensorflow' has no attribute 'optimizers' in JupyterNotebook (using colab.research)
Asked Answered
T

2

8

I am trying to run my neural network in colab.research page, but I am still getting error AttributeError: module 'tensorflow' has no attribute 'optimizers' at this line:

opt = tensorflow.optimizers.RMSprop(learning_rate=0.00001, decay=1e-6)

My importing part from the code:

import tensorflow
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten
from tensorflow.keras.layers import Conv2D, MaxPooling2D
from keras import optimizers
import os

Tensorflow version:

print(tensroflow.__version__) # 1.15.0
Tonita answered 13/11, 2019 at 12:37 Comment(0)
C
11

optimizers is part of the keras library. Either do

from tensorflow.keras import optimizers

And then use

optimizers.RMSprop()

in your code Or

opt = tensorflow.keras.optimizers.RMSprop()
Confederacy answered 13/11, 2019 at 12:52 Comment(1)
opt = tensorflow.keras.optimizers.RMSprop()Moorer
F
0

Use this:

opt = tensorflow.compat.v1.train.RMSPropOptimizer(learning_rate=0.00001, decay=1e-6)

Reference: https://www.tensorflow.org/api_docs/python/tf/compat/v1/train/RMSPropOptimizer

Fingertip answered 10/6, 2021 at 22:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.