MCPcopy Create free account
hub / github.com/MotrixLab/insactor / Crop

Class Crop

diffplanner/datasets/pipelines/transforms.py:13–50  ·  view source on GitHub ↗

r"""Crop motion sequences. Args: crop_size (int): The size of the cropped motion sequence.

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected