Week 1 Assignment 2 Convolutional Model Application Attribute Error

Hello

I’ve implemented the happymodel function, but it keeps throwing the Attribute error. Can someone help me with solving this issue?

Note that happyModel uses the Keras Sequential API. So what you are doing is creating a python list, each element of which is a defined (instantiated) layer function. That means you have to call the layer function with the defining parameters (e.g. number of filters for a conv layer or stride for a pooling layer or pad size for a padding layer). That then returns a function, so you’re making a list of “defined and created” functions. If you just list the function without invoking it to define the parameters (layer size or whatever), then you probably will get an error message like the one you got.

The syntax is a bit hard to get used to and they don’t do a very good job of explaining it in the notebook. As an example, if you want to add a “ReLU” layer, you can’t just say:

tfl.ReLU,

as part of the list, because that just gives the layer function itself. You need to call it like this:

tfl.ReLU(),

Note the comma on the end is because this is one element of a list of such layers.

Of course this will all be different in the next section where we switch to using the “Functional API”. There you need two steps: you call the layer function to define it and then actually invoke it with an input tensor. So in that section (not here), an invocation of ReLU would look like this:

outputTensor = tfl.ReLU()(inputTensor)

Note that is not for happyModel but the next section. Also note that all those parentheses are necessary and there is no comma at the end.

I was able to fix the issue. The reason was that I didn’t add the input shape parameter into my first layer. Thank you for your help!

I was able to resolve the issue. The reason was that I didn’t add the input shape parameter into my first layer. Thank you for your help!