r"""Crop motion sequences. Args: crop_size (int): The size of the cropped motion sequence.
| 9 | |
| 10 | @PIPELINES.register_module() |
| 11 | class Crop(object): |
| 12 | r"""Crop motion sequences. |
| 13 | |
| 14 | Args: |
| 15 | crop_size (int): The size of the cropped motion sequence. |
| 16 | """ |
| 17 | |
| 18 | def __init__(self, crop_size: Optional[Union[int, None]] = None): |
| 19 | self.crop_size = crop_size |
| 20 | assert self.crop_size is not None |
| 21 | |
| 22 | def __call__(self, results): |
| 23 | motion = results['motion'] |
| 24 | length = len(motion) |
| 25 | if length >= self.crop_size: |
| 26 | idx = random.randint(0, length - self.crop_size) |
| 27 | motion = motion[idx:idx + self.crop_size] |
| 28 | results['motion_length'] = self.crop_size |
| 29 | else: |
| 30 | padding_length = self.crop_size - length |
| 31 | D = motion.shape[1:] |
| 32 | padding_zeros = np.zeros((padding_length, *D), dtype=np.float32) |
| 33 | motion = np.concatenate([motion, padding_zeros], axis=0) |
| 34 | results['motion_length'] = length |
| 35 | assert len(motion) == self.crop_size |
| 36 | results['motion'] = motion |
| 37 | results['motion_shape'] = motion.shape |
| 38 | if length >= self.crop_size: |
| 39 | results['motion_mask'] = torch.ones(self.crop_size).numpy() |
| 40 | else: |
| 41 | results['motion_mask'] = torch.cat( |
| 42 | (torch.ones(length), |
| 43 | torch.zeros(self.crop_size - length))).numpy() |
| 44 | return results |
| 45 | |
| 46 | def __repr__(self): |
| 47 | repr_str = self.__class__.__name__ + f'(crop_size={self.crop_size})' |
| 48 | return repr_str |
| 49 | |
| 50 | |
| 51 | @PIPELINES.register_module() |
nothing calls this directly
no outgoing calls
no test coverage detected