Model.summary() error without input layer

Hello,
I’m doing the practice C2_W2_Assignment. If I create the model without specifying the inputs, summary() throws the next error.

{remove by mentor}

Error

But if I define the input, the summary returns Ok.

{remove by mentor}

Why this error message? I thought the input was not required and would be determined by the model during the fit method calls.

Thanks.
Regards.

@gmazzaglia Well, think about it-- Your ‘input’ still does constitute a layer (the same way your output would).

It is not requiring the actual data at this stage, but at least it needs to know how many input nodes you have, or otherwise how else could it map out the model ?

1 Like

In this example, the model has not been fit yet, it’s only been created and then the summary printed.

So for the summary to work without the model being fit, you need to include an Input layer.

1 Like

Hi @gmazzaglia

In TensorFlow, the input shape must be known to properly initialize the weights of the first layer and to compute the shape of subsequent layers. If the input shape is not specified, the model cannot infer the dimensions and throws an error.

You can exclude an explicit input layer. Then, you need to specify the input shape in first layer of the model like this (in Sequential API):

layers.Dense(25, activation='relu', input_shape=(400,)),

1 Like

Hello, @gmazzaglia,

People before me has given 100% of the explanation, so I would just like to share an evidence that your input layer is helpful for summary to do its job:

image

Cheers,
Raymond

PS: We can’t share our assignment work publicly, so I would remove some screenshots for you.

@rmwkwok hey Raymond, thanks for chiming in-- I thought about pointing this out as well… but couldn’t understand… So I get the 25 x 400, but what is the extra + 25 all about ?

1 Like

Hi @rmwkwok , I didn’t realize it, sorry.

Regards.
Gus

1 Like

That’s not a problem :wink:

That’s for the bias. Each neuron has one bias.

Oh, yes, yes-- Of course, got you.

1 Like