Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: module 'keras.optimizers' has no attribute 'Adam'

Tags:

python-3.8

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 !

like image 442
Raghu Avatar asked Sep 26 '21 10:09

Raghu


Video Answer


3 Answers

Use tf.keras.optimizers.Adam(learning_rate) instead of keras.optimizers.Adam(learning_rate)

like image 57
Abhinav Kaushal Keshari Avatar answered Oct 20 '22 09:10

Abhinav Kaushal Keshari


As per the documentation , try to import keras into your code like this,

>>> from tensorflow import keras

This has helped me as well.

like image 14
samrat230599 Avatar answered Oct 20 '22 10:10

samrat230599


Make sure you've imported tensorflow:

import tensorflow as tf 

Then use

tf.optimizers.Adam(learning_rate)
like image 5
Van Victor Avatar answered Oct 20 '22 08:10

Van Victor