Skip to content

Commit c538725

Browse files
bottlerfacebook-github-bot
authored andcommitted
use C for #channels in textures
Summary: Comments in textures.py were inconsistent in describing the number of channels, sometimes C, sometimes D, sometimes 3. Now always C. Reviewed By: patricklabatut Differential Revision: D29263435 fbshipit-source-id: 7c1260c164c52852dc9e14d0e12da4cfb64af408
1 parent c639198 commit c538725

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

pytorch3d/renderer/mesh/textures.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,17 @@ def _pad_texture_maps(
109109
Pad all texture images so they have the same height and width.
110110
111111
Args:
112-
images: list of N tensors of shape (H_i, W_i, 3)
112+
images: list of N tensors of shape (H_i, W_i, C)
113113
align_corners: used for interpolation
114114
115115
Returns:
116-
tex_maps: Tensor of shape (N, max_H, max_W, 3)
116+
tex_maps: Tensor of shape (N, max_H, max_W, C)
117117
"""
118118
tex_maps = []
119119
max_H = 0
120120
max_W = 0
121121
for im in images:
122-
h, w, _3 = im.shape
122+
h, w, _C = im.shape
123123
if h > max_H:
124124
max_H = h
125125
if w > max_W:
@@ -134,7 +134,7 @@ def _pad_texture_maps(
134134
image_BCHW, size=max_shape, mode="bilinear", align_corners=align_corners
135135
)
136136
tex_maps[i] = new_image_BCHW[0].permute(1, 2, 0)
137-
tex_maps = torch.stack(tex_maps, dim=0) # (num_tex_maps, max_H, max_W, 3)
137+
tex_maps = torch.stack(tex_maps, dim=0) # (num_tex_maps, max_H, max_W, C)
138138
return tex_maps
139139

140140

@@ -288,12 +288,12 @@ def Textures(
288288
289289
Args:
290290
maps: texture map per mesh. This can either be a list of maps
291-
[(H, W, 3)] or a padded tensor of shape (N, H, W, 3).
291+
[(H, W, C)] or a padded tensor of shape (N, H, W, C).
292292
faces_uvs: (N, F, 3) tensor giving the index into verts_uvs for each
293293
vertex in the face. Padding value is assumed to be -1.
294294
verts_uvs: (N, V, 2) tensor giving the uv coordinate per vertex.
295-
verts_rgb: (N, V, 3) tensor giving the rgb color per vertex. Padding
296-
value is assumed to be -1.
295+
verts_rgb: (N, V, C) tensor giving the color per vertex. Padding
296+
value is assumed to be -1. (C=3 for RGB.)
297297
298298
299299
Returns:
@@ -327,7 +327,7 @@ def __init__(self, atlas: Union[torch.Tensor, List[torch.Tensor]]):
327327
This is based on the implementation from SoftRasterizer [1].
328328
329329
Args:
330-
atlas: (N, F, R, R, D) tensor giving the per face texture map.
330+
atlas: (N, F, R, R, C) tensor giving the per face texture map.
331331
The atlas can be created during obj loading with the
332332
pytorch3d.io.load_obj function - in the input arguments
333333
set `create_texture_atlas=True`. The atlas will be
@@ -354,7 +354,7 @@ def __init__(self, atlas: Union[torch.Tensor, List[torch.Tensor]]):
354354
)
355355
if not correct_format:
356356
msg = (
357-
"Expected atlas to be a list of tensors of shape (F, R, R, D) "
357+
"Expected atlas to be a list of tensors of shape (F, R, R, C) "
358358
"with the same value of R."
359359
)
360360
raise ValueError(msg)
@@ -373,7 +373,7 @@ def __init__(self, atlas: Union[torch.Tensor, List[torch.Tensor]]):
373373

374374
elif torch.is_tensor(atlas):
375375
if atlas.ndim != 5:
376-
msg = "Expected atlas to be of shape (N, F, R, R, D); got %r"
376+
msg = "Expected atlas to be of shape (N, F, R, R, C); got %r"
377377
raise ValueError(msg % repr(atlas.ndim))
378378
self._atlas_padded = atlas
379379
self._atlas_list = None
@@ -499,7 +499,7 @@ def sample_textures(self, fragments, **kwargs) -> torch.Tensor:
499499
representation) which overlap the pixel.
500500
501501
Returns:
502-
texels: (N, H, W, K, 3)
502+
texels: (N, H, W, K, C)
503503
"""
504504
N, H, W, K = fragments.pix_to_face.shape
505505
atlas_packed = self.atlas_packed()
@@ -532,7 +532,7 @@ def faces_verts_textures_packed(self) -> torch.Tensor:
532532
"""
533533
Samples texture from each vertex for each face in the mesh.
534534
For N meshes with {Fi} number of faces, it returns a
535-
tensor of shape sum(Fi)x3xD (D = 3 for RGB).
535+
tensor of shape sum(Fi)x3xC (C = 3 for RGB).
536536
You can use the utils function in structures.utils to convert the
537537
packed representation to a list or padded.
538538
"""
@@ -603,7 +603,8 @@ def __init__(
603603
604604
Args:
605605
maps: texture map per mesh. This can either be a list of maps
606-
[(H, W, 3)] or a padded tensor of shape (N, H, W, 3)
606+
[(H, W, C)] or a padded tensor of shape (N, H, W, C).
607+
For RGB, C = 3.
607608
faces_uvs: (N, F, 3) LongTensor giving the index into verts_uvs
608609
for each face
609610
verts_uvs: (N, V, 2) tensor giving the uv coordinates per vertex
@@ -708,7 +709,7 @@ def __init__(
708709

709710
if isinstance(maps, torch.Tensor):
710711
if maps.ndim != 4 or maps.shape[0] != self._N:
711-
msg = "Expected maps to be of shape (N, H, W, 3); got %r"
712+
msg = "Expected maps to be of shape (N, H, W, C); got %r"
712713
raise ValueError(msg % repr(maps.shape))
713714
self._maps_padded = maps
714715
self._maps_list = None
@@ -1061,8 +1062,8 @@ def _place_map_into_single_map(
10611062
Used by join_scene.
10621063
10631064
Args:
1064-
single_map: (total_H, total_W, 3)
1065-
map_: (H, W, 3) source data
1065+
single_map: (total_H, total_W, C)
1066+
map_: (H, W, C) source data
10661067
location: where to place map
10671068
"""
10681069
do_flip = location.flipped
@@ -1246,10 +1247,10 @@ def __init__(
12461247
):
12471248
"""
12481249
Batched texture representation where each vertex in a mesh
1249-
has a D dimensional feature vector.
1250+
has a C dimensional feature vector.
12501251
12511252
Args:
1252-
verts_features: list of (Vi, D) or (N, V, D) tensor giving a feature
1253+
verts_features: list of (Vi, C) or (N, V, C) tensor giving a feature
12531254
vector with arbitrary dimensions for each vertex.
12541255
"""
12551256
if isinstance(verts_features, (tuple, list)):
@@ -1258,7 +1259,7 @@ def __init__(
12581259
)
12591260
if not correct_shape:
12601261
raise ValueError(
1261-
"Expected verts_features to be a list of tensors of shape (V, D)."
1262+
"Expected verts_features to be a list of tensors of shape (V, C)."
12621263
)
12631264

12641265
self._verts_features_list = verts_features
@@ -1276,7 +1277,7 @@ def __init__(
12761277

12771278
elif torch.is_tensor(verts_features):
12781279
if verts_features.ndim != 3:
1279-
msg = "Expected verts_features to be of shape (N, V, D); got %r"
1280+
msg = "Expected verts_features to be of shape (N, V, C); got %r"
12801281
raise ValueError(msg % repr(verts_features.shape))
12811282
self._verts_features_padded = verts_features
12821283
self._verts_features_list = None

0 commit comments

Comments
 (0)