ImportError: cannot import name 'rmsprop' from 'keras.optimizers'

Viewed 33116

can anybody help me. when I try to run my codes they an error ImportError: cannot import name 'rmsprop' from 'keras.optimizers'

bellow are the libraries and all imports I used.

import gym
import random
from keras.models import Sequential
from keras.layers import Dense, Dropout
from keras.optimizers import rmsprop, Adam
import numpy as np
import matplotlib.pyplot as plt
from collections import deque
from statistics import mean
import h5py
4 Answers

It should be :

from tensorflow.keras.optimizers import RMSprop

instead of :

from keras.optimizers import RMSprop

Try to import the optimizers from Tensorflow instead of Keras library.

from tensorflow.keras import optimizers
optimizers.RMSprop
optimizers.Adam

or you can directly import the required optimizer as:

from tensorflow.keras.optimizers import RMSprop,Adam

and it should be RMSprop not rmsprop.

It’s because you need to do

from keras.optimizers import RMSprop

As opposed to

from keras.optimizers import rmsprop

Just like variables, modules in python are case-sensitive.

go to keras folder in your computer and search rmsprop. Probably rmsprop is in another folder and it's not in optimizers folder.

Related