Week 1 Assignment 2 Input Shape configuration

I’ll try to point out something that stuck out in this assignment without actually sharing anything of value for completing the assignment.

The assignment instructs you to use a ZeroPadding2D layer with an input shape of 64 x 64 x 3. This seems to be the intention of the person who wrote the assignment:

## ZeroPadding2D with padding 3, input shape of 64 x 64 x 3
tfl.ZeroPadding2D(..., input_shape=(64, 64, 3)),

However, this is not actually documented in the ZeroPadding2D documentation, and is a bit of a nasty subtle gotcha to just casually have sitting there with no emphasis to be cautious of it, or where to look in the Keras documentation to solve it.

It seems like it might not even be idiomatic Keras usage - from reading the Keras documentations, it seems there is an Input layer that is intended to be used for setting the shape:

# Define input shape of 64 x 64 x 3
tfl.Input(shape=(64, 64, 3)),
## ZeroPadding2D with padding 3, input shape of 64 x 64 x 3
tfl.ZeroPadding2D(...), 

Here is an example from the Keras documentation: Simple MNIST convnet

The assignment is probably fine as is - but it seems like an unnecessary use of time to have people getting stuck on such a trivial piece of configuration rather than on the actual ConvNet itself. Adding the Input layer to the assignment documentation, or otherwise suggesting how to configure the input shape would be a useful improvement, I feel.

1 Like

Thanks for your suggestion.

TensorFlow documentation is no thing of beauty, to be sure.

Note that ZeroPadding2D() inherits from Layer, which supports the input_shape parameter.

There is more than one way to specify the input shape. This assignment uses one of the methods, without much explanation.

1 Like

I absolutely agree with you and I was really getting quite anxious about it. In the official documentation, only two arguments are allowed in the ZeroPadding2Dlayer (padding and data_format). I finally found some non-official description of the function, where the “parameters” also included inputShape. I was excited to use it (inputShape = (64, 64, 3)) only to find out that it also does not work (it should be “input_shape”, not “inputShape”). (Originally, I was putting it into an extra set of parentheses after the ZeroPadding2D which seemed to be the way it was done on the internet.)
Even though I like a bit of challenge in the assignments, I felt we were really left hanging. We had never seen the syntax before (tensorFlow intro in the previous course did not use this style of syntax) and the official and unofficial documentation was of no help.