Week 2 : Programming Assignment: Residual Networks

Week 2 : Programming Assignment: Residual Networks
Facing this error. please guide.

NameError Traceback (most recent call last)
Input In [27], in <cell line: 13>()
9 X3 = np.ones((1, 4, 4, 3)) * 3
11 X = np.concatenate((X1, X2, X3), axis = 0).astype(np.float32)
—> 13 A3 = identity_block(X, f=2, filters=[4, 4, 3],
14 initializer=lambda seed=0:constant(value=1))
15 print(‘\033[1mWith training=False\033[0m\n’)
16 A3np = A3.numpy()

Input In [26], in identity_block(X, f, filters, initializer)
24 # First component of main path
25 X = Conv2D(filters = F1, kernel_size = 1, strides = (1,1), padding = ‘valid’, kernel_initializer = initializer(seed=0))(X)
—> 26 X = BatchNormalization(axis = 3)(X, training = training) # Default axis
27 X = Activation(‘relu’)(X)
29 ### START CODE HERE
30 ## Second component of main path (≈3 lines)

NameError: name ‘training’ is not defined

Does this help?

I am adding training = True but giving error.

Hi @fayyaz9191 ,

Your code in the first post is correct, because it is the value in the input argument ‘training’ needs to be passed to BatchNormalization(). The error reported could be due to the execution environment is not up-to-date, ie. you notebook has been inactive. Just rerun your code from start should help.

@Kic

The notebook makes use of tf.keras.backend.set_learning_phase to set the training phase. Why use training flag inside the method def identity_block ?

Hi @balaji.ambresh ,

Unless I am on the wrong course. I am referring to C4 week2 ResNets ex1 where the function identity_block() is defined

@Kic

This is the function signature:

def identity_block(X, f, filters, initializer=random_uniform):

training is not part of the parameter list.

Hi @balaji.ambresh ,

You are right about. I was using the assignment on github repo. Will try to locate that file again later.