Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

keras

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
like image 989
Love69 Avatar asked Nov 15 '20 12:11

Love69


People also ask

Why can't I find RMSProp in keras?

Try to import the optimizers from Tensorflow instead of Keras library. and it should be RMSprop not rmsprop. go to keras folder in your computer and search rmsprop. Probably rmsprop is in another folder and it's not in optimizers folder. Just like variables, modules in python are case-sensitive.

Why can’t I import name ‘Adam’ from ‘keras’?

importerror: cannot import name ‘adam’ from ‘keras.optimizers’ error occurs because of using keras import in the place of tensorflow.keras imports . See, Since Keras is one of the most popular High level deep learning libraries. Later on TensorFlow 2.0 version, Google Tensorflow Team has released an encapsulated keras library.

What are the best keras optimizers?

This is because Tensorflow is now the de facto Keras backend. The eight optimizers we went over are: Adam, SGD, RMSprop, Adagrad, Adadelta, Adamax, Nesterov-Accelerated Adam (Nadam), and FTRL. The most popular are Adam, SGD, and RMSprop.

Is it possible to use keras with TensorFlow?

If you want to use keras specifically, importing tensorflow.keras.optimizers won't work as it will conflict with other parts of your program. In this case use my solution instead. That's right. Also, if you'd like to use Adam, then you need to use the from keras.optimizers import adam_v2 statement.


1 Answers

It should be :

from tensorflow.keras.optimizers import RMSprop

instead of :

from keras.optimizers import RMSprop
like image 156
RAVIKUMAR NADUVIN Avatar answered Sep 29 '22 02:09

RAVIKUMAR NADUVIN