Skip to content

Commit

Permalink
(bug) Fix exception when creating a TextureAtlas
Browse files Browse the repository at this point in the history
Summary: Fixes GitHub issue #751. The vectorized implementation of bilinear interpolation didn't properly handle the edge cases in the same way as the `grid_sample` method in PyTorch.

Reviewed By: bottler

Differential Revision: D30684208

fbshipit-source-id: edf241ecbd72d46b94ad340a4e601e26c83db88e
  • Loading branch information
nikhilaravi authored and facebook-github-bot committed Sep 1, 2021
1 parent 835e662 commit fc156b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pytorch3d/io/mtl_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def make_material_atlas(

# bi-linearly interpolate the textures from the images
# using the uv coordinates given by uv_pos.
textures = _bilinear_interpolation_vectorized(image, uv_pos)
textures = _bilinear_interpolation_grid_sample(image, uv_pos)

return textures

Expand All @@ -311,11 +311,14 @@ def _bilinear_interpolation_vectorized(
Bi linearly interpolate the image using the uv positions in the flow-field
grid (following the naming conventions for torch.nn.functional.grid_sample).
This implementation uses the same steps as in the SoftRas cuda kernel
to make it easy to compare. This vectorized version requires less memory than
This implementation uses the same steps as in the SoftRasterizer CUDA kernel
for loading textures. We are keeping it for reference to make it easy to
compare if required.
However it doesn't properly handle the out of bound values in the same way as
the grid_sample function does with the padding_mode argument.
This vectorized version requires less memory than
_bilinear_interpolation_grid_sample but is slightly slower.
If speed is an issue and the number of faces in the mesh and texture image sizes
are small, consider using _bilinear_interpolation_grid_sample instead.
Args:
image: FloatTensor of shape (H, W, D) a single image/input tensor with D
Expand Down
Binary file modified tests/data/test_texture_atlas_8x8_back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fc156b5

Please sign in to comment.