Course 4 week 1 Assignment 2 ex 1

really really need some help

{moderator edit - solution code removed}

When you use the Sequential model, you’re creating a python list.
This means the layers must be within a set of square brackets, and be separated by commas.

In the assert in your second image, you’re missing a comma before “data_format”.

Also, please don’t post your code on the forum. That breaks the community standards.
If a mentor needs to see your code, we’ll ask you to send it via a private message.

There are two different methods here: the Keras Sequential API and the Keras Functional API.

In the Sequential case, you only instantiate the “layer” functions and then make list with commas, as Tom pointed out.

In the Functional case, you both instantiate the “layers” and then actually invoke them with an input tensor. No commas required.

You are using the Sequential method, but you omitted the commas and the syntax that closes off the list and the Sequential declaration.

You can argue that they did not really give us much to go on here. You would probably be well served to spend a bit of time reading through this thread from fellow student ai_curious about how these two methods work.

1 Like

I placed the layers within two square brackets. and also placed the comma before “data_format”
I’m still getting a syntax error

And also placed commas between each of the layers. I’m still getting a syntax error

Course policy does prohibit posting solutions (source code) but it’s hard to help with syntax errors without seeing the error message itself. Remember that Python syntax errors are reported by the parser; there is something fundamentally out of compliance with the language specification. Further, The parser repeats the offending line and displays a little ‘arrow’ pointing at the earliest point in the line where the error was detected. The error is caused by (or at least detected at) the token preceding the arrow

Maybe start at the indicated token and work backwards, looking for typographic errors too. And share the particular error you’re getting.

{mentor edit: code removed - the problem was a missing comma in the parameter list)

this is it

I just checked. the arrow is on the “l” of “tfl”. I dont get why thats the case. the instructions in the assignment stated we could use tfl in place of tensorflow.keras.layers

Well, that looks like source code again, not the error message, but ok. Compare what you have to what is on the Keras doc page.

    max_value=None, negative_slope=0.0, threshold=0.0, **kwargs

Look carefully at the list, ahem, of parameters


This is the error

Alright. I fixed that and got myself a new error

You have to be very careful when you mix named and unnamed parameters in the same layer definition.

If you don’t name the parameters, “strides” is defined as the third value.

But you have both an unnamed third value, and then you also have a named strides parameter.

Check the definition for the Keras Conv2D layer:

1 Like

Both the ReLU and Conv2D syntax errors have the same root cause; non-compliance with the documented function parameters. I never saw the code, but it seems like the original Sequential error was, too. So my advice would be to get in the practice of really looking carefully at the official documentation and any examples provided there when you write your code. Do a detailed comparison and understand whether the differences will cause trouble. There might also be some benefit from an editor that supports typeahead, such as Jupyter Lab (instead of Notebook). Especially until you develop more fluency. HTH

Thank you for the tips. I’ve been able to complete the exercise. took me a whole day but I think I’ve learnt a thing or two. Thank you