jboth commited on
Commit
fac3209
·
verified ·
1 Parent(s): a32b1b2

Upload pytorch3d_stub/pytorch3d/structures/__init__.py with huggingface_hub

Browse files
pytorch3d_stub/pytorch3d/structures/__init__.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """pytorch3d.structures stub – Meshes only."""
2
+ import torch
3
+
4
+ class Meshes:
5
+ def __init__(self, verts=None, faces=None, textures=None):
6
+ if isinstance(verts, list):
7
+ self._verts_list = [v if isinstance(v, torch.Tensor) else torch.tensor(v, dtype=torch.float32) for v in verts]
8
+ elif isinstance(verts, torch.Tensor):
9
+ self._verts_list = [verts]
10
+ else:
11
+ self._verts_list = []
12
+ if isinstance(faces, list):
13
+ self._faces_list = [f if isinstance(f, torch.Tensor) else torch.tensor(f, dtype=torch.long) for f in faces]
14
+ elif isinstance(faces, torch.Tensor):
15
+ self._faces_list = [faces]
16
+ else:
17
+ self._faces_list = []
18
+ self.textures = textures
19
+
20
+ def verts_list(self):
21
+ return self._verts_list
22
+
23
+ def faces_list(self):
24
+ return self._faces_list
25
+
26
+ def verts_packed(self):
27
+ if self._verts_list:
28
+ return torch.cat(self._verts_list, dim=0)
29
+ return torch.zeros(0, 3)
30
+
31
+ def faces_packed(self):
32
+ if self._faces_list:
33
+ return torch.cat(self._faces_list, dim=0)
34
+ return torch.zeros(0, 3, dtype=torch.long)
35
+
36
+ def num_verts_per_mesh(self):
37
+ return torch.tensor([v.shape[0] for v in self._verts_list])
38
+
39
+ def __len__(self):
40
+ return len(self._verts_list)