W1 Assignment 2 convolutional_model


I have created all the layers with the mentioned parameters but keep getting this below error. What could be causing this?

in convolutional_model(input_shape)
50 P2 = tfl.MaxPool2D((4, 4), 4, padding=‘same’)(A2)
—> 52 F = tfl.Flatten(P2)
53 ## Dense layer
54 ## 6 neurons in output layer. Hint: one of the arguments should be “activation=‘softmax’”

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/layers/core.py in init(self, data_format, **kwargs)
642 def init(self, data_format=None, **kwargs):
643 super(Flatten, self).init(**kwargs)
→ 644 self.data_format = conv_utils.normalize_data_format(data_format)
645 self.input_spec = InputSpec(min_ndim=1)
646 self._channels_first = self.data_format == ‘channels_first’

/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’

I have no idea.
Check if you have some mis-matched parenthesis in that cell farther above that line.

I checked all the parentheses and they are all matching correctly.

Anyway, I deleted all the code and rewrote it, now it all works!

Ok. I suspect there was a syntax error somewhere.

change F = tfl.Flatten(P2) to F = tfl.Flatten()(P2) I have same error. But I dont know what difference between F = tfl.Flatten()(F2) and F = tfl.Flatten(P2)


The layer functions in Keras return a function. You call the layer function with the parameters you want and it returns you a function which you then invoke with the appropriate input tensor.

Here’s a thread which gives you a guided tour of the Keras Sequential and Functional APIs.

1 Like