Convolutional Networks Week 1 Assignment 2

There is a problem with the adding the Conv2D() using the Sequential API. It give an error:

“This layer has never been called and thus has no defined output shape”. Someone else has posted this error earlier in the class forum only to be told that discussions have moved over here with anyone bothering answering them. I hope I have better luck.

Note that you posted this in “General Discussion”. I’ve moved it for you to DLS Course 4 (by using the little “edit pencil” on the title). You’ll have better luck getting answers if you post things in the relevant categories. There are quite a lot of different Deeplearning.AI courses which use this Discourse instance.

That error means you have not using the Keras “layer” functions correctly. There are two steps to using each layer function:

  1. You invoke it with the parameters that describe how you want it to act. E.g. for a Conv2D layer, that includes the padding, stride and kernel size among other things. This operation gives you back the “instantiated” function with the properties you have requested.
  2. Then you need to call that function with an input tensor (in the case of the Functional API) or just add the new function to the list of layers (in the case of the Sequential API). You’re in the Sequential case. The point of the Sequential API is that you don’t have to do the “second level” explicit invocation with the input tensor: that is implied by the list of layers. When you execute the model, it does the invocations for you feeding the output of each layer as the input to the next layer in the list.

I grant you that the instructions they give are not as helpful as they could be and the Keras documentation is also not so good at this type of “general usage” guidance. Your best bet to understand more of the details here is to have a look at this thread, created by one of our fellow students here, which gives the best introduction I’ve seen to how to use the Sequential and Functional Keras APIs.

I found a solution to my problem.
When using the sequentail() API, the first thing to do before the zero padding is to setup a call to the input function using the shape that is given in the comments. Once the input call is setup things seemed to flow smoothly

I think you probably fixed several problems, but it is great to hear that you found the solution!