def __init__(self, out_h=256, out_w=192, use_regular_grid=True, grid_size=3, reg_factor=0):
    super(TpsGridGen, self).__init__()
    (self.out_h, self.out_w) = (out_h, out_w)
    self.reg_factor = reg_factor
    self.grid = np.zeros([self.out_h, self.out_w, 3], dtype=np.float32)
    (self.grid_X, self.grid_Y) = np.meshgrid(np.linspace((- 1), 1, out_w), np.linspace((- 1), 1, out_h))
    self.grid_X = torch.FloatTensor(self.grid_X).unsqueeze(0).unsqueeze(3)
    self.grid_Y = torch.FloatTensor(self.grid_Y).unsqueeze(0).unsqueeze(3)
    self.grid_X = self.grid_X.to(device)
    self.grid_Y = self.grid_Y.to(device)
    if use_regular_grid:
        axis_coords = np.linspace((- 1), 1, grid_size)
        self.N = (grid_size * grid_size)
        (P_Y, P_X) = np.meshgrid(axis_coords, axis_coords)
        P_X = np.reshape(P_X, ((- 1), 1))
        P_Y = np.reshape(P_Y, ((- 1), 1))
        P_X = torch.FloatTensor(P_X)
        P_X = P_X.to(device)
        P_Y = torch.FloatTensor(P_Y)
        P_Y = P_Y.to(device)
        self.P_X_base = P_X.clone()
        self.P_X_base = self.P_X_base.to(device)
        self.P_Y_base = P_Y.clone()
        self.P_Y_base = self.P_Y_base.to(device)
        self.Li = self.compute_L_inverse(P_X, P_Y).unsqueeze(0)
        self.P_X = P_X.unsqueeze(2).unsqueeze(3).unsqueeze(4).transpose(0, 4)
        self.P_Y = P_Y.unsqueeze(2).unsqueeze(3).unsqueeze(4).transpose(0, 4)
def __init__(self, out_h=256, out_w=192, use_regular_grid=True, grid_size=3, reg_factor=0):
    super(TpsGridGen, self).__init__()
    (self.out_h, self.out_w) = (out_h, out_w)
    self.reg_factor = reg_factor
    self.grid = np.zeros([self.out_h, self.out_w, 3], dtype=np.float32)
    (self.grid_X, self.grid_Y) = np.meshgrid(np.linspace((- 1), 1, out_w), np.linspace((- 1), 1, out_h))
    self.grid_X = torch.FloatTensor(self.grid_X).unsqueeze(0).unsqueeze(3)
    self.grid_Y = torch.FloatTensor(self.grid_Y).unsqueeze(0).unsqueeze(3)
    self.grid_X = self.grid_X.to(device)
    self.grid_Y = self.grid_Y.to(device)
    if use_regular_grid:
        axis_coords = np.linspace((- 1), 1, grid_size)
        self.N = (grid_size * grid_size)
        (P_Y, P_X) = np.meshgrid(axis_coords, axis_coords)
        P_X = np.reshape(P_X, ((- 1), 1))
        P_Y = np.reshape(P_Y, ((- 1), 1))
        P_X = torch.FloatTensor(P_X)
        P_X = P_X.to(device)
        P_Y = torch.FloatTensor(P_Y)
        P_Y = P_Y.to(device)
        self.P_X_base = P_X.clone()
        self.P_X_base = self.P_X_base.to(device)
        self.P_Y_base = P_Y.clone()
        self.P_Y_base = self.P_Y_base.to(device)
        self.Li = self.compute_L_inverse(P_X, P_Y).unsqueeze(0)
        self.P_X = P_X.unsqueeze(2).unsqueeze(3).unsqueeze(4).transpose(0, 4)
        self.P_Y = P_Y.unsqueeze(2).unsqueeze(3).unsqueeze(4).transpose(0, 4)