Hi Everyone,
I am getting this error while compiling the code for Week 1 Programming Assignment 2 -
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-133-f33284fd82fe> in <module>
----> 1 happy_model = happyModel()
2 # Print a summary for each layer
3 for layer in summary(happy_model):
4 print(layer)
5
<ipython-input-132-93e688c7667d> in happyModel()
32
33 # YOUR CODE STARTS HERE
---> 34 tfl.add([tfl.ZeroPadding2D(padding=3)(input_shape=tf.keras.Input(shape= (64,64,3))),
35 tfl.Conv2D(filters=32, Kernel_size=(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)
914 # not to any other argument.
915 # - setting the SavedModel saving spec.
--> 916 inputs, args, kwargs = self._split_out_first_arg(args, kwargs)
917 input_list = nest.flatten(inputs)
918
/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in _split_out_first_arg(self, args, kwargs)
2978 else:
2979 raise ValueError(
-> 2980 'The first argument to `Layer.call` must always be passed.')
2981 return inputs, args, kwargs
2982
ValueError: The first argument to `Layer.call` must always be passed.
Could you please guide me where i am going wrong with this?
There are two ways to implement the Sequential model.
One is by creating a Sequential layer, and passing it a list (within square brackets) of the layers you want to use, separated by commas.
The other is by creating a Sequential layer, and then using the .add method to add the other layers. This method does not use a list, so you don’t need square brackets or commas.
Given the error you are seeing, I suspect there’s a problem (a syntax error) in how you’re defining the list of layers.
For someone who might be facing the same problem as me :
Tip - Pass InputLayer as your first parameter to the sequential keras model and everything else will fall into place.
UnboundLocalError 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()
21
22 ## ZeroPadding2D with padding 3, input shape of 64 x 64 x 3
—> 23 model.add(tfl.ZeroPadding2D(padding=(3,3))),
24
25 ## Conv2D with 32 7x7 filters and stride of 1
UnboundLocalError: local variable ‘model’ referenced before assignment