Course 4 Week 1 Assignment no 2 Issue while creating Sequential layer

In assignment 2 , inside happyModel() function , I wanted to create Sequential layer by first instantiating the Sequence() and then adding layers one by one , but here I am getting error that
AttributeError: The layer has never been called and thus has no defined output shape.
I don’t understand this line tried stackoverflow also but not that much help, can anyone tell me meaning of the error.

   from tensorflow.keras.models import Sequential
    from tensorflow.keras.layers import ZeroPadding2D, Conv2D, BatchNormalization, ReLU, 
    MaxPooling2D, Flatten,Dense
    model = tf.keras.Sequential()
    model.add(Conv2D(32, (7,7),strides=1))
    model.add(Dense(1,activation = 'sigmoid'))

Here is the screenshot of the error:

I guess you are getting this error because, you haven’t defined the input_shape argument in the ZeroPadding2D layer. And this leads to an error because the further layers depends on the shapes of their inputs.

1 Like

Thanks, that was causing problem.
If you don’t mind can you tell me why we need to define input shape.
As when I don’t define it I am getting error :
AttributeError: The layer has never been called and thus has no defined output shape.

what is the meaning of this line?

If I am correct, then it is because that when you are trying to add ZeroMaxPadding2D without the input_shape argument, it raises an error, and your model as of now, consists of only the sequential layer.
But Sequential and Functional, as we learned are just the wrappers for models, so essentially there your model is an empty model, and therefore is not called, and since it is not called, hence no output shape as well

how to do that can you please tell

try inserting the keyword argument in the function arguments of tensorflow.keras.layers.ZeroPadding2D( padding=(-,-), input_shape=(-,-,-) )