| 441 | |
| 442 | class HomographyGridGen(Module): |
| 443 | def __init__(self, out_h=240, out_w=240, use_cuda=True): |
| 444 | super(HomographyGridGen, self).__init__() |
| 445 | self.out_h, self.out_w = out_h, out_w |
| 446 | self.use_cuda = use_cuda |
| 447 | |
| 448 | # create grid in numpy |
| 449 | # self.grid = np.zeros( [self.out_h, self.out_w, 3], dtype=np.float32) |
| 450 | # sampling grid with dim-0 coords (Y) |
| 451 | self.grid_X, self.grid_Y = np.meshgrid(np.linspace(-1, 1, out_w), np.linspace(-1, 1, out_h)) |
| 452 | # grid_X,grid_Y: size [1,H,W,1,1] |
| 453 | self.grid_X = torch.FloatTensor(self.grid_X).unsqueeze(0).unsqueeze(3) |
| 454 | self.grid_Y = torch.FloatTensor(self.grid_Y).unsqueeze(0).unsqueeze(3) |
| 455 | self.grid_X = Variable(self.grid_X, requires_grad=False) |
| 456 | self.grid_Y = Variable(self.grid_Y, requires_grad=False) |
| 457 | if use_cuda: |
| 458 | self.grid_X = self.grid_X.cuda() |
| 459 | self.grid_Y = self.grid_Y.cuda() |
| 460 | |
| 461 | def forward(self, theta): |
| 462 | b = theta.size(0) |