mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-12-20 14:20:38 +08:00
replace view with reshape, check for nans
Summary: Replace view with reshape, add check for nans before mesh sampling Reviewed By: nikhilaravi Differential Revision: D20548456 fbshipit-source-id: c4e1b88e033ecb8f0f3a8f3a33a04ce13a5b5043
This commit is contained in:
committed by
Facebook GitHub Bot
parent
53599770dd
commit
6c48ff6ad9
@@ -41,6 +41,8 @@ def sample_points_from_meshes(
|
||||
raise ValueError("Meshes are empty.")
|
||||
|
||||
verts = meshes.verts_packed()
|
||||
if not torch.isfinite(verts).all():
|
||||
raise ValueError("Meshes contain nan or inf.")
|
||||
faces = meshes.faces_packed()
|
||||
mesh_to_face = meshes.mesh_to_faces_packed_first_idx()
|
||||
num_meshes = len(meshes)
|
||||
|
||||
@@ -53,7 +53,7 @@ def interpolate_texture_map(fragments, meshes) -> torch.Tensor:
|
||||
N, H_in, W_in, C = texture_maps.shape # 3 for RGB
|
||||
|
||||
# pixel_uvs: (N, H, W, K, 2) -> (N, K, H, W, 2) -> (NK, H, W, 2)
|
||||
pixel_uvs = pixel_uvs.permute(0, 3, 1, 2, 4).view(N * K, H_out, W_out, 2)
|
||||
pixel_uvs = pixel_uvs.permute(0, 3, 1, 2, 4).reshape(N * K, H_out, W_out, 2)
|
||||
|
||||
# textures.map:
|
||||
# (N, H, W, C) -> (N, C, H, W) -> (1, N, C, H, W)
|
||||
@@ -81,7 +81,7 @@ def interpolate_texture_map(fragments, meshes) -> torch.Tensor:
|
||||
if texture_maps.device != pixel_uvs.device:
|
||||
texture_maps = texture_maps.to(pixel_uvs.device)
|
||||
texels = F.grid_sample(texture_maps, pixel_uvs, align_corners=False)
|
||||
texels = texels.view(N, K, C, H_out, W_out).permute(0, 3, 4, 1, 2)
|
||||
texels = texels.reshape(N, K, C, H_out, W_out).permute(0, 3, 4, 1, 2)
|
||||
return texels
|
||||
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ def padded_to_packed(
|
||||
"Only one of split_size or pad_value should be provided."
|
||||
)
|
||||
|
||||
x_packed = x.view(-1, D) # flatten padded
|
||||
x_packed = x.reshape(-1, D) # flatten padded
|
||||
|
||||
if pad_value is None and split_size is None:
|
||||
return x_packed
|
||||
|
||||
Reference in New Issue
Block a user