torch.max
a = np.random.rand(5,2)
a = torch.tensor(a)
a_max,a_argmax = torch.max(a, dim=1)
Output:
a : tensor([[0.2805, 0.4071],
[0.4589, 0.8937],
[0.5888, 0.5372],
[0.5745, 0.8074],
[0.6305, 0.4937]], dtype=torch.float64)
a_max :
tensor([0.4071, 0.8937, 0.5888, 0.8074, 0.6305], dtype=torch.float64)
a_argmax :
tensor([1, 1, 0, 1, 0])
torch.full_like(x, 5) : 复制x的size,全部填充5
torch.ones_like(x) : 复制x的size,全部填充1(default)
x = np.random.rand(2,5)
x = torch.tensor(x)
x_out = torch.full_like(x, 5)
Output:
tensor([[0.3922, 0.7949, 0.8138, 0.7863, 0.4903],
[0.3115, 0.0753, 0.8717, 0.9812, 0.2786]], dtype=torch.float64)
tensor([[5., 5., 5., 5., 5.],
[5., 5., 5., 5., 5.]], dtype=torch.float64)
如:IOU_max.shape : [5]
torch.lt(IOU_max, 0.4) = 0 : 得到小于0.4的index shape : [5]
torch.ge(IOU_max, 0.5) = 0 : 得到大于0.5的index shape : [5]
IOU_max = np.random.rand(5)
IOU_max = torch.tensor(IOU_max)
x_out = torch.lt(IOU_max, 0.4)
Output:
tensor([0.3703, 0.2704, 0.6448, 0.7957, 0.3264], dtype=torch.float64)
tensor([ True, True, False, False, True])