C4 week 1 convolutional_model

It took me 4 hours to fix it ! but not OK

{moderator edit - solution code removed}

AttributeError: ‘Dense’ object has no attribute ‘op’

Hi, I had same issue and have figured out. You have to specify the input for each API.
For example:

{moderator edit - solution code removed}

and so on.
The final input for Dense function will be (F)

4 Likes

Exactly! We are using the “Functional API” in this section, not the “Sequential API”. The syntax is different, as @veenay has pointed out. Please read through the examples they show in the instructions for that section.

Also note that you have a stray trailing “,” (comma) after the Flatten function. That is a holdover from the “Sequential” syntax and it will make a mess when you are using the “Functional” syntax.

Also please note that we don’t want solution source code to be left showing in the Forums. Once you get this solved @trongduynguyen, please go back and edit your post to remove the source code. Thanks!

2 Likes

thank you so much !
How do I do this step? can you help me to solve it?

F =tf.keras.layers.Flatten()
outputs= tf.keras.layers.Dense(6,activation=‘softmax’)
# YOUR CODE ENDS HERE
model = tf.keras.Model(inputs=input_img, outputs=outputs)
return model

@trongduynguyen: Did you do as I suggested and read the instructions? They literally wrote that line of code for you in the instructions. I mean the invocation of the “Dense” layer. The point of the “Functional API” syntax is that this function invocation returns a function:

tf.keras.layers.Dense(... some parameters describing the Dense layer you want ...)

So you then need to invoke the resulting function and pass it the actual arguments:

tf.keras.layers.Dense(... some parameters ...)(... the arguments for the Dense function ...)

They give you a very specific line of code in the instructions, but I’m just giving the background explanation for why that line of code looks the way it does.

1 Like

Thank you! I have succeeded <33

I’m stuck in the same place, but none of my solutions are working:

{moderator edit - solution code removed}

I get a bunch of errors, but notably it gets stuck right at the first ReLU call.

39 A1 = tf.keras.layers.ReLU(Z1)

Please help. I’ve been at this for hours and I cannot get to the bottom of it.

oops. nevermind. I saw my mistake. you ALWAYS need two sets of (). the first is to choose the function parameters, even if they’re the defaults… the second is to identify the argument of that function. fun(… params)(argument) as Dr. Paul had already explained. I was so sure I was doing that, but I overlooked that subtlety in the cases for which I chose the defaults parameters. Won’t be making that mistake again… (I hope.)

People reading this thread and still confused about model definition syntax might benefit from reading this one → Tips for troubles with Sequential and Functional API syntax

1 Like

i had skimmed through that page before, but, for me, the most relevant portion didn’t really emerge until very near the end, so it was easy for me to miss. unfortunately, many explanations are written from the point of view of someone who already knows it, so it can be difficult to pinpoint the source of confusion. now that i know the syntax, it’s obvious, and appear to have been right there in front of me the whole time. but the function(…params)(argument) construction wasn’t front-and-center in any of the documentation i searched. just my $0.02.