To mention in brief: I have been faced with this error while running the code:
NotImplementedError: Cannot convert a symbolic Tensor (functional_5/block1_conv1/Relu:0) to a numpy array. This error may indicate that you’re trying to pass a Tensor to a NumPy call, which is not supported
Also, I do have a fundamental problem, which is the place of the last Cell
(#You always must run the last cell before this one. You will get an error if not.)
Thanks
Sorry, can you give us more context here? Is the error you show happening when you run the tests in the notebook or when you run the grader? If the former case, please show us the complete exception trace that you are getting.
I also don’t understand your point about the last cell. It’s just giving you some what are intended to be helpful instructions. Do you not see how to follow the instructions?
It is happening when I run the test.
Here is the code:
generated_image = tf.Variable(generated_image)
J1 = train_step(generated_image)
print(J1)
assert type(J1) == EagerTensor, f"Wrong type {type(J1)} != {EagerTensor}"
assert np.isclose(J1, 25629.055, rtol=0.05), f"Unexpected cost for epoch 0: {J1} != {25629.055}"
J2 = train_step(generated_image)
print(J2)
assert np.isclose(J2, 17812.627, rtol=0.05), f"Unexpected cost for epoch 1: {J2} != {17735.512}"
print("\033[92mAll tests passed")
Here is the exception:
NotImplementedError: in user code:
<ipython-input-26-9e19f6e2a8a8>:19 train_step *
J_style = compute_style_cost(a_S,a_G)
<ipython-input-14-d70c9653228b>:28 compute_style_cost *
J_style_layer = compute_layer_style_cost(a_S[i], a_G[i])
<ipython-input-9-2e83c067b7e4>:20 compute_layer_style_cost *
a_G = tf.transpose(np.reshape(a_G,[n_H * n_W,n_C]),[1,0])
<__array_function__ internals>:6 reshape **
/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py:301 reshape
return _wrapfunc(a, 'reshape', newshape, order=order)
/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py:58 _wrapfunc
return _wrapit(obj, method, *args, **kwds)
/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py:47 _wrapit
result = getattr(asarray(obj), method)(*args, **kwds)
/usr/local/lib/python3.6/dist-packages/numpy/core/_asarray.py:85 asarray
return array(a, dtype, copy=False, order=order)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py:848 __array__
" a NumPy call, which is not supported".format(self.name))
NotImplementedError: Cannot convert a symbolic Tensor (functional_5/block1_conv1/Relu:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported
Could you please help me on finding the last cell?
The last cell is [51] [43] or somewhere else in the code!!!
Thankyou
I think that line is the problem. You are mixing numpy and TF, which may work sometimes, but it fails spectacularly when you are computing gradients with TF, because the numpy operation is not part of the TF Graph. So that code in compute_layer_style_cost may have worked in the earlier tests, but it crashes and burns here when you run the training. Try using tf.reshape instead of np.reshape and that should help.
When they say “the last cell” they mean “the previous cell”. That is to say the one that defines the train_step function. The point is try running the call that calls train_step twice in a row and watch it crash. So you have to run both cells every time: first run the cell that defines train_step and then run the cell that calls train_step.
Yeah, that worked.
Thankyou