0

I'm converting torch code to tensorflow 2.0

prior_boxes = torch.FloatTensor(prior_boxes).to(device)  # (8732, 4)
prior_boxes.clamp_(0, 1)  # (8732, 4)

is there any replacement of clamp_(0,1) in tensorflow > 2.0?

1 Answers1

1

Try tf.clip_by_value, though unlike clamp_, it is not in-place:

t = tf.constant([[-10., -1., 0.], [0., 2., 10.]])
t2 = tf.clip_by_value(t, clip_value_min=-1, clip_value_max=1)
t2.numpy()
# gives [[-1., -1., 0.], [0., 1., 1.]]
jayelm
  • 7,236
  • 5
  • 43
  • 61