Convolution_model_Application - getting error while running happymodel()

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

1 Like

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.

5 Likes

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  |  TensorFlow Core v2.6.0

3 Likes

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.

4 Likes

thanks again for this

1 Like

Thank you. That’s the problem I had! Passing the input_shape argument solved it.