Unable to run a code which is showing an error on cell where i am forbidden to correct


NameError Traceback (most recent call last)
Input In [16], 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 [15], in identity_block(X, f, filters, initializer)
6 “”"
7 Implementation of the identity block as defined in Figure 4
8
(…)
18 X – output of the identity block, tensor of shape (m, n_H, n_W, n_C)
19 “”"
20 # defining name basis
—> 21 conv_name_base = ‘res’ + str(stage) + block + ‘_branch’
22 bn_name_base = ‘bn’ + str(stage) + block + ‘_branch’
23 # Retrieve Filters

NameError: name ‘stage’ is not defined

Where does conv_name_base come from (file and line)?

1 Like

It was used in earlier cell

but the cell where forbidden to edit have public_tests showing back normalization units are not wokign

1 Like

It is an error in your code for one of the functions.

Corrected the errors and showing below errors now

AssertionError Traceback (most recent call last)
Input In [17], 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

2 Likes

Cell #5. Can’t compile the student’s code. Error: NameError(“name ‘convolutional_block’ is not defined”)
Traceback (most recent call last):
File “/home/www/app/grading/exceptions.py”, line 112, in handle_solution_errors
yield {}
File “/home/www/app/grading/abstract.py”, line 393, in _grade
context = compiled_code.run(cell_index=cell.index)
File “/home/www/app/grading/submission/compiled_code.py”, line 195, in run
return list(self._code_items.values())[cell_num - 1].run()
File “/home/www/app/grading/submission/compiled_code.py”, line 54, in run
return import_module(self.import_statement, items)
File “/usr/local/lib/python3.8/importlib/init.py”, line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 1014, in _gcd_import
File “”, line 991, in _find_and_load
File “”, line 975, in _find_and_load_unlocked
File “”, line 671, in _load_unlocked
File “”, line 843, in exec_module
File “”, line 219, in _call_with_frames_removed
File “/tmp/student_solution_cells/cell_5.py”, line 9, in
public_tests.convolutional_block_test(convolutional_block)
NameError: name ‘convolutional_block’ is not defined

1 Like

My guess is that there is something structural wrong with your notebook. Have you downloaded it, run it on some other platform like Colab and then uploaded it to Coursera again? Doing that usually causes problems.

One thing that could cause the grader error you show is that you accidentally changed the cell type of the function cell for convolutional_block from Code to Markdown. Can you run the test cell in the notebook that calls that function?

2 Likes

I can’t find any strings like that in the current version of the notebook. Did you perhaps try to copy a solution from GitHub? If so a) that is considered cheating according to the rules here and b) it doesn’t work if you copy a version that is old. :grin:

2 Likes

I haven’t used any such string and still the error reflecting

1 Like

never run in colab.
With training=False

[[[0. 0. 0. 0. ]
[0. 0. 0. 0. ]]

[[0.40732 0.40732 0.40732 0.40732]
[0.40732 0.40732 0.40732 0.40732]]

[[5.00011 5.00011 5.00011 3.25955]
[3.25955 3.25955 3.25955 2.40732]]]
0.40732422

With training=True

[[[0. 0. 0. 0. ]
[0. 0. 0. 0. ]]

[[0.40732 0.40732 0.40732 0.40732]
[0.40732 0.40732 0.40732 0.40732]]

[[5.00011 5.00011 5.00011 3.25955]
[3.25955 3.25955 3.25955 2.40732]]]

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:36, in identity_block_test(target)
33 assert np.floor(resume[1, 1, 0]) == 2 * np.floor(resume[1, 1, 3]), “Check the padding and strides”
34 assert np.floor(resume[1, 1, 0]) == 2 * np.floor(resume[1, 1, 3]), “Check the padding and strides”
—> 36 assert resume[1, 1, 0] - np.floor(resume[1, 1, 0]) > 0.7, “Looks like the BatchNormalization units are not working”
38 assert np.allclose(resume,
39 np.array([[[ 0., 0., 0., 0., ],
40 [ 0., 0., 0., 0., ]],
(…)
44 [290.99988, 290.99988, 290.99988, 146.99994]]]),
45 atol = 1e-5 ), “Wrong values with training=False”
47 tf.keras.backend.set_learning_phase(True)

AssertionError: Looks like the BatchNormalization units are not working

above error is coming while running the program cell

1 Like

Error identified and code executed,
Thank you so much for support and response

3 Likes