I’m receiving this error about converting a tf tensor to a np array:
NotImplementedError Traceback (most recent call last)
Input In [44], in <cell line: 7>()
1 ### you cannot edit this cell
2
3 # You always must run the last cell before this one. You will get an error if not.
5 generated_image = tf.Variable(generated_image)
----> 7 train_step_test(train_step, generated_image)
File /tf/W4A2/public_tests.py:86, in train_step_test(target, generated_image)
82 def train_step_test(target, generated_image):
83 generated_image = tf.Variable(generated_image)
—> 86 J1 = target(generated_image)
87 print(J1)
88 assert type(J1) == EagerTensor, f"Wrong type {type(J1)} != {EagerTensor}"
File /usr/local/lib/python3.8/dist-packages/tensorflow/python/util/traceback_utils.py:153, in filter_traceback..error_handler(*args, **kwargs)
151 except Exception as e:
152 filtered_tb = _process_traceback_frames(e.traceback)
→ 153 raise e.with_traceback(filtered_tb) from None
154 finally:
155 del filtered_tb
File /tmp/autograph_generated_file85bicldm.py:12, in outer_factory..inner_factory..tf__train_step(generated_image)
10 with ag.ld(tf).GradientTape() as tape:
11 a_G = ag__.converted_call(ag__.ld(vgg_model_outputs), (ag__.ld(generated_image),), None, fscope)
—> 12 J_style = ag__.converted_call(ag__.ld(compute_style_cost), (ag__.ld(a_S), ag__.ld(a_G)), None, fscope)
13 J_content = ag__.converted_call(ag__.ld(compute_content_cost), (ag__.ld(a_C), ag__.ld(a_G)), None, fscope)
14 J = ag__.converted_call(ag__.ld(total_cost), (ag__.ld(J_content), ag__.ld(J_style)), dict(alpha=10, beta=40), fscope)
File /tmp/autograph_generated_file1ujc77yi.py:31, in outer_factory..inner_factory..tf__compute_style_cost(style_image_output, generated_image_output, STYLE_LAYERS)
29 J_style_layer = ag.Undefined(‘J_style_layer’)
30 i = ag__.Undefined(‘i’)
—> 31 ag__.for_stmt(ag__.converted_call(ag__.ld(zip), (ag__.converted_call(ag__.ld(range), (ag__.converted_call(ag__.ld(len), (ag__.ld(a_S),), None, fscope),), None, fscope), ag__.ld(STYLE_LAYERS)), None, fscope), None, loop_body, get_state, set_state, (‘J_style’,), {‘iterate_names’: ‘(i, weight)’})
32 try:
33 do_return = True
File /tmp/autograph_generated_file1ujc77yi.py:25, in outer_factory..inner_factory..tf__compute_style_cost..loop_body(itr)
23 nonlocal J_style
24 (i, weight) = itr
—> 25 J_style_layer = ag.converted_call(ag__.ld(compute_layer_style_cost), (ag__.ld(a_S)[ag__.ld(i)], ag__.ld(a_G)[ag__.ld(i)]), None, fscope)
26 J_style = ag__.ld(J_style)
27 J_style += (weight[1] * J_style_layer)
File /tmp/autograph_generated_file1arwgtg9.py:16, in outer_factory..inner_factory..tf__compute_layer_style_cost(a_S, a_G)
14 GS = ag.converted_call(ag__.ld(gram_matrix), (ag__.ld(a_S),), None, fscope)
15 GG = ag__.converted_call(ag__.ld(gram_matrix), (ag__.ld(a_G),), None, fscope)
—> 16 J_style_layer = (ag__.converted_call(ag__.ld(tf).reduce_sum, (ag__.converted_call(ag__.ld(np).square, (ag__.converted_call(ag__.ld(np).subtract, (ag__.ld(GS), ag__.ld(GG)), None, fscope),), None, fscope),), None, fscope) / (4.0 * (ag__.converted_call(ag__.ld(np).square, (ag__.ld(n_C),), None, fscope) * ag__.converted_call(ag__.ld(np).square, ((ag__.ld(n_H) * ag__.ld(n_W)),), None, fscope))))
17 try:
18 do_return = True
NotImplementedError: in user code:
File "<ipython-input-43-b6fcbd5a7ea2>", line 19, in train_step *
J_style = compute_style_cost(a_S, a_G)
File "<ipython-input-29-7b56545257a6>", line 30, in compute_style_cost *
J_style_layer = compute_layer_style_cost(a_S[i], a_G[i])
File "<ipython-input-24-c133bbc265a0>", line 27, in compute_layer_style_cost *
J_style_layer = (tf.reduce_sum(np.square(np.subtract(GS, GG))))/(4.0*(np.square(n_C)*np.square(n_H*n_W)))
NotImplementedError: Cannot convert a symbolic tf.Tensor (MatMul: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.
I’m not really sure where to begin with it. At first I was having other problems regarding tf and np not working interchangeably. I tried fixing it by using floats but got this error