I have tensor with shape (1, 3)
and I'm using TensorFlow 2.4.1
but I have code that needs to run on the old version. So, I use
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
predicted_id = tf.argmax(sample_decoder_output[-1]).numpy()
The problem is that I got the following error :
predicted_id = tf.argmax(sample_decoder_output[-1]).numpy()
AttributeError: 'Tensor' object has no attribute 'numpy'
and I have found many answers [1][2] that I applied but I got the following error
predicted_id = tf.argmax(sample_decoder_output[-1]).numpy() File "~/lib/python3.8/site-packages/tensorflow/python/util/dispatch.py", line 201, in wrapper
return target(*args, **kwargs) File "~/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py", line 1036, in _slice_helper
return strided_slice( File "~/lib/python3.8/site-packages/tensorflow/python/util/dispatch.py", line 201, in wrapper
return target(*args, **kwargs) File "~/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py", line 1209, in strided_slice
op = gen_array_ops.strided_slice( File "~/lib/python3.8/site-packages/tensorflow/python/ops/gen_array_ops.py", line 10451, in strided_slice
return strided_slice_eager_fallback( File "~/lib/python3.8/site-packages/tensorflow/python/ops/gen_array_ops.py", line 10521, in strided_slice_eager_fallback
_result = _execute.execute(b"StridedSlice", 1, inputs=_inputs_flat, File "~/lib/python3.8/site-packages/tensorflow/python/eager/execute.py", line 75, in quick_execute
raise e File "~/lib/python3.8/site-packages/tensorflow/python/eager/execute.py", line 59, in quick_execute
tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name, TypeError: An op outside of the function building code is being passed a "Graph" tensor. It is possible to have Graph tensors leak out of the function building context by including a tf.init_scope in your function building code. For example, the following function will fail:
@tf.function
def has_init_scope():
my_constant = tf.constant(1.)
with tf.init_scope():
added = my_constant * 2
The graph tensor has name: decoder/dense/BiasAdd:0