@@ -251,7 +251,7 @@ def test_padded_to_packed(self):
251
251
def test_getitem (self ):
252
252
N = 5
253
253
V = 20
254
- source = {"verts_features" : torch .randn (size = (N , 10 , 128 ))}
254
+ source = {"verts_features" : torch .randn (size = (N , V , 128 ))}
255
255
tex = TexturesVertex (verts_features = source ["verts_features" ])
256
256
257
257
verts = torch .rand (size = (N , V , 3 ))
@@ -268,6 +268,30 @@ def test_getitem(self):
268
268
tryindex (self , index , tex , meshes , source )
269
269
tryindex (self , [2 , 4 ], tex , meshes , source )
270
270
271
+ def test_sample_textures_error (self ):
272
+ N = 5
273
+ V = 20
274
+ verts = torch .rand (size = (N , V , 3 ))
275
+ faces = torch .randint (size = (N , 10 , 3 ), high = V )
276
+ tex = TexturesVertex (verts_features = torch .randn (size = (N , 10 , 128 )))
277
+
278
+ # Verts features have the wrong number of verts
279
+ with self .assertRaisesRegex (ValueError , "do not match the dimensions" ):
280
+ Meshes (verts = verts , faces = faces , textures = tex )
281
+
282
+ # Verts features have the wrong batch dim
283
+ tex = TexturesVertex (verts_features = torch .randn (size = (1 , V , 128 )))
284
+ with self .assertRaisesRegex (ValueError , "do not match the dimensions" ):
285
+ Meshes (verts = verts , faces = faces , textures = tex )
286
+
287
+ meshes = Meshes (verts = verts , faces = faces )
288
+ meshes .textures = tex
289
+
290
+ # Cannot use the texture attribute set on meshes for sampling
291
+ # textures if the dimensions don't match
292
+ with self .assertRaisesRegex (ValueError , "do not match the dimensions" ):
293
+ meshes .sample_textures (None )
294
+
271
295
272
296
class TestTexturesAtlas (TestCaseMixin , unittest .TestCase ):
273
297
def test_sample_texture_atlas (self ):
@@ -456,11 +480,12 @@ def test_padded_to_packed(self):
456
480
def test_getitem (self ):
457
481
N = 5
458
482
V = 20
459
- source = {"atlas" : torch .randn (size = (N , 10 , 4 , 4 , 3 ))}
483
+ F = 10
484
+ source = {"atlas" : torch .randn (size = (N , F , 4 , 4 , 3 ))}
460
485
tex = TexturesAtlas (atlas = source ["atlas" ])
461
486
462
487
verts = torch .rand (size = (N , V , 3 ))
463
- faces = torch .randint (size = (N , 10 , 3 ), high = V )
488
+ faces = torch .randint (size = (N , F , 3 ), high = V )
464
489
meshes = Meshes (verts = verts , faces = faces , textures = tex )
465
490
466
491
tryindex (self , 2 , tex , meshes , source )
@@ -473,6 +498,32 @@ def test_getitem(self):
473
498
tryindex (self , index , tex , meshes , source )
474
499
tryindex (self , [2 , 4 ], tex , meshes , source )
475
500
501
+ def test_sample_textures_error (self ):
502
+ N = 1
503
+ V = 20
504
+ F = 10
505
+ verts = torch .rand (size = (5 , V , 3 ))
506
+ faces = torch .randint (size = (5 , F , 3 ), high = V )
507
+ meshes = Meshes (verts = verts , faces = faces )
508
+
509
+ # TexturesAtlas have the wrong batch dim
510
+ tex = TexturesAtlas (atlas = torch .randn (size = (1 , F , 4 , 4 , 3 )))
511
+ with self .assertRaisesRegex (ValueError , "do not match the dimensions" ):
512
+ Meshes (verts = verts , faces = faces , textures = tex )
513
+
514
+ # TexturesAtlas have the wrong number of faces
515
+ tex = TexturesAtlas (atlas = torch .randn (size = (N , 15 , 4 , 4 , 3 )))
516
+ with self .assertRaisesRegex (ValueError , "do not match the dimensions" ):
517
+ Meshes (verts = verts , faces = faces , textures = tex )
518
+
519
+ meshes = Meshes (verts = verts , faces = faces )
520
+ meshes .textures = tex
521
+
522
+ # Cannot use the texture attribute set on meshes for sampling
523
+ # textures if the dimensions don't match
524
+ with self .assertRaisesRegex (ValueError , "do not match the dimensions" ):
525
+ meshes .sample_textures (None )
526
+
476
527
477
528
class TestTexturesUV (TestCaseMixin , unittest .TestCase ):
478
529
def setUp (self ) -> None :
@@ -824,9 +875,10 @@ def test_mesh_to(self):
824
875
def test_getitem (self ):
825
876
N = 5
826
877
V = 20
878
+ F = 10
827
879
source = {
828
880
"maps" : torch .rand (size = (N , 1 , 1 , 3 )),
829
- "faces_uvs" : torch .randint (size = (N , 10 , 3 ), high = V ),
881
+ "faces_uvs" : torch .randint (size = (N , F , 3 ), high = V ),
830
882
"verts_uvs" : torch .randn (size = (N , V , 2 )),
831
883
}
832
884
tex = TexturesUV (
@@ -836,7 +888,7 @@ def test_getitem(self):
836
888
)
837
889
838
890
verts = torch .rand (size = (N , V , 3 ))
839
- faces = torch .randint (size = (N , 10 , 3 ), high = V )
891
+ faces = torch .randint (size = (N , F , 3 ), high = V )
840
892
meshes = Meshes (verts = verts , faces = faces , textures = tex )
841
893
842
894
tryindex (self , 2 , tex , meshes , source )
@@ -858,6 +910,46 @@ def test_centers_for_image(self):
858
910
expected = torch .FloatTensor ([[32 , 224 ], [64 , 96 ], [64 , 128 ]])
859
911
self .assertClose (tex .centers_for_image (0 ), expected )
860
912
913
+ def test_sample_textures_error (self ):
914
+ N = 1
915
+ V = 20
916
+ F = 10
917
+ maps = torch .rand (size = (N , 1 , 1 , 3 ))
918
+ verts_uvs = torch .randn (size = (N , V , 2 ))
919
+ tex = TexturesUV (
920
+ maps = maps ,
921
+ faces_uvs = torch .randint (size = (N , 15 , 3 ), high = V ),
922
+ verts_uvs = verts_uvs ,
923
+ )
924
+ verts = torch .rand (size = (5 , V , 3 ))
925
+ faces = torch .randint (size = (5 , 10 , 3 ), high = V )
926
+ meshes = Meshes (verts = verts , faces = faces )
927
+
928
+ # Wrong number of faces
929
+ with self .assertRaisesRegex (ValueError , "do not match the dimensions" ):
930
+ Meshes (verts = verts , faces = faces , textures = tex )
931
+
932
+ # Wrong batch dim for faces
933
+ tex = TexturesUV (
934
+ maps = maps ,
935
+ faces_uvs = torch .randint (size = (1 , F , 3 ), high = V ),
936
+ verts_uvs = verts_uvs ,
937
+ )
938
+ with self .assertRaisesRegex (ValueError , "do not match the dimensions" ):
939
+ Meshes (verts = verts , faces = faces , textures = tex )
940
+
941
+ # Wrong batch dim for verts_uvs is not necessary to check as
942
+ # there is already a check inside TexturesUV for a batch dim
943
+ # mismatch with faces_uvs
944
+
945
+ meshes = Meshes (verts = verts , faces = faces )
946
+ meshes .textures = tex
947
+
948
+ # Cannot use the texture attribute set on meshes for sampling
949
+ # textures if the dimensions don't match
950
+ with self .assertRaisesRegex (ValueError , "do not match the dimensions" ):
951
+ meshes .sample_textures (None )
952
+
861
953
862
954
class TestRectanglePacking (TestCaseMixin , unittest .TestCase ):
863
955
def setUp (self ) -> None :
0 commit comments