First use the short side for cropping length, center crop video, then resize to the specified size
| 235 | |
| 236 | |
| 237 | class CenterCropResizeVideo: |
| 238 | """ |
| 239 | First use the short side for cropping length, |
| 240 | center crop video, then resize to the specified size |
| 241 | """ |
| 242 | |
| 243 | def __init__( |
| 244 | self, |
| 245 | size, |
| 246 | interpolation_mode="bilinear", |
| 247 | ): |
| 248 | if isinstance(size, tuple): |
| 249 | if len(size) != 2: |
| 250 | raise ValueError( |
| 251 | f"size should be tuple (height, width), instead got {size}" |
| 252 | ) |
| 253 | self.size = size |
| 254 | else: |
| 255 | self.size = (size, size) |
| 256 | |
| 257 | self.interpolation_mode = interpolation_mode |
| 258 | |
| 259 | def __call__(self, clip): |
| 260 | """ |
| 261 | Args: |
| 262 | clip (torch.tensor): Video clip to be cropped. Size is (T, C, H, W) |
| 263 | Returns: |
| 264 | torch.tensor: scale resized / center cropped video clip. |
| 265 | size is (T, C, crop_size, crop_size) |
| 266 | """ |
| 267 | clip_center_crop = center_crop_using_short_edge(clip) |
| 268 | clip_center_crop_resize = resize( |
| 269 | clip_center_crop, |
| 270 | target_size=self.size, |
| 271 | interpolation_mode=self.interpolation_mode, |
| 272 | ) |
| 273 | return clip_center_crop_resize |
| 274 | |
| 275 | def __repr__(self) -> str: |
| 276 | return f"{self.__class__.__name__}(size={self.size}, interpolation_mode={self.interpolation_mode}" |
| 277 | |
| 278 | |
| 279 | class UCFCenterCropVideo: |
nothing calls this directly
no outgoing calls
no test coverage detected