mmtracking icon indicating copy to clipboard operation
mmtracking copied to clipboard

Abount flow grid in mmtrack.core.motion.flow.py line 27,29

Open haodehao opened this issue 3 years ago • 1 comments

I think it should be: grid[:, 0] = grid[:, 0] / (W-1) * 2 - 1 grid[:, 1] = grid[:, 1] / (H-1) * 2 - 1

demo test: import torch import torch.nn.functional as F

x = torch.arange(1,5, dtype=torch.float32)
x = x.view(1,1,2,2)
print('input', x)

h, w = x.shape[-2:]
h_grid, w_grid = torch.meshgrid(torch.arange(h), torch.arange(w))


grid = torch.cat((w_grid[None, None, ...], h_grid[None, None, ...]), dim=1)

grid[:, 0] = grid[:, 0] / (w-1) * 2 - 1
grid[:, 1] = grid[:, 1] / (h-1) * 2 - 1

grid = grid.permute(0, 2, 3, 1).float()
print('grid', grid)

x_warp = F.grid_sample(x, grid, padding_mode='border', align_corners=True)
print('x_warp', x_warp)

haodehao avatar Mar 22 '22 03:03 haodehao

What you said is right in the case of 'align_corners=True'. Could you please create a PR to fix it?

JingweiZhang12 avatar Mar 24 '22 03:03 JingweiZhang12