Error in keras - name 'Dense' is not defined
37,777
Solution 1
You need from keras.layers import Activation, Dense
.
Solution 2
I had a similar problem in tensorflow 2.0 and solved it by using
from tensorflow.keras.layers import Dense
Author by
vivek
Updated on July 09, 2022Comments
-
vivek almost 2 years
I'm new to Deep Neural Network libraries in python. I've installed Theano & keras in my windows system by following these steps(I already had anaconda):
Install TDM GCC x64.
Run the below code from command prompt
conda update conda conda update --all conda install mingw libpython pip install git+git://github.com/Theano/Theano.git pip install git+git://github.com/fchollet/keras.git
When I'm running the following code in Ipython,
import numpy as np import keras.models from keras.models import Sequential model = Sequential() model.add(Dense(32, input_shape=(784,))) model.add(Activation('relu'))
it is showing the following error:
NameError
Traceback (most recent call last)
----> 1 model.add(Dense(32, input_shape=(784,)))
NameError: name 'Dense' is not defined
Here is the error message screenshot.
How come sequential was imported successfully and 'Dense' was not defined?
-
vivek almost 8 yearsThanks for the reply.