MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / Compose

Class Compose

detrsmpl/utils/transforms.py:38–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36
37
38class Compose:
39 def __init__(self, transforms: list):
40 """Composes several transforms together. This transform does not
41 support torchscript.
42
43 Args:
44 transforms (list): (list of transform functions)
45 """
46 self.transforms = transforms
47
48 def __call__(self,
49 rotation: Union[torch.Tensor, numpy.ndarray],
50 convention: str = 'xyz',
51 **kwargs):
52 convention = convention.lower()
53 if not (set(convention) == set('xyz') and len(convention) == 3):
54 raise ValueError(f'Invalid convention {convention}.')
55 if isinstance(rotation, numpy.ndarray):
56 data_type = 'numpy'
57 rotation = torch.FloatTensor(rotation)
58 elif isinstance(rotation, torch.Tensor):
59 data_type = 'tensor'
60 else:
61 raise TypeError(
62 'Type of rotation should be torch.Tensor or numpy.ndarray')
63 for t in self.transforms:
64 if 'convention' in t.__code__.co_varnames:
65 rotation = t(rotation, convention.upper(), **kwargs)
66 else:
67 rotation = t(rotation, **kwargs)
68 if data_type == 'numpy':
69 rotation = rotation.detach().cpu().numpy()
70 return rotation
71
72
73def aa_to_rotmat(

Callers 15

aa_to_rotmatFunction · 0.70
aa_to_quatFunction · 0.70
ee_to_rotmatFunction · 0.70
rotmat_to_eeFunction · 0.70
rotmat_to_quatFunction · 0.70
rotmat_to_rot6dFunction · 0.70
quat_to_aaFunction · 0.70
quat_to_rotmatFunction · 0.70
rot6d_to_rotmatFunction · 0.70
aa_to_eeFunction · 0.70
aa_to_rot6dFunction · 0.70
ee_to_aaFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected