Week1 assignment 2, error happyModel

{moderator edit - solution code removed}

===========================
and it gave following errors

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.

===========================

could you please help

I think your code looks correct, although maybe I’m missing something subtle. My guess is that you’ve fixed it, but forgot to actually run that cell again by clicking “Shift-Enter” in that cell. Just calling the function again runs the old code.

In other words: just typing some new code doesn’t really do anything. It doesn’t take effect until you click “Shift-Enter” in that cell itself to interpret the new code and generate the runtime JIT compiled version of the new code.

The other thing to try is “Kernel → Restart and Clear Output” and then “Cell → Run All” and see what happens. That is more of a “sledge hammer” way to make sure that “what you see is what you get” :nerd_face:

Hey, @annabellal8063. If you Google for that AttributeError message a couple of top results mention how to make sure the layer is called, and that’s by defining the input shape. So on your first layer (ZEROPAD) make sure you’re using the parameter input_shape. Also, you’ll want to delete your code to avoid any Honor Code violation.