# Convolution\_model\_Application - getting error while running happymodel()

**URL:** <https://community.deeplearning.ai/t/convolution-model-application-getting-error-while-running-happymodel/31384>\
**Category:** Convolutional Neural Networks\
**Tags:** coursera-platform\
**Created:** [August 26, 2021, 2:02pm UTC](https://community.deeplearning.ai/t/convolution-model-application-getting-error-while-running-happymodel/31384 "2021-08-26T14:02:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![clonesangram](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/clonesangram/32/6421_2.png) [@clonesangram](https://community.deeplearning.ai/u/clonesangram)\
**Post date:** [August 26, 2021, 2:02pm UTC](https://community.deeplearning.ai/t/convolution-model-application-getting-error-while-running-happymodel/31384/1 "2021-08-26T14:02:36Z")

</div>

Can anyone help me understand where am I doing wrong? I can’t find the issue.  
I am getting below error while running the below code

happy\_model = happyModel()

# Print a summary for each layer

for layer in summary(happy\_model):  
print(layer)

output = [[‘ZeroPadding2D’, (None, 70, 70, 3), 0, ((3, 3), (3, 3))],  
[‘Conv2D’, (None, 64, 64, 32), 4736, ‘valid’, ‘linear’, ‘GlorotUniform’],  
[‘BatchNormalization’, (None, 64, 64, 32), 128],  
[‘ReLU’, (None, 64, 64, 32), 0],  
[‘MaxPooling2D’, (None, 32, 32, 32), 0, (2, 2), (2, 2), ‘valid’],  
[‘Flatten’, (None, 32768), 0],  
[‘Dense’, (None, 1), 32769, ‘sigmoid’]]

comparator(summary(happy\_model), output)

* * *

TypeError Traceback (most recent call last)  
 in   
----\> 1 happy\_model = happyModel()  
2 # Print a summary for each layer  
3 for layer in summary(happy\_model):  
4 print(layer)  
5

in happyModel()  
41 tfl.MaxPool2D(pool\_size=(2, 2)),  
42 tfl.Flatten(),  
—\> 43 tfl.Dense(1, activation = ‘sigmoid’)  
44  
45

/opt/conda/lib/python3.7/site-packages/tensorflow/python/training/tracking/base.py in \_method\_wrapper(self, \*args, \*\*kwargs)  
455 self.\_self\_setattr\_tracking = False # pylint: disable=protected-access  
456 try:  
 → 457 result = method(self, \*args, \*\*kwargs)  
458 finally:  
459 self.\_self\_setattr\_tracking = previous\_value # pylint: disable=protected-access

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/sequential.py in **init** (self, layers, name)  
140 layers = [layers]  
141 for layer in layers:  
 → 142 self.add(layer)  
143  
144 @property

/opt/conda/lib/python3.7/site-packages/tensorflow/python/training/tracking/base.py in \_method\_wrapper(self, \*args, \*\*kwargs)  
455 self.\_self\_setattr\_tracking = False # pylint: disable=protected-access  
456 try:  
 → 457 result = method(self, \*args, \*\*kwargs)  
458 finally:  
459 self.\_self\_setattr\_tracking = previous\_value # pylint: disable=protected-access

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/sequential.py in add(self, layer)  
180 raise TypeError('The added layer must be ’  
181 'an instance of class Layer. ’  
 → 182 'Found: ’ + str(layer))  
183  
184 tf\_utils.assert\_no\_legacy\_layers([layer])

TypeError: The added layer must be an instance of class Layer. Found: Tensor(“zero\_padding2d\_63/Pad:0”, shape=(None, 70, 70, 3), dtype=float32)

Below is my happymodel function

# GRADED FUNCTION: happyModel

Mentor edit: removed all but the incorrect line of code:

` tfl.ZeroPadding2D(padding=3)(tf.keras.Input(shape = (64, 64, 3))),`

---

<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:** [August 26, 2021, 3:16pm UTC](https://community.deeplearning.ai/t/convolution-model-application-getting-error-while-running-happymodel/31384/2 "2021-08-26T15:16:45Z")

</div>

For starters:  
In the Sequential model, do not pass any data to the layers individually. So your code for passing the input shape doesn’t belong in a separate set of parenthesis. And it isn’t a separate Input layer.

Instead you should pass an additional “input\_shape =…” argument, with the size as a tuple.

---

<div class="post-metadata">

**Author:** ![clonesangram](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/clonesangram/32/6421_2.png) [@clonesangram](https://community.deeplearning.ai/u/clonesangram)\
**Post date:** [August 26, 2021, 3:29pm UTC](https://community.deeplearning.ai/t/convolution-model-application-getting-error-while-running-happymodel/31384/3 "2021-08-26T15:29:36Z")

</div>

Thanks for this. I was struggling from 1 day b’coz the input shape argument is not mentioned in tensorflow document - [tf.keras.layers.ZeroPadding2D &nbsp;|&nbsp; TensorFlow Core v2.6.0](https://www.tensorflow.org/api_docs/python/tf/keras/layers/ZeroPadding2D)

---

<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:** [August 26, 2021, 4:15pm UTC](https://community.deeplearning.ai/t/convolution-model-application-getting-error-while-running-happymodel/31384/4 "2021-08-26T16:15:37Z")

</div>

The Keras documentation is very thin. And it never mentions any of the arguments that are inherited from other classes. So you have to backtrack a long way sometimes to find the information.

---

<div class="post-metadata">

**Author:** ![clonesangram](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/clonesangram/32/6421_2.png) [@clonesangram](https://community.deeplearning.ai/u/clonesangram)\
**Post date:** [August 26, 2021, 5:59pm UTC](https://community.deeplearning.ai/t/convolution-model-application-getting-error-while-running-happymodel/31384/5 "2021-08-26T17:59:11Z")

</div>

thanks again for this

---

<div class="post-metadata">

**Author:** ![Lucasfmon](https://avatars.discourse-cdn.com/v4/letter/l/f05b48/32.png) [@Lucasfmon](https://community.deeplearning.ai/u/Lucasfmon)\
**Post date:** [November 17, 2021, 5:46pm UTC](https://community.deeplearning.ai/t/convolution-model-application-getting-error-while-running-happymodel/31384/6 "2021-11-17T17:46:55Z")

</div>

Thank you. That’s the problem I had! Passing the input\_shape argument solved it.
