mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Expose bicubic mode for torch::nn::functional::grid_sample in LibTorch (#150817)
When bicubic interpolation was added to grid_sampler in #44780, `GridSampleFuncOptions` was not updated to allow a user to use bicubic mode in LibTorch, even though the function could handle it. This PR fixes the parity such that LibTorch's `torch::nn::functional::grid_sample` behaves the same as PyTorch's `torch.nn.functional.grid_sample`. Existing users can directly use `torch::grid_sampler` but must know what int to pass for the interpolation (2 for bicubic) and padding mode parameters, which is not ideal. Pull Request resolved: https://github.com/pytorch/pytorch/pull/150817 Approved by: https://github.com/Skylion007
This commit is contained in:
committed by
PyTorch MergeBot
parent
2a9afdae81
commit
bf28d1cafc
@ -631,6 +631,17 @@ TEST_F(FunctionalTest, GridSample) {
|
||||
|
||||
ASSERT_TRUE(output.allclose(expected));
|
||||
|
||||
// bicubic, zeros, true
|
||||
options = F::GridSampleFuncOptions()
|
||||
.mode(torch::kBicubic)
|
||||
.padding_mode(torch::kZeros)
|
||||
.align_corners(true);
|
||||
output = F::grid_sample(input, grid, options);
|
||||
expected = torch::tensor(
|
||||
{{{{0., 0., 1.}, {3., 4., 5.}, {7., 8., 0.}}}}, torch::kFloat);
|
||||
|
||||
ASSERT_TRUE(output.allclose(expected));
|
||||
|
||||
// bilinear, border, true
|
||||
options = F::GridSampleFuncOptions()
|
||||
.mode(torch::kBilinear)
|
||||
|
Reference in New Issue
Block a user