Reputation:
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
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