nerfstudio icon indicating copy to clipboard operation
nerfstudio copied to clipboard

Tricky thing about the F.grid_sample

Open liruilong940607 opened this issue 3 years ago • 1 comments

Issue of the F.grid_sample: padding_mode==zeros means padding zero voxel values outside the grid. a query point that is slightly outside the grid would be interpolated by the voxel values on the boarder of the grid and the outside zero voxels. So it gives non-zero value at regions slightly outside the grid.

Toy code to show:

grid = torch.ones((1, 1, 128, 128, 128))
positions = torch.tensor([[0.5, 1.004, 0.5]])
values = F.grid_sample(
    grid,
    positions.view(1, -1, 1, 1, 3),
    align_corners=True,
    padding_mode="zeros",
)
print(values.flatten())  # >> 0.7460

Relevant code in our code base:

https://github.com/plenoptix/pyrad/blob/91ef54963c43beb34f13301f8496faf2f0de8a2e/pyrad/fields/occupancy_fields/occupancy_grid.py#L131

liruilong940607 avatar Jul 14 '22 05:07 liruilong940607

It shouldn't affect the performance as the border of the occupancy grid would be learnt to be zero. But the cuda code I'm writting would make sure all points outside the boarder have zero values, which would results slightly different behavior with F.grid_sample but should be more suitable for our case.

liruilong940607 avatar Jul 14 '22 05:07 liruilong940607