def identity_block(X, f, filters, training=True, initializer=random_uniform):
“”"
Implementation of the identity block as defined in Figure 4
Arguments:
X -- input tensor of shape (m, n_H_prev, n_W_prev, n_C_prev)
f -- integer, specifying the shape of the middle CONV's window for the main path
filters -- python list of integers, defining the number of filters in the CONV layers of the main path
training -- True: Behave in training mode
False: Behave in inference mode
initializer -- to set up the initial weights of a layer. Equals to random uniform initializer
Returns:
X -- output of the identity block, tensor of shape (n_H, n_W, n_C)
"""
# Retrieve Filters
F1, F2, F3 = filters
# Save the input value. You'll need this later to add back to the main path.
X_shortcut = X
# First component of main path
X = Conv2D(filters = F1, kernel_size = (1,1), strides = (1,1), padding = 'valid', kernel_initializer = initializer(seed=0))(X)
X = BatchNormalization(axis = 3)(X, training = training) # Default axis
X = Activation('relu')(X)
### START CODE HERE
## Second component of main path (≈3 lines)
X = Conv2D(filters = F2, kernel_size = (1,1), strides = (1,1), padding = 'same', kernel_initializer = initializer(seed=0))(X)
X = BatchNormalization(axis = 3)(X, training = training) # Default axis
X = Activation('relu')(X)
## Third component of main path (≈2 lines)
X = Conv2D(filters = F3, kernel_size = (1,1), strides = (1,1), padding = 'valid', kernel_initializer = initializer(seed=0))(X)
X = BatchNormalization(axis = 3)(X, training = training) # Default axis
## Final step: Add shortcut value to main path, and pass it through a RELU activation (≈2 lines)
X = Add()([X_shortcut,X])
X = Activation('relu')(X)
return X
**
this is my code and i got this error
**
With training=False
[[[ 0. 0. 0. 0. ]
[ 0. 0. 0. 0. ]]
[[ 48.92808 48.92808 48.92808 48.92808]
[ 48.92808 48.92808 48.92808 48.92808]]
[[146.78426 146.78426 146.78426 146.78426]
[146.78426 146.78426 146.78426 146.78426]]]
48.928085
With training=True
[[[0. 0. 0. 0. ]
[0. 0. 0. 0. ]]
[[0.29298 0.29298 0.29298 0.29298]
[0.29298 0.29298 0.29298 0.29298]]
[[4.41404 4.41404 4.41404 4.41404]
[4.41404 4.41404 4.41404 4.41404]]]
AssertionError Traceback (most recent call last)
in
22 print(np.around(A4.numpy()[:,(0,-1),:,:].mean(axis = 3), 5))
23
—> 24 public_tests.identity_block_test(identity_block)
/tf/W2A1/public_tests.py in identity_block_test(target)
25 resume = A3np[:,(0,-1),:,:].mean(axis = 3)
26
—> 27 assert np.floor(resume[1, 0, 0]) == 2 * np.floor(resume[1, 0, 3]), “Check the padding and strides”
28 assert np.floor(resume[1, 0, 3]) == np.floor(resume[1, 1, 0]), “Check the padding and strides”
29 assert np.floor(resume[1, 1, 0]) == 2 * np.floor(resume[1, 1, 3]), “Check the padding and strides”
AssertionError: Check the padding and strides