示例#1
0
def rotate_and_flip(tensor,device,p=0.5):
    for i in range(tensor.shape[0]):
        random_number=np.random.uniform()
        if random_number < p:
            center = torch.ones(tensor.shape[1], 2).to(device)
            center[:, 0] = tensor.shape[3] / 2  # x
            center[:, 1] = tensor.shape[2] / 2  # y
            #scale: torch.tensor = torch.ones(1)#*np.random.uniform(0.8,1.2)
            angle = torch.tensor([np.random.randint(-90,90,)*np.ones(tensor.shape[1])]).squeeze().to(device).float()
            #print(angle.shape)
            #print(tensor[i].shape)
            #M = kornia.get_rotation_matrix2d(center, angle, scale)#.to(device)
            #Mt = torch.ones((tensor.shape[0],2,3))
            #Mt[:] = M
            #Mt=Mt.to(device)
            #tensor[:,j]=kornia.warp_affine(tensor[:,j], Mt, dsize=(tensor.shape[3], tensor.shape[4]))
            #print(tensor.dtype)
            tensor[i]=kornia.rotate(tensor[i],angle,center)
        random_number=np.random.uniform()
        if random_number < p:
            tensor[i,:]=kornia.hflip(tensor[i,:])

        random_number=np.random.uniform()
        if random_number < p:
            tensor[i,:]=kornia.vflip(tensor[i,:])

    return tensor
示例#2
0
def hflip(tensor,p=1):
    for i in range(tensor.shape[0]):
        random_number=np.random.uniform()
        if random_number < p:
            tensor[i,:]=kornia.vflip(tensor[i,:])

    return tensor
示例#3
0
        def op_script(data: torch.Tensor) -> torch.Tensor:

            return kornia.vflip(data)