Helpful Advice for Week 1 Assignment 2 Exercise 1

You might be stuck on this as I was. The input parameters are 64 X 64 X 3. However, if you use the example from the Keras documentation for ZeroPadding2d you will get an error about expecting 4 dimensions and only getting 3.

Technically this is true for the example as it’s expecting Batch, H, W, C. However the instructors didn’t tell us the batch size. In short, having us go to the documentation misled us.

I solved it. I suggest that you add another layer right at the start - an input layer of shape 64, 64, 3. Then don’t worry about passing input shapes (that’s the extra () after each layer function).

I feel like we really got thrown in the deep end on this assignment. I truly hope my advice saves you hours of head scratching.


Many thanks Chris for taking the time to share with others your solution and saving potential frustration in other students. Glad to see such engaged and active members in this community :smiley:

Happy learning



The creation of an Input layer is explicitly indicated in part 2 of this assignment but not in part 1. Seems like an overlooked detail.

1 Like

What helped me solve it, was discovering tfl.ZeroPadding2D() accepts “input_shape=shape_as_tuple” as one of its arguments [i.e. tfl.ZeroPadding2D(padding=(padding, padding), input_shape=(input_shape)] . The linked documentation does not show this, but further digging into Tensor flow reveals this.


I have found that with Tensorflow related assignments there seems to be a different approach. I am assuming they were written by another person and there clearly is an expection of a more than beginners knowledge of Tensorflow - not necessarily in sync with the limited exposure to this framework in the Deep Learning Specialisation

If you skipped Course 2 and came directly to Course 4, you missed the actual “intro to TF” here. That was given in Week 3 of Course 2.

But I agree that a lot of people feel that the amount of background they give in TF is not really as thorough as it should be. There are lots of TF tutorials out there (“google is your friend” in more ways than one :nerd_face:) and here’s a useful thread on Discourse from a fellow student who gives a much more thorough explanation of how to use the Sequential and Functional Models in Keras.

Hi Paul.
Could you please explain why axis=3 instead of 1 in the BatchNormalization() class.
Does 3 here refer to batch normalization of channel NC? If so, can you explain what goes into this process?
Thanks you in advance.

Had same doubts - you can refer to the answer in here:

Basically since the tensor is of shape (m, n_h, n_w, n_c) and we want to perform normalization over the channels, we select that axis which represents the channel’s dimension - which in this case is n_c.

After several years, this is still not clear in the documentation. I found the following thought useful: Because it is required to construct a Sequence Sequential Model, the first layer (ZeroPadding2D in this case) has to create the variables. For that, the Class Layer (from which all layers inherit) has a method called build, which has the argument input_shape. So, to create the variables in the first layer of the Sequence you have to pass the input_shape as *karg:

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

I hope that helps ! Cheers,

Thanks, Byron! Very nice explanation.

It’s a great point that TF is heavily “object oriented” and the documentation tries to keep things from getting too crazy by not documenting all the inherited attributes from the parent classes on every node in the tree. So you frequently need to “climb” the inheritance tree in the documentation in order to really get the full picture of how to use the various lower level APIs. Of course the other approach is to start reading the documentation from a higher level, e.g. the various tutorials and “how-to” topics they provide on the TF website.

Thank you for your feedback! I already made the correction you suggested. Cheers !