C4W2 Assignment 2 Ex.2 GlobalAveragePooling not defined

I’ve fixed a number of coding errors for this exercise but cant seem to get around the NameError i keep getting regarding GlobalAveragePooling. The error message is below. Thanks for any help you may be able to provide.

NameError Traceback (most recent call last)
in
----> 1 model2 = alpaca_model(IMG_SIZE, data_augmentation)

in alpaca_model(image_shape, data_augmentation)
38 # use global avg pooling to summarize the info in each channel
39 nb_layers = len(base_model.layers)
—> 40 x = GlobalAveragePooling2D(x)
41 #include dropout with probability of 0.2 to avoid overfitting
42 x = tf.Keras.Droput(rate=0.2)(x)

NameError: name ‘GlobalAveragePooling2D’ is not defined

I think you forgot to include the “tfl.” prefix.
The Dropout layer should also have a tfl. prefix.

2 Likes

Thanks TMosh! I was indeed missing the prefix on both, however GlobalAvgPooling is still coming up as the source of my error. The error code is shown below.

AttributeError Traceback (most recent call last)
in
----> 1 model2 = alpaca_model(IMG_SIZE, data_augmentation)

in alpaca_model(image_shape, data_augmentation)
38 # use global avg pooling to summarize the info in each channel
39 nb_layers = len(base_model.layers)
—> 40 x = tfl.GlobalAveragePooling2D(x)
41 #include dropout with probability of 0.2 to avoid overfitting
42 x = tfl.Keras.Droput(rate=0.2)(x)

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/layers/pooling.py in init(self, data_format, **kwargs)
847 def init(self, data_format=None, **kwargs):
848 super(GlobalPooling2D, self).init(**kwargs)
→ 849 self.data_format = conv_utils.normalize_data_format(data_format)
850 self.input_spec = InputSpec(ndim=4)
851

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/utils/conv_utils.py in normalize_data_format(value)
190 if value is None:
191 value = backend.image_data_format()
→ 192 data_format = value.lower()
193 if data_format not in {‘channels_first’, ‘channels_last’}:
194 raise ValueError('The data_format argument must be one of ’

AttributeError: ‘Tensor’ object has no attribute ‘lower’

Hey TMosh, - i corrected some bad syntax and it seems to have solved the problem.

2 Likes

Great! Yes, there was a problem in how you invoked the GlobalPooling function. You need two steps: define the function and then invoke it. You only did one of those two steps.

Yup, that’s exactly what happened, plus a misspelling, Thanks paulinpaloalto, thanks TMosh!

1 Like