7

I am trying to play around with Keras a little.

When I try the following code :

from keras.layers import Dense

I get the following error:

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    from keras.layers import Dense
ImportError: cannot import name 'Dense'

I am using Python 3.4.3, I am on a Windows 8 64 bit machine.

Thank you.

3 Answers 3

21

The error is telling you that it found nothing named Dense in that module.

Perhaps you meant from keras.layers.core import Dense?

2
  • Worked Perfectly. I, however, have a small query. How did you know that this was the solution? I mean, what was your problem-solving methodology? Commented Sep 22, 2016 at 19:16
  • 3
    I googled "python keras layers dense", went to the top search result page, saw there was an object named Dense on that page, and noted that the full module name of that object was keras.layers.core.Dense. Commented Sep 22, 2016 at 19:19
0

from keras.layers.core import Dense, Activation

when trying to import above line i was facing error. The answer would be

from keras.layers import Dense, Activation as core module do not contain Activation.

-1

use

from tensorflow.keras.layers import Dense
1
  • For me, from tensorflow.keras.layers import Dense solved the issue.
    – Wanderer
    Commented Mar 2, 2022 at 11:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.