Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in keras - name 'Dense' is not defined

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?

like image 446
vivek Avatar asked May 12 '16 06:05

vivek


2 Answers

You need from keras.layers import Activation, Dense.

like image 80
1'' Avatar answered Nov 06 '22 06:11

1''


I had a similar problem in tensorflow 2.0 and solved it by using

from tensorflow.keras.layers import Dense
like image 2
user12888738 Avatar answered Nov 06 '22 06:11

user12888738