I am getting the following error when trying to do the ‘train_step’ function and I have no idea how to fix this.
I have looked at the functions I have created that are used and they all seem to work fine.
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
Input In [46], 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.<locals>.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_filequundupz.py:12, in outer_factory.<locals>.inner_factory.<locals>.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_filesn2nhuk1.py:31, in outer_factory.<locals>.inner_factory.<locals>.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_filesn2nhuk1.py:25, in outer_factory.<locals>.inner_factory.<locals>.tf__compute_style_cost.<locals>.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_filefzajk99g.py:13, in outer_factory.<locals>.inner_factory.<locals>.tf__compute_layer_style_cost(a_S, a_G)
11 (_, n_H, n_W, n_C) = ag__.converted_call(ag__.ld(a_G).shape.as_list, (), None, fscope)
12 a_S = ag__.converted_call(ag__.ld(np).reshape, (ag__.converted_call(ag__.ld(np).transpose, (ag__.ld(a_S), [0, 3, 1, 2]), None, fscope), [ag__.ld(n_C), (ag__.ld(n_H) * ag__.ld(n_W))]), None, fscope)
---> 13 a_G = ag__.converted_call(ag__.ld(np).reshape, (ag__.converted_call(ag__.ld(np).transpose, (ag__.ld(a_G), [0, 3, 1, 2]), None, fscope), [ag__.ld(n_C), (ag__.ld(n_H) * ag__.ld(n_W))]), None, fscope)
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)
File <__array_function__ internals>:180, in transpose(*args, **kwargs)
File /usr/local/lib/python3.8/dist-packages/numpy/core/fromnumeric.py:660, in transpose(a, axes)
601 @array_function_dispatch(_transpose_dispatcher)
602 def transpose(a, axes=None):
603 """
604 Reverse or permute the axes of an array; returns the modified array.
605
(...)
658
659 """
--> 660 return _wrapfunc(a, 'transpose', axes)
File /usr/local/lib/python3.8/dist-packages/numpy/core/fromnumeric.py:54, in _wrapfunc(obj, method, *args, **kwds)
52 bound = getattr(obj, method, None)
53 if bound is None:
---> 54 return _wrapit(obj, method, *args, **kwds)
56 try:
57 return bound(*args, **kwds)
File /usr/local/lib/python3.8/dist-packages/numpy/core/fromnumeric.py:43, in _wrapit(obj, method, *args, **kwds)
41 except AttributeError:
42 wrap = None
---> 43 result = getattr(asarray(obj), method)(*args, **kwds)
44 if wrap:
45 if not isinstance(result, mu.ndarray):
NotImplementedError: in user code:
File "<ipython-input-39-344a2016faad>", line 19, in train_step *
J_style = compute_style_cost(a_S, a_G)
File "<ipython-input-15-7b56545257a6>", line 30, in compute_style_cost *
J_style_layer = compute_layer_style_cost(a_S[i], a_G[i])
File "<ipython-input-10-617022207b12>", line 20, in compute_layer_style_cost *
a_G = np.reshape(np.transpose(a_G, [0,3,1,2]), [n_C,n_H*n_W])
File "<__array_function__ internals>", line 180, in transpose **
File "/usr/local/lib/python3.8/dist-packages/numpy/core/fromnumeric.py", line 660, in transpose
return _wrapfunc(a, 'transpose', axes)
File "/usr/local/lib/python3.8/dist-packages/numpy/core/fromnumeric.py", line 54, in _wrapfunc
return _wrapit(obj, method, *args, **kwds)
File "/usr/local/lib/python3.8/dist-packages/numpy/core/fromnumeric.py", line 43, in _wrapit
result = getattr(asarray(obj), method)(*args, **kwds)
NotImplementedError: Cannot convert a symbolic tf.Tensor (model/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.