# Model.summary() error without input layer

**URL:** <https://community.deeplearning.ai/t/model-summary-error-without-input-layer/644939>\
**Category:** Advanced Learning Algorithms\
**Tags:** week-module-2\
**Created:** [June 11, 2024, 12:04am UTC](https://community.deeplearning.ai/t/model-summary-error-without-input-layer/644939 "2024-06-11T00:04:14Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![gmazzaglia](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/gmazzaglia/32/147125_2.png) [@gmazzaglia](https://community.deeplearning.ai/u/gmazzaglia)\
**Post date:** [June 11, 2024, 12:04am UTC](https://community.deeplearning.ai/t/model-summary-error-without-input-layer/644939/1 "2024-06-11T00:04:14Z")

</div>

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

 ![image](https://global.discourse-cdn.com/dlai/original/3X/b/1/b1ff76b99041e938e355f92027ef6f60e623eee0.png)

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

{remove by mentor}

 ![image](https://global.discourse-cdn.com/dlai/original/3X/3/f/3f7801456215fa7575f4157520a7d74211b5235b.png)

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.

---

<div class="post-metadata">

**Author:** ![Nevermnd](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/nevermnd/32/126021_2.png) [@Nevermnd](https://community.deeplearning.ai/u/Nevermnd)\
**Post date:** [June 11, 2024, 1:21am UTC](https://community.deeplearning.ai/t/model-summary-error-without-input-layer/644939/2 "2024-06-11T01:21:52Z")

</div>

@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 ?

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [June 11, 2024, 7:11am UTC](https://community.deeplearning.ai/t/model-summary-error-without-input-layer/644939/3 "2024-06-11T07:11:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Alireza\_Saei](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/alireza_saei/32/85175_2.png) [@Alireza\_Saei](https://community.deeplearning.ai/u/Alireza_Saei)\
**Post date:** [June 11, 2024, 7:21am UTC](https://community.deeplearning.ai/t/model-summary-error-without-input-layer/644939/4 "2024-06-11T07:21:38Z")

</div>

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,)),`

---

<div class="post-metadata">

**Author:** ![rmwkwok](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rmwkwok/32/126977_2.png) [@rmwkwok](https://community.deeplearning.ai/u/rmwkwok)\
**Post date:** [June 11, 2024, 8:47am UTC](https://community.deeplearning.ai/t/model-summary-error-without-input-layer/644939/5 "2024-06-11T08:47:42Z")

</div>

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](https://global.discourse-cdn.com/dlai/original/3X/4/5/45f640c0ee332c59c84d9c65c6d622164b54eba1.png)

Cheers,  
Raymond

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

---

<div class="post-metadata">

**Author:** ![Nevermnd](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/nevermnd/32/126021_2.png) [@Nevermnd](https://community.deeplearning.ai/u/Nevermnd)\
**Post date:** [June 11, 2024, 12:16pm UTC](https://community.deeplearning.ai/t/model-summary-error-without-input-layer/644939/6 "2024-06-11T12:16:38Z")

</div>

@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 ?

---

<div class="post-metadata">

**Author:** ![gmazzaglia](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/gmazzaglia/32/147125_2.png) [@gmazzaglia](https://community.deeplearning.ai/u/gmazzaglia)\
**Post date:** [June 11, 2024, 12:20pm UTC](https://community.deeplearning.ai/t/model-summary-error-without-input-layer/644939/7 "2024-06-11T12:20:06Z")

</div>

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

Regards.  
Gus

---

<div class="post-metadata">

**Author:** ![rmwkwok](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rmwkwok/32/126977_2.png) [@rmwkwok](https://community.deeplearning.ai/u/rmwkwok)\
**Post date:** [June 11, 2024, 12:43pm UTC](https://community.deeplearning.ai/t/model-summary-error-without-input-layer/644939/8 "2024-06-11T12:43:00Z")

</div>

That’s not a problem 😉

---

<div class="post-metadata">

**Author:** ![rmwkwok](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rmwkwok/32/126977_2.png) [@rmwkwok](https://community.deeplearning.ai/u/rmwkwok)\
**Post date:** [June 11, 2024, 12:43pm UTC](https://community.deeplearning.ai/t/model-summary-error-without-input-layer/644939/9 "2024-06-11T12:43:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nevermnd](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/nevermnd/32/126021_2.png) [@Nevermnd](https://community.deeplearning.ai/u/Nevermnd)\
**Post date:** [June 11, 2024, 1:32pm UTC](https://community.deeplearning.ai/t/model-summary-error-without-input-layer/644939/10 "2024-06-11T13:32:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mushi](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@Mushi](https://community.deeplearning.ai/u/Mushi)\
**Post date:** [June 21, 2024, 11:32am UTC](https://community.deeplearning.ai/t/model-summary-error-without-input-layer/644939/12 "2024-06-21T11:32:51Z")

</div>

This is how it’s calculated the parameters for the layer  
W: The parameter ‘W’ will be decided based on this formula  
Sin x Sout  
Were ‘Sin’ is the number of inputs and ‘Sout’ is the number of outputs/units

b: calculated by the number of units in a layer
