Exercise 1 - happyModel

Hi
I have written this code for the happy model, but it didn’t work. Additionally, because the function has no input I was confused. What should I do?

Error:
File “”, line 34
input_shape = tf.keras.input(shape=(64,64,3))
^
SyntaxError: invalid syntax

The error is before the input shape line. Check for any accidental edits.

There is not anything before this, this is all the code

Every layer you define within the square brackets must end with a comma. You are creating a list of layers.

And you do not need any of the equal signs or the temp variables. Nothing on the left at all. You are just creating a list of layers.

You do need “model =”, but none of the others.

Please edit your message and remove the code.

1 Like

Thanks for your responsibilty.
I edited the code as below:

model = tf.keras.Sequential([
        # YOUR CODE STARTS HERE
         tfl.ZeroPadding2D(padding=3,input_shape=(64,64,3)),
         tfl.Conv2D(kernel_size=(7,7),filters=32,strides=1),
         tfl.BatchNormalization(axis=3),
         tfl.ReLU,
         tfl.MaxPool2D,
         tfl.Flatten,
         tfl.Dense(units=1,activation='sigmoid')
        # YOUR CODE ENDS HERE
    ])

but I still get this failure:

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()
39 tfl.MaxPool2D,
40 tfl.Flatten,
—> 41 tfl.Dense(units=1,activation=‘sigmoid’)
42 # YOUR CODE ENDS HERE
43 ])

/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: <class ‘tensorflow.python.keras.layers.advanced_activations.ReLU’>

I am learning Keras but I have no clue how to get this issue sorted

1 Like

Maybe try adding () after ReLU, MaxPool2D, and Flatten, to indicate that those are functions.

1 Like

So thankful for your response. My problem is solved.

I think or you have to do the below
tfl.ReLU(),
tfl.MaxPool2D(),
tfl.Flatten(),

1 Like

Yeah, thanks for your helpful soloution. It was right.