Course 4, Week 1, Assignment 2, Ex. 2 Attribute Error

Received the below error diagnostic for exercise 2. I believe my syntax for flattening as well as the line prior to it for Maxpool is ok but the diagnosics say otherwise. Can anyone help? Thanx in advance.

AttributeError Traceback (most recent call last)
----> 1 conv_model = convolutional_model((64, 64, 3))
2 conv_model.compile(optimizer=‘adam’,
3 loss=‘categorical_crossentropy’,
4 metrics=[‘accuracy’])
5 conv_model.summary()

in convolutional_model(input_shape)
—> 59 F = tf.keras.layers.Flatten()(P2)
61 ## Dense layer

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/ in call(self, *args, **kwargs)
980 with ops.name_scope_v2(name_scope):
981 if not self.built:
→ 982 self._maybe_build(inputs)
984 with ops.enable_auto_cast_variables(self._compute_dtype_object):

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/ in _maybe_build(self, inputs)
2616 if not self.built:
2617 input_spec.assert_input_compatibility(
→ 2618 self.input_spec, inputs,
2619 input_list = nest.flatten(inputs)
2620 if input_list and self._dtype_policy.compute_dtype is None:

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/ in assert_input_compatibility(input_spec, inputs, layer_name)
164 spec.min_ndim is not None or
165 spec.max_ndim is not None):
→ 166 if x.shape.ndims is None:
167 raise ValueError('Input ’ + str(input_index) + ’ of layer ’ +
168 layer_name + ’ is incompatible with the layer: ’

AttributeError: ‘MaxPooling2D’ object has no attribute ‘shape’

  1. List item

Hey @ekennedy , could you share your notebook with me in a direct message ? I could then help you with it. Thanks.

Thank you. I hate to trouble you more but how do i do that?

You can follow these instructions to download the notebook:How to Download Your Notebook

Then once you have, click on my name and choose to message me. There you can attach your notebook and send.

AttributeError: ‘MaxPooling2D’ object has no attribute ‘shape’

As stated in the statement, the correct attribute name is pool_size.

Thank you cmarquay. The pool_size attribute was present when the error appeared. The (partial) syntax was P2 = tf.keras.layers.MaxPool2D(pool_size=(4, 4), … If i interpreted the error code correctly it was the second call to MaxPool2D that flagged the error and not the first call which is identical to the second in terms of the syntax. Could i have botched something else?

which is identical to the second in terms of the syntax.

Pay attention to the statement. In the Sequential API, MaxPool2D is called with the default parameters. In the Functional API, MaxPool2D has window 4x4, stride 4 and padding ‘SAME’.

Thanks again but i am missing the point. Per the instructions P2 has the parameters you mentioned but P1 was set to an 8x8 window, a stride of 8 and ‘SAME’ padding. I tried changing P1 to the same parameters as P2 just to see what happens but continued to get the same error.

Hey Mubsi;
Do you have any further guidance on where i botched my code? cmarquay has identified the MaxPool2D as where the botch is. I do not disagree, however i’m having trouble seeing where i made the mistake there.