r"""Random crop motion sequences. Each sequence will be padded with zeros to the maximum length. Args: min_size (int or None): The minimum size of the cropped motion sequence (inclusive). max_size (int or None): The maximum size of the cropped motion sequence (inclusive).
| 51 | |
| 52 | @PIPELINES.register_module() |
| 53 | class RandomCrop(object): |
| 54 | r"""Random crop motion sequences. Each sequence will be padded with zeros to the maximum length. |
| 55 | |
| 56 | Args: |
| 57 | min_size (int or None): The minimum size of the cropped motion sequence (inclusive). |
| 58 | max_size (int or None): The maximum size of the cropped motion sequence (inclusive). |
| 59 | """ |
| 60 | def __init__(self, |
| 61 | min_size: Optional[Union[int, None]] = None, |
| 62 | max_size: Optional[Union[int, None]] = None): |
| 63 | self.min_size = min_size |
| 64 | self.max_size = max_size |
| 65 | assert self.min_size is not None |
| 66 | assert self.max_size is not None |
| 67 | |
| 68 | def __call__(self, results): |
| 69 | motion = results['motion'] |
| 70 | length = len(motion) |
| 71 | crop_size = random.randint(self.min_size, self.max_size) |
| 72 | if length > crop_size: |
| 73 | idx = random.randint(0, length - crop_size) |
| 74 | motion = motion[idx: idx + crop_size] |
| 75 | results['motion_length'] = crop_size |
| 76 | else: |
| 77 | results['motion_length'] = length |
| 78 | padding_length = self.max_size - min(crop_size, length) |
| 79 | if padding_length > 0: |
| 80 | D = motion.shape[1:] |
| 81 | padding_zeros = np.zeros((padding_length, *D), dtype=np.float32) |
| 82 | motion = np.concatenate([motion, padding_zeros], axis=0) |
| 83 | results['motion'] = motion |
| 84 | results['motion_shape'] = motion.shape |
| 85 | if length >= self.max_size and crop_size == self.max_size: |
| 86 | results['motion_mask'] = torch.ones(self.max_size).numpy() |
| 87 | else: |
| 88 | results['motion_mask'] = torch.cat(( |
| 89 | torch.ones(min(length, crop_size)), |
| 90 | torch.zeros(self.max_size - min(length, crop_size))), dim=0).numpy() |
| 91 | assert len(motion) == self.max_size |
| 92 | return results |
| 93 | |
| 94 | |
| 95 | def __repr__(self): |
| 96 | repr_str = self.__class__.__name__ + f'(min_size={self.min_size}' |
| 97 | repr_str += f', max_size={self.max_size})' |
| 98 | return repr_str |
| 99 | |
| 100 | @PIPELINES.register_module() |
| 101 | class Normalize(object): |
nothing calls this directly
no outgoing calls
no test coverage detected