When i am using "optimizer = keras.optimizers.Adam(learning_rate)" i am getting this error "AttributeError: module 'keras.optimizers' has no attribute 'Adam". I am using python3.8 keras 2.6 and backend tensorflow 1.13.2 for running the program. Please help to resolve !
Asked
Active
Viewed 5.7k times
5 Answers
29
Use tf.keras.optimizers.Adam(learning_rate)
instead of keras.optimizers.Adam(learning_rate)

Abhinav Kaushal Keshari
- 536
- 4
- 9
-
Awesome, this works. But follow-up question: What is the difference between the modules `keras` and `tensorflow.keras`? – KingOtto Oct 23 '21 at 15:46
-
1tensorflow.keras is the adopted version of keras by tensorflow. You can read more here: https://stackoverflow.com/a/63517100/4584901 – Abhinav Kaushal Keshari Oct 23 '21 at 19:11
14
As per the documentation , try to import keras
into your code like this,
>>> from tensorflow import keras
This has helped me as well.

tarmas99
- 359
- 1
- 11
5
Make sure you've imported tensorflow:
import tensorflow as tf
Then use
tf.optimizers.Adam(learning_rate)

ZygD
- 22,092
- 39
- 79
- 102

Van Victor
- 51
- 2
1
There are ways to solve your problem as you are using keras 2.6 and tensorflow too:
- use (from keras.optimizer_v2.adam import Adam as Adam) but go through the function documentation once to specify your learning rate and beta values
- you can also use (Adam = keras.optimizers.Adam).
- (import tensorflow as tf) then (Adam = tf.keras.optimizers.Adam)
Use the form that is useful for the environment you set

Bharath Jatoth
- 73
- 4
0
I think you are using Keras directly. Instead of giving as from keras.distribute import —> give as from tensorflow.keras.distribute import
Hope this would help you.. It is working for me.

Harika M
- 1
- 1