@@ -137,7 +137,7 @@ def _pad_texture_maps(
137
137
# This is also useful to have so that inside `Meshes`
138
138
# we can allow the input textures to be any texture
139
139
# type which is an instance of the base class.
140
- class TexturesBase ( object ) :
140
+ class TexturesBase :
141
141
def __init__ (self ):
142
142
self ._N = 0
143
143
self .valid = None
@@ -262,9 +262,6 @@ class attributes for item i. Then, a new
262
262
"""
263
263
raise NotImplementedError ()
264
264
265
- def __repr__ (self ):
266
- return "TexturesBase"
267
-
268
265
269
266
def Textures (
270
267
maps : Union [List , torch .Tensor , None ] = None ,
@@ -385,14 +382,6 @@ def __init__(self, atlas: Union[torch.Tensor, List, None]):
385
382
# refer to the __init__ of Meshes.
386
383
self .valid = torch .ones ((self ._N ,), dtype = torch .bool , device = self .device )
387
384
388
- # This is a hack to allow the child classes to also have the same representation
389
- # as the parent. In meshes.py we check that the input textures have the correct
390
- # type. However due to circular imports issues, we can't import the texture
391
- # classes into any files in pytorch3d.structures. Instead we check
392
- # for repr(textures) == "TexturesBase".
393
- def __repr__ (self ):
394
- return super ().__repr__ ()
395
-
396
385
def clone (self ):
397
386
tex = self .__class__ (atlas = self .atlas_padded ().clone ())
398
387
if self ._atlas_list is not None :
@@ -556,10 +545,7 @@ def __init__(
556
545
[(H, W, 3)] or a padded tensor of shape (N, H, W, 3)
557
546
faces_uvs: (N, F, 3) tensor giving the index into verts_uvs for each face
558
547
verts_uvs: (N, V, 2) tensor giving the uv coordinates per vertex
559
-
560
- Note: only the padded and list representation of the textures are stored
561
- and the packed representations is computed on the fly and
562
- not cached.
548
+ (a FloatTensor with values between 0 and 1)
563
549
"""
564
550
super ().__init__ ()
565
551
if isinstance (faces_uvs , (list , tuple )):
@@ -611,9 +597,6 @@ def __init__(
611
597
"verts_uvs and faces_uvs must have the same batch dimension"
612
598
)
613
599
if not all (v .device == self .device for v in verts_uvs ):
614
- import pdb
615
-
616
- pdb .set_trace ()
617
600
raise ValueError ("verts_uvs and faces_uvs must be on the same device" )
618
601
619
602
# These values may be overridden when textures is
@@ -669,9 +652,6 @@ def __init__(
669
652
670
653
self .valid = torch .ones ((self ._N ,), dtype = torch .bool , device = self .device )
671
654
672
- def __repr__ (self ):
673
- return super ().__repr__ ()
674
-
675
655
def clone (self ):
676
656
tex = self .__class__ (
677
657
self .maps_padded ().clone (),
@@ -759,12 +739,6 @@ def faces_uvs_list(self) -> List[torch.Tensor]:
759
739
)
760
740
return self ._faces_uvs_list
761
741
762
- def faces_uvs_packed (self ) -> torch .Tensor :
763
- if self .isempty ():
764
- return torch .zeros ((self ._N , 3 ), dtype = torch .float32 , device = self .device )
765
- faces_uvs_list = self .faces_uvs_list ()
766
- return list_to_packed (faces_uvs_list )[0 ]
767
-
768
742
def verts_uvs_padded (self ) -> torch .Tensor :
769
743
if self ._verts_uvs_padded is None :
770
744
if self .isempty ():
@@ -789,12 +763,6 @@ def verts_uvs_list(self) -> List[torch.Tensor]:
789
763
)
790
764
return self ._verts_uvs_list
791
765
792
- def verts_uvs_packed (self ) -> torch .Tensor :
793
- if self .isempty ():
794
- return torch .zeros ((self ._N , 2 ), dtype = torch .float32 , device = self .device )
795
- verts_uvs_list = self .verts_uvs_list ()
796
- return list_to_packed (verts_uvs_list )[0 ]
797
-
798
766
# Currently only the padded maps are used.
799
767
def maps_padded (self ) -> torch .Tensor :
800
768
return self ._maps_padded
@@ -850,9 +818,15 @@ def sample_textures(self, fragments, **kwargs) -> torch.Tensor:
850
818
texels: tensor of shape (N, H, W, K, C) giving the interpolated
851
819
texture for each pixel in the rasterized image.
852
820
"""
853
- verts_uvs = self .verts_uvs_packed ()
854
- faces_uvs = self .faces_uvs_packed ()
855
- faces_verts_uvs = verts_uvs [faces_uvs ]
821
+ if self .isempty ():
822
+ faces_verts_uvs = torch .zeros (
823
+ (self ._N , 3 , 2 ), dtype = torch .float32 , device = self .device
824
+ )
825
+ else :
826
+ packing_list = [
827
+ i [j ] for i , j in zip (self .verts_uvs_list (), self .faces_uvs_list ())
828
+ ]
829
+ faces_verts_uvs = torch .cat (packing_list )
856
830
texture_maps = self .maps_padded ()
857
831
858
832
# pixel_uvs: (N, H, W, K, 2)
@@ -890,6 +864,7 @@ def sample_textures(self, fragments, **kwargs) -> torch.Tensor:
890
864
if texture_maps .device != pixel_uvs .device :
891
865
texture_maps = texture_maps .to (pixel_uvs .device )
892
866
texels = F .grid_sample (texture_maps , pixel_uvs , align_corners = False )
867
+ # texels now has shape (NK, C, H_out, W_out)
893
868
texels = texels .reshape (N , K , C , H_out , W_out ).permute (0 , 3 , 4 , 1 , 2 )
894
869
return texels
895
870
@@ -990,9 +965,6 @@ def __init__(
990
965
# refer to the __init__ of Meshes.
991
966
self .valid = torch .ones ((self ._N ,), dtype = torch .bool , device = self .device )
992
967
993
- def __repr__ (self ):
994
- return super ().__repr__ ()
995
-
996
968
def clone (self ):
997
969
tex = self .__class__ (self .verts_features_padded ().clone ())
998
970
if self ._verts_features_list is not None :
@@ -1048,7 +1020,7 @@ def verts_features_list(self) -> List[torch.Tensor]:
1048
1020
if self ._verts_features_list is None :
1049
1021
if self .isempty ():
1050
1022
self ._verts_features_list = [
1051
- torch .empty ((0 , 3 , 0 ), dtype = torch .float32 , device = self .device )
1023
+ torch .empty ((0 , 3 ), dtype = torch .float32 , device = self .device )
1052
1024
] * self ._N
1053
1025
else :
1054
1026
self ._verts_features_list = padded_to_list (
0 commit comments