happyModel showing error

I am facing some problem while running happymodel code, the window that is given for student to write code is run perfectly issuing no error while the built in window show the following error.

YOUR CODE STARTS HERE

        tf.keras.layers.ZeroPadding2D(padding=3),
        tf.keras.layers.Conv2D(32, 7),
        tf.keras.layers.BatchNormalization(axis=3),
        tf.keras.layers.ReLU(),
        tf.keras.layers.MaxPool2D(),
        tf.keras.layers.Flatten(),
        tf.keras.layers.Dense(units=1, activation="sigmoid")
        # YOUR CODE ENDS HERE

AttributeError 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

~/work/release/W1A2/test_utils.py in summary(model)
30 result =
31 for layer in model.layers:
—> 32 descriptors = [layer.class.name, layer.output_shape, layer.count_params()]
33 if (type(layer) == Conv2D):
34 descriptors.append(layer.padding)

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in output_shape(self)
2177 “”"
2178 if not self._inbound_nodes:
→ 2179 raise AttributeError('The layer has never been called ’
2180 ‘and thus has no defined output shape.’)
2181 all_output_shapes = set(

AttributeError: The layer has never been called and thus has no defined output shape.

Today is last day of submission of assignment.

1 Like

For ZeroPadding2D(), you did not provide the required input shape.
Please read the instructions carefully.

2 Likes

thanks, but unable to connect with the idea how to pass input shape in the ZeroPadding2D().

thanks, but unable to connect with the idea how to pass input shape in the ZeroPadding2D(). Any suggestion would be help to how pass input shape in ZeroPadding2D()

Set the “input_shape=…” parameter to the appropriate value. The shape to use is given in the code comment.

Ok thanks, it help a lot.

I was struggling with the same issue, and for me it arised from the fact that I couldn’t readily find the argument input_size in the documentation I was wondering if @TMosh can point us where this parameter lives in the documentation?
Thanks!

2 Likes

It is inherited from one of the parent classes. The layer functions are subclasses of Layer which is in turn a subclass of Module. Have a look at the docpage for tfl.InputLayer.

2 Likes

Great, thank you for you explanation. I get it now :slightly_smiling_face: