First scale to the specified size in equal proportion to the short edge, then center cropping
| 277 | |
| 278 | |
| 279 | class UCFCenterCropVideo: |
| 280 | """ |
| 281 | First scale to the specified size in equal proportion to the short edge, |
| 282 | then center cropping |
| 283 | """ |
| 284 | |
| 285 | def __init__( |
| 286 | self, |
| 287 | size, |
| 288 | interpolation_mode="bilinear", |
| 289 | ): |
| 290 | if isinstance(size, tuple): |
| 291 | if len(size) != 2: |
| 292 | raise ValueError( |
| 293 | f"size should be tuple (height, width), instead got {size}" |
| 294 | ) |
| 295 | self.size = size |
| 296 | else: |
| 297 | self.size = (size, size) |
| 298 | |
| 299 | self.interpolation_mode = interpolation_mode |
| 300 | |
| 301 | def __call__(self, clip): |
| 302 | """ |
| 303 | Args: |
| 304 | clip (torch.tensor): Video clip to be cropped. Size is (T, C, H, W) |
| 305 | Returns: |
| 306 | torch.tensor: scale resized / center cropped video clip. |
| 307 | size is (T, C, crop_size, crop_size) |
| 308 | """ |
| 309 | clip_resize = resize_scale( |
| 310 | clip=clip, target_size=self.size, interpolation_mode=self.interpolation_mode |
| 311 | ) |
| 312 | clip_center_crop = center_crop(clip_resize, self.size) |
| 313 | return clip_center_crop |
| 314 | |
| 315 | def __repr__(self) -> str: |
| 316 | return f"{self.__class__.__name__}(size={self.size}, interpolation_mode={self.interpolation_mode}" |
| 317 | |
| 318 | |
| 319 | class KineticsRandomCropResizeVideo: |
no outgoing calls
no test coverage detected