Week1 Assignment 2 Puzzled

# GRADED FUNCTION: happyModel
def happyModel():
    # YOUR CODE STARTS HERE
    model = tf.keras.Sequential()
    ## ZeroPadding2D with padding 3, input shape of 64 x 64 x 3
    model.add(tf.keras.layers.ZeroPadding2D(padding=(3,3),input_shape = (64,64,3)))
    ## Conv2D with 32 7x7 filters and stride of 1
    model.add(tf.keras.layers.Conv2D(32,(7, 7),strides=(1, 1),activation='linear', padding='valid'))
    ## BatchNormalization for axis 3
    model.add(tf.keras.layers.BatchNormalization(axis = 3))
    ## ReLU
    model.add(tf.keras.layers.Activation('relu'))
    # Max Pooling 2D with default parameters
    model.add(tf.keras.layers.MaxPooling2D((2, 2)))
    ## Flatten layer
    model.add(tf.keras.layers.Flatten())
    ## Dense layer with 1 unit for output & 'sigmoid' activation 
    model.add(tf.keras.layers.Dense(1, activation='sigmoid'))     
    # YOUR CODE ENDS HERE
    return model
happy_model = happyModel()
# Print a summary for each layer
for layer in summary(happy_model):
    print(layer)
    
output = [['ZeroPadding2D', (None, 70, 70, 3), 0, ((3, 3), (3, 3))],
            ['Conv2D', (None, 64, 64, 32), 4736, 'valid', 'linear', 'GlorotUniform'],
            ['BatchNormalization', (None, 64, 64, 32), 128],
            ['ReLU', (None, 64, 64, 32), 0],
            ['MaxPooling2D', (None, 32, 32, 32), 0, (2, 2), (2, 2), 'valid'],
            ['Flatten', (None, 32768), 0],
            ['Dense', (None, 1), 32769, 'sigmoid']]
    
comparator(summary(happy_model), output)
['ZeroPadding2D', (None, 70, 70, 3), 0, ((3, 3), (3, 3))]
['Conv2D', (None, 64, 64, 32), 4736, 'valid', 'linear', 'GlorotUniform']
['BatchNormalization', (None, 64, 64, 32), 128]
['Activation', (None, 64, 64, 32), 0]
['MaxPooling2D', (None, 32, 32, 32), 0, (2, 2), (2, 2), 'valid']
['Flatten', (None, 32768), 0]
['Dense', (None, 1), 32769, 'sigmoid']
Test failed 
 Expected value 

 ['ReLU', (None, 64, 64, 32), 0] 

 does not match the input value: 

 ['Activation', (None, 64, 64, 32), 0]
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-10-f33284fd82fe> in <module>
     12             ['Dense', (None, 1), 32769, 'sigmoid']]
     13 
---> 14 comparator(summary(happy_model), output)

~/work/release/W1A2/test_utils.py in comparator(learner, instructor)
     20                   "\n\n does not match the input value: \n\n",
     21                   colored(f"{a}", "red"))
---> 22             raise AssertionError("Error in test")
     23     print(colored("All tests passed!", "green"))
     24 

AssertionError: Error in test

How this error could be solved please help…

I think there it needs a ReLU layer, not an activation.

The instructions cover this:
image

1 Like

Thanks alot @TMosh I have made a silly mistake of not reading the instruction carefully. Thanks again for your time and reply.