I want to threshold a tensor used in self-defined loss function into binary values. Previously, I used torch.round(prob) to do it. Since my prob tensor value range in [0 1]. This is equivalent to threshold the tensor prob using a threshold value 0.5.
For example,
prob = [0.1, 0.3, 0.7, 0.9], torch.round(prob) = [0, 0, 1, 1]
Now, I would like to use a changeable threshold value, how to do it?