Week 1 Assignment 2 Sequential API happyModel()- Please help!

Hi,

I have looked up other queries regarding this assignment but did not encounter a solution to my issue. Please let me know where I might be going wrong.


ValueError 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()
32
33 # YOUR CODE STARTS HERE
—> 34 tfl.ZeroPadding2D(padding=(3,3))((64,64,3)),
35 tfl.Conv2D(32,(7,7), strides=1),
36 tfl.BatchNormalization(axis=3),

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in call(self, *args, **kwargs)
980 with ops.name_scope_v2(name_scope):
981 if not self.built:
→ 982 self._maybe_build(inputs)
983
984 with ops.enable_auto_cast_variables(self._compute_dtype_object):

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in _maybe_build(self, inputs)
2616 if not self.built:
2617 input_spec.assert_input_compatibility(
→ 2618 self.input_spec, inputs, self.name)
2619 input_list = nest.flatten(inputs)
2620 if input_list and self._dtype_policy.compute_dtype is None:

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/input_spec.py in assert_input_compatibility(input_spec, inputs, layer_name)
156 str(len(input_spec)) + ’ inputs, ’
157 'but it received ’ + str(len(inputs)) +
→ 158 ’ input tensors. Inputs received: ’ + str(inputs))
159 for input_index, (x, spec) in enumerate(zip(inputs, input_spec)):
160 if spec is None:

ValueError: Layer zero_padding2d_6 expects 1 inputs, but it received 3 input tensors. Inputs received: [<tf.Tensor: shape=(), dtype=int32, numpy=64>, <tf.Tensor: shape=(), dtype=int32, numpy=64>, <tf.Tensor: shape=(), dtype=int32, numpy=3>]

In the case of happyModel, we are using the Keras Sequential API. That means you just define the functions, but don’t actually feed them any input tensor. That will be handled later when the model is executed. You’ve written the ZeroPad call as if you are both defining it with padding=(3,3) and then invoking it with a shape argument. The shape argument is optional in any case, but the real mistake is supplying it as an extra argument with a separate set of parens. That’s the way we do things in the second part of the assignment when we use the “Functional API”.

1 Like

Thank you very much!
Issue rectified.

1 Like