Week 2 assignment 1 issue

Hi, I am trying to complete week 2 assignment 1, which seems like a pretty simple use of Keras. But, I consistently get a test failing on both of the first two graded blocks.

Below are the failing tests. I have checked and rechecked the stride and filter parameters and they seem to match what is expected in the description. One question is – I don’t see a use for the f parameter to the function, as the filter specifications are provided separately in F1, F2, F3 but is there some use for f that I am missing that’s actually causing this?

Function 1

AssertionError                            Traceback (most recent call last)
Input In [4], in <cell line: 30>()
     26 A4 = identity_block(X, f=2, filters=[3, 3, 3],
     27                    initializer=lambda seed=0:constant(value=1))
     28 print(np.around(A4.numpy()[:,(0,-1),:,:].mean(axis = 3), 5))
---> 30 public_tests.identity_block_test(identity_block)

File /tf/W2A1/public_tests.py:31, in identity_block_test(target)
     28 assert np.all(A3np >= 0), "The ReLu activation at the last layer is missing"
     29 resume = A3np[:,(0,-1),:,:].mean(axis = 3)
---> 31 assert np.floor(resume[1, 0, 0]) == 2 * np.floor(resume[1, 0, 3]), "Check the padding and strides"
     32 assert np.floor(resume[1, 0, 3]) == np.floor(resume[1, 1, 0]),     "Check the padding and strides"
     33 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

Function 2

tf.Tensor(
[[[0.         0.         0.         0.         0.10979614 0.        ]
  [0.         0.         0.         0.         0.10979614 0.        ]]

 [[0.         0.         0.         0.         0.10979614 0.        ]
  [0.         0.         0.         0.         0.10979614 0.        ]]], shape=(2, 2, 6), dtype=float32)

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Input In [5], in <cell line: 3>()
      1 ### you cannot edit this cell
----> 3 public_tests.convolutional_block_test(convolutional_block)

File /tf/W2A1/public_tests.py:115, in convolutional_block_test(target)
    112 tf.keras.backend.set_learning_phase(True)
    114 C = target(X, f = 2, filters = [2, 4, 6])
--> 115 assert np.allclose(C.numpy(), convolutional_block_output2), "Wrong values when training=True."
    117 print('\033[92mAll tests passed!')

AssertionError: Wrong values when training=True.

Thanks, Jeff

1 Like

They have already given you the CONV2D specifications:
for the f here is the instruction again;

The second CONV2D has F2 filters of shape (f,f) and a stride of (1,1). Its padding is “same”. Use 0 as the seed for the random

1 Like

I did all of that, but receive the errors above

1 Like

I guess maybe I am missing something in the shape of the filters – based on the docs tf.keras.layers.Conv2D  |  TensorFlow v2.16.1

I only see an int filters param, how do I specify the filter shape? Is that kernel_size?

1 Like

Ah, that did it. Sorry the name of the param threw me off. Thanks for your help and quick response to this

4 Likes

Yes, the filter shape is specified by the kernel_size. If the filters are symmetric (which happens in every case I’ve seen here in the courses), you can just specify one number or you can specify it as a tuple, as in kernel_size = (f, f).

1 Like