Bobby commited on
Commit
32bc653
·
1 Parent(s): 09e4a17

Make kaolin optional for FlexiCubes import on Spaces

Browse files
trellis/representations/mesh/flexicubes/flexicubes.py CHANGED
@@ -8,7 +8,21 @@
8
 
9
  import torch
10
  from .tables import *
11
- from kaolin.utils.testing import check_tensor
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  __all__ = [
14
  'FlexiCubes'
 
8
 
9
  import torch
10
  from .tables import *
11
+
12
+ try:
13
+ from kaolin.utils.testing import check_tensor
14
+ except ImportError:
15
+ def check_tensor(tensor, shape, throw=False):
16
+ """Fallback for kaolin.utils.testing.check_tensor used in Spaces builds."""
17
+ ok = torch.is_tensor(tensor) and tensor.ndim == len(shape)
18
+ if ok:
19
+ for i, expected in enumerate(shape):
20
+ if expected is not None and tensor.shape[i] != expected:
21
+ ok = False
22
+ break
23
+ if throw and not ok:
24
+ raise ValueError(f"Tensor shape {tuple(tensor.shape)} does not match expected {shape}")
25
+ return ok
26
 
27
  __all__ = [
28
  'FlexiCubes'