C4W1A2-Dense function happyModel issues

Hello Folks,

Maybe you can help me out with some issues I am experiencing in the Keras tutorial from W1. When I try to generate the function happyModel, I experience the following error when calling dense function (I have already gone through the TensorFlow help, and it doesn’t work),

In order to indicate the way I am calling the function here you are a hint:

model = tf.keras.Sequential([…,tfl.Dense(1,activation=‘sigmoid’,name=‘FCL’)])

Please let me know if I am missing something,

Thank you in advance,



There may be an error in an earlier line of your code. Some things to check:

  • Within the […] structure, all of the layers should be separated by commas.
  • Try removing the “name=…” specification. I don’t see that argument listed in the Keras documentation.
1 Like

Do the commas need to be added after the command tfl.Dense(…)? I am also suspecting that I didn’t introduce well the input shape in the ZeroPadding2D method. How shall I introduce the input size?

The way I am doing it and it doesn’t work is the following one


But I am not able to detect my own failure



The layers are identified within a set of square brackets, separated by commas.
The last layer has no comma, because there is nothing to separate it from.

The instructions for zero padding specifically tell you to use “input shape of 64 x 64 x 3”. Those are hard-coded constants.

You can’t use those variable names, because they’re globals and won’t have the correct values in all situations.

1 Like

Thanks for the first answer, but I “hard coded the constant” bus I don’t know how I am supposed to hard code them. The way I introduce them is like,


but I still get the failure,

*TypeError: The added layer must be an instance of class Layer. Found: Tensor(“zero_padding2d_6/Pad:0”, shape=(None, 70, 70, 3), dtype=float32)

I am learning Keras but I have no clue how to get this issue sorted,



Use the “input_shape = …” argument, not a tfl.Input() layer.


thanks a lot, maybe it looks easy but as a rookie, this tip has been quite helpful, thanks again! BR Fran

I was having the exact same issue, and thanks to you and TMosh (question and answer). Thanks a lot

this solves all my problems! Thanks!

Thanks @TMosh, but I did not find this as an argument for ZeroPadding2D function from the TensorFlow Doc., there’s just the ‘padding’ and ‘dataformat’ args. How did you come to know about that argument??
Just curious cause I wasted so much time on this.
Also what’s that x in tf.keras.layers.ZeroPadding2D(padding=1)(x) in the example given in the doc., what does it signify???

1 Like

The “input_shape” argument is inherited from the parent class.
The argument “(X)” is how you provide data to the layer.

I added the argument you mentioned, but I still get this error:
Expected value

[‘ZeroPadding2D’, (None, 70, 70, 3), 0, ((3, 3), (3, 3))]

does not match the input value:

[‘InputLayer’, [(None, 64, 64, 3)], 0]

For the record, my zero padding is like this:
tfl.ZeroPadding2D(padding=3, input_shape=(64,64,3)),

Did you add an InputLayer? If you did, that’s not correct.

No, I didn’t. This is my first layer:

model = tf.keras.Sequential([
## ZeroPadding2D with padding 3, input shape of 64 x 64 x 3

        tfl.ZeroPadding2D(padding=3, input_shape=(64,64,3))
1 Like

In the Sequential model, you should not have a closing square bracket ‘]’ until the end of the list of all of the layers.

WIthin the list of layers, they should be separated by commas.

That’s the same way you create any list in Python.

Actually, I know it should be interpreted as a list. My whole code is full of all layers. This one is just my first layer in the Sequential list:

tfl.ZeroPadding2D(padding=3, input_shape=(64,64,3))

But I still get the error!

Hi @TMosh, could you clarify more on how to know that this “input_shape” argument should be provided?
I was just randomly clicking through a few layers in the tensorflow documentation and saw this which looks like the correct thing to do, But if I only searched for tf.keras.layers.ZeroPadding2D documentation, I would have never thought about using “input_shape”.

Sorry, but I am off-duty at this time.

That saved me!! The annoying thing is that “input_shape” argument is not listed the ZeroPadding2D api docs!!

1 Like

I have done this to see what the model outputs:


I would have expected the matrix to include 1s and 0s (since there is generally a threshold applied to sigmoid output so you can compare it to the true output), but it seems to include values between 0.9 and 1? I am unsure what the threshold the model is using and where to find this. I have looked at the TF documentation for the dense layer and also losses but they don’t seem to specify.

Thanks in advance!