| 36 | |
| 37 | |
| 38 | class 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 | |
| 73 | def aa_to_rotmat( |
no outgoing calls
no test coverage detected