-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
is that possible to replace your TrilinearInterpolation with torch.nn.functional.grid_sample? #14
Comments
Hi, this is an interesting idea. |
Hi! grid_sample actually uses trilinear interpolation if a 5d tensor is passed when mode is set to bilinear. So, instead of using
one can use:
|
changing to:ndarr = result.squeeze().mul_(255).add_(0.5).clamp_(0, 255).permute(1, 2, 0).to('cpu', torch.uint8).numpy() to ndarr = result.squeeze().mul_(255).add_(0.5).clamp_(0, 255).to('cpu', torch.uint8).numpy() |
Has anyone ever used grid_sample instead of Trilinear Interpolation? Why is the result of using grid_sample worse? |
scale im between -1 and 1 since its used as grid input in grid_sampleimg = (img - .5) * 2. grid_sample expects NxDxHxWx3 (1x1xHxWx3)img = img.permute(0, 2, 3, 1)[:, None] add batch dim to LUTLUT = LUT[None] grid sampleresult = F.grid_sample(LUT, img, mode='bilinear', padding_mode='border', align_corners=True) drop added dimensions and permute backresult = result[:, :, 0].permute(0, 2, 3, 1) How to set batch_size > 1? LUT = LUT[None] --> LUT = LUT[None].repeat(bs, 1,1,1,1) is ok? |
good trick! |
/
Could you please add an _ext function to the code? it seemed that the code lack it. |
is that possible to replace your TrilinearInterpolation with torch.nn.functional.grid_sample? If ok, it would be more convenient.
The text was updated successfully, but these errors were encountered: