Week 1 Programming Assignment 2

Hello, implementing convolutional_model() function returns AttributeError: ‘Flatten’ object has no attribute ‘shape’ error.
The error is shown in the line:

outputs = tf.keras.layers.Dense(units=6, activation='softmax')(F)

The error refers to the Flatten() layer. Not the Dense() layer.

1 Like

Thanks for the reply :smiley:smile:
The flatten layer looks like this:

F = tf.keras.layers.Flatten()

You have to pass the a data argument to the Flatten layer. That’s what’s missing, so the interpreter is looking at the next line hoping to find it. That’s why it flags the error on the Dense() line.


Hello, thanks for the reply. I read the documentations on Flatten layer and it turns out it only takes a single argument data_format. How should I pass some data argument in the layer?

Just like you did for all the other layers, you add (…) with the data argument inside it.


I just tried it and it worked! Thanks a lot sir!