user11173832
user11173832

Reputation:

is there any similar function with clamp_ in tensorflow > 2.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?

Upvotes: 0

Views: 440

Answers (1)

jayelm
jayelm

Reputation: 7688

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.]]

Upvotes: 1

Related Questions