COurse 4 Exercise 1 - zero_pad

Hi all,
I am getting a weird error as below

NameError                                 Traceback (most recent call last)
<ipython-input-10-67a1f5c5f3a2> in <module>
     19 axarr[1].set_title('x_pad')
     20 axarr[1].imshow(x_pad[0, :, :, 0])
---> 21 zero_pad_test(zero_pad)

~/work/release/W1A1/public_tests.py in zero_pad_test(target)
      7     np.random.seed(1)
      8     x = np.random.randn(4, 3, 3, 2)
----> 9     x_pad = zero_pad(x, 3)
     10     print ("x.shape =\n", x.shape)
     11     print ("x_pad.shape =\n", x_pad.shape)

NameError: name 'zero_pad' is not defined

‘zero_pad’ is the function which I have defined already and also get the result for x_pad

1 Like

This probably just means that you closed and reopened the notebook. Anytime you do that, you need to re-execute all the previous cells in the notebook. Try “Cell → Run All Above” and it should define that function.

Well, unless that cell throws an error.

I also made this mistake

def zero_pad_test(target):    
    # Test 1
    np.random.seed(1)
    x = np.random.randn(4, 3, 3, 2)
    #  Why not   x_pad = target(x, 3)----------------
    x_pad = zero_pad(x, 3)
    print ("x.shape =\n", x.shape)
    print ("x_pad.shape =\n", x_pad.shape)
    print ("x[1,1] =\n", x[1, 1])
    print ("x_pad[1,1] =\n", x_pad[1, 1])
1 Like

Sorry, we can’t actually see an error message in the information that you posted.

It seems not a code error.

I also have this problem.

I submit the correct code last night and get 25 score on this exercise1.

but today, I re-executed the same code, then the error happend.

I have tried re-login\re-execute and re-enter, but nothing worked.

At the same time, so many people have the same trouble and their code is seems right.

May be it is a notebook system error.

I also have this problem.
Traceback is follows:

NameError                                 Traceback (most recent call last)
<ipython-input-5-a6f364884ebb> in <module>
     12 axarr[1].set_title('x_pad')
     13 axarr[1].imshow(x_pad[0, :, :, 0])
---> 14 zero_pad_test(zero_pad)

~/work/release/W1A1/public_tests.py in zero_pad_test(target)
      7     np.random.seed(1)
      8     x = np.random.randn(4, 3, 3, 2)
----> 9     x_pad = zero_pad(x, 3)
     10     print ("x.shape =\n", x.shape)
     11     print ("x_pad.shape =\n", x_pad.shape)

NameError: name 'zero_pad' is not defined

And the fact that it failed to call zero_pad inside zero_pad_test but not failed to call the same function inside notebook seems like an error in zero_pad_test.

The public_tests.py file was updated by the course staff earlier today.
I’ll ask them to investigate the problem.

I think its an error outside of the files you should work on. In public_tests.py in function zero_pad_test(target) the line

{mentor edit}

zero_pad is passed as an argument, that is called in target in the defined function.

Cheers

1 Like

I tired Hohlweger_Bernhard’s solution, and it works locally. However, online grader still grade with public__tests.py that has error. So, the resulting score still not be able to pass the assignment.

2 Likes

me as well, it seems a recent error

i have the same error.
It worked yesterday

I also have this problem.
Traceback is follows:

NameError Traceback (most recent call last)
in
19 axarr[1].set_title(‘x_pad’)
20 axarr[1].imshow(x_pad[0, :, :, 0])
—> 21 zero_pad_test(zero_pad)

~/work/release/W1A1/public_tests.py in zero_pad_test(target)
7 np.random.seed(1)
8 x = np.random.randn(4, 3, 3, 2)
----> 9 x_pad = zero_pad(x, 3)
10 print (“x.shape =\n”, x.shape)
11 print (“x_pad.shape =\n”, x_pad.shape)

NameError: name ‘zero_pad’ is not defined

I’ve reported the error to the course staff.

2 Likes

Course staff reports that the issue with public_tests.py has been resolved.
The zero_pad_test() function now works correctly.

Now its working. thank you