Search code examples
python-2.7deep-learningkeras

Error in keras - name 'Dense' is not defined


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?


Solution

  • You need from keras.layers import Activation, Dense.