0
votes

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? - Sean Powell
in this line box_predictions[..., 2:4] = tf.Variable((tf.math.sign(box_predictions[..., 2:4])) * (tf.math.abs(box_predictions[..., 2:4]))) - Olfa2

2 Answers

0
votes

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

0
votes

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,