Wrapper for grid_sample, uses pixel coordinates
(img, coords, mode='bilinear', mask=False)
| 56 | return torch.from_numpy(flow).float() |
| 57 | |
| 58 | def bilinear_sampler(img, coords, mode='bilinear', mask=False): |
| 59 | """ Wrapper for grid_sample, uses pixel coordinates """ |
| 60 | H, W = img.shape[-2:] |
| 61 | xgrid, ygrid = coords.split([1,1], dim=-1) |
| 62 | xgrid = 2*xgrid/(W-1) - 1 |
| 63 | ygrid = 2*ygrid/(H-1) - 1 |
| 64 | |
| 65 | grid = torch.cat([xgrid, ygrid], dim=-1) |
| 66 | img = F.grid_sample(img, grid, align_corners=True) |
| 67 | |
| 68 | if mask: |
| 69 | mask = (xgrid > -1) & (ygrid > -1) & (xgrid < 1) & (ygrid < 1) |
| 70 | return img, mask.float() |
| 71 | |
| 72 | return img |
| 73 | |
| 74 | def indexing(img, coords, mask=False): |
| 75 | """ Wrapper for grid_sample, uses pixel coordinates """ |
no outgoing calls
no test coverage detected