sam achmad
sam achmad

Reputation: 11

how can i fix this : AttributeError: module 'tensorflow_core.python.keras.api._v2.keras' has no attribute 'Dense'

AttributeError: module 'tensorflow_core.python.keras.api._v2.keras' has no attribute 'Dense' in model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu)) model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))model.add(tf.keras.Dense(10, activation=tf.nn.softmax)

Upvotes: 0

Views: 4810

Answers (1)

Andrea Angeli
Andrea Angeli

Reputation: 745

In your last model.add() call, you try to use tf.keras.Dense instead of tf.keras.layers.Dense. Modify you code to the following:

    model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))
    model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))
    model.add(tf.keras.layers.Dense(10, activation=tf.nn.softmax) # <-- your typo was in this line

Upvotes: 3

Related Questions