tf.keras.Sequential not working in happyModel

Hi,

For some reason the tf.keras.Sequential is not working for me, and I get a message that I have a comma on the left of the all the layers commands, but I don’t! Its on the right as it should!
I tried to use model.add to build the sequential and it also not working, giving similar errors, claiming some symbols being on the beginning of a command, when they’re actually at the end as it should! (See example below)
Im not sure, but maybe it relates to the fact that only in this course (CNN), for some reason all the writings in the jupyter notebook aligned to the right, not like in the previous courses, that they were aligned to the left as it should. Please help me here, as its very frustrating and Im wasting a lot of time on something that looks like a technical problem of coursera.

Example:
model = tf.keras.Sequential([
tfl.ZeroPadding2D(padding=3,(64,64,3)),
tfl.Conv2D(32,7),

])

the error I get:
file “”, line 21
,tfl.ZeroPadding2D(padding=3,(64,64,3))
^
SyntaxError: positional argument follows keyword argument

Hi yonatan.hayoun,

The only thing I can think of is trying to refresh you notebook. Maybe then the text will align correctly. You can find the description of how to do this here:

If this should not help you can try contacting the Coursera helpdesk here:

Good luck!

1 Like

The syntax you are using is problematic. You can’t follow a keyword argument with a positional one. The keyword argument in your example is “padding” and the second one (which should correspond to the argument “data_format”) is (64,64,3). This should work if you either type
tfl.Zeropadding(3, (64,64,3))
or
tfl.ZeroPadding(padding=3, data_format=(64,64,3))
(at least the syntax!!)

1 Like

That’s correct. See, e.g., python - positional argument follows keyword argument - Stack Overflow and 6. Expressions — Python 3.9.5 documentation

having a similar problem.pls help!
File “”, line 26
tfl.Conv2D(filters=32,kernal_size=(7,7),strides=1)
^
SyntaxError: invalid syntax
Capture
SOLVED!
I FORGOT THE COMMA BETWEEN LAYERS!
PUT COMMAS BETWEEN LAYERS.

2 Likes

Hello there. I am having a similar issue with ZeroPadding2D.

Input
tfl.ZeroPadding2D(padding=3, data_format=(64,64,3)),
tfl.Conv2D(filters=32,kernel_size=(7,7),strides=(1,1)),

Error
—> 34 tfl.ZeroPadding2D(padding=3, data_format=(64,64,3)),
35 tfl.Conv2D(filters=32,kernel_size=(7,7),strides=(1,1)),
36 tfl.BatchNormalization(axis=3),

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/layers/convolutional.py in init(self, padding, data_format, **kwargs)
2800 def init(self, padding=(1, 1), data_format=None, **kwargs):
2801 super(ZeroPadding2D, self).init(**kwargs)
→ 2802 self.data_format = conv_utils.normalize_data_format(data_format)
2803 if isinstance(padding, int):
2804 self.padding = ((padding, padding), (padding, padding))

/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: ‘tuple’ object has no attribute ‘lower’

I’m not entirely sure where exactly im going wrong here.

1 Like

I believe data_form is not for the input size of the model! This argument is actually supposed to be a string and i believe we do not need to set it here!

34 tfl.ZeroPadding2D(padding=3, data_format=(64,64,3))
change data_format to input_shape
tfl.ZeroPadding2D(padding=3,input_shape=(64,64,3))

2 Likes

Thank you @OAN and @rebeldose! It worked out perfectly

I forgot too, waste too much time

what do you mean by MISSING COMMA because i don’t understand

In the Sequential model, you’re creating a python list.
Each element in the list is a layer.
In a list, the elements must be separated by commas, and enclosed in outer square brackets.

I know it’s been a while since this thread was active…
But I don’t understand the meaning of the input_shape argument here. It’s not in the function’s argument list. So how does mentioning it explicitly solves this?

Please post a new thread for this topic.