0

While coding the Yolo version1 Loss function, I got this error, in this line of code:

box_predictions[..., 2:4] = tf.Variable((tf.math.sign(box_predictions[..., 2:4])) * (tf.math.abs(box_predictions[..., 2:4])))

Even with these lines of code, it displays the same error:

box11 = tf.math.sign(box_predictions[..., 2:4])
box12 = tf.math.abs(box_predictions[..., 2:4])
box_predictions[..., 2:4] = box11 * box12

2
  • on which line is the error occuring? Commented Aug 6, 2021 at 14:23
  • in this line box_predictions[..., 2:4] = tf.Variable((tf.math.sign(box_predictions[..., 2:4])) * (tf.math.abs(box_predictions[..., 2:4]))) Commented Aug 6, 2021 at 14:28

2 Answers 2

1

It looks like you're trying to update your tensor in place. This is not implemented in tensorflow. See https://www.tensorflow.org/api_docs/python/tf/tensor_scatter_nd_update

Therefore you need to use the tf.tensor_scatter_nd_update function

Sign up to request clarification or add additional context in comments.

Comments

0

Thank you so much @ablanch5,

Another solution is to convert it to an array numpy and then to reconvert it to a tensor, and it works fine, here is the code:

box_predictions_np = box_predictions.numpy()
box_predictions_np[..., 2:4] = (tf.math.sign(box_predictions[..., 2:4]))* (tf.math.abs(box_predictions[..., 2:4]))
box_predictions = tf.convert_to_tensor(box_predictions_np, dtype=tf.float32) 

Your solution also works great, but you should be careful to the indices. Thank you,

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.