Perform spatial sampling on the given video frames. If spatial_idx is -1, perform random scale, random crop, and random flip on the given frames. If spatial_idx is 0, 1, or 2, perform spatial uniform sampling with the given spatial_idx. Args: frames (tensor): frames of i
(
frames,
spatial_idx=-1,
min_scale=256,
max_scale=320,
crop_size=224,
random_horizontal_flip=True,
inverse_uniform_sampling=False,
aspect_ratio=None,
scale=None,
motion_shift=False,
)
| 107 | |
| 108 | |
| 109 | def spatial_sampling( |
| 110 | frames, |
| 111 | spatial_idx=-1, |
| 112 | min_scale=256, |
| 113 | max_scale=320, |
| 114 | crop_size=224, |
| 115 | random_horizontal_flip=True, |
| 116 | inverse_uniform_sampling=False, |
| 117 | aspect_ratio=None, |
| 118 | scale=None, |
| 119 | motion_shift=False, |
| 120 | ): |
| 121 | """ |
| 122 | Perform spatial sampling on the given video frames. If spatial_idx is |
| 123 | -1, perform random scale, random crop, and random flip on the given |
| 124 | frames. If spatial_idx is 0, 1, or 2, perform spatial uniform sampling |
| 125 | with the given spatial_idx. |
| 126 | Args: |
| 127 | frames (tensor): frames of images sampled from the video. The |
| 128 | dimension is `num frames` x `height` x `width` x `channel`. |
| 129 | spatial_idx (int): if -1, perform random spatial sampling. If 0, 1, |
| 130 | or 2, perform left, center, right crop if width is larger than |
| 131 | height, and perform top, center, buttom crop if height is larger |
| 132 | than width. |
| 133 | min_scale (int): the minimal size of scaling. |
| 134 | max_scale (int): the maximal size of scaling. |
| 135 | crop_size (int): the size of height and width used to crop the |
| 136 | frames. |
| 137 | inverse_uniform_sampling (bool): if True, sample uniformly in |
| 138 | [1 / max_scale, 1 / min_scale] and take a reciprocal to get the |
| 139 | scale. If False, take a uniform sample from [min_scale, |
| 140 | max_scale]. |
| 141 | aspect_ratio (list): Aspect ratio range for resizing. |
| 142 | scale (list): Scale range for resizing. |
| 143 | motion_shift (bool): Whether to apply motion shift for resizing. |
| 144 | Returns: |
| 145 | frames (tensor): spatially sampled frames. |
| 146 | """ |
| 147 | assert spatial_idx in [-1, 0, 1, 2] |
| 148 | if spatial_idx == -1: |
| 149 | if aspect_ratio is None and scale is None: |
| 150 | frames, _ = transform.random_short_side_scale_jitter( |
| 151 | images=frames, |
| 152 | min_size=min_scale, |
| 153 | max_size=max_scale, |
| 154 | inverse_uniform_sampling=inverse_uniform_sampling, |
| 155 | ) |
| 156 | frames, _ = transform.random_crop(frames, crop_size) |
| 157 | else: |
| 158 | transform_func = ( |
| 159 | transform.random_resized_crop_with_shift |
| 160 | if motion_shift |
| 161 | else transform.random_resized_crop |
| 162 | ) |
| 163 | frames = transform_func( |
| 164 | images=frames, |
| 165 | target_height=crop_size, |
| 166 | target_width=crop_size, |
nothing calls this directly
no outgoing calls
no test coverage detected