(
image_size: int,
rescale_factor: float = 1.0,
mean: Optional[Tuple[float, ...]] = None,
std: Optional[Tuple[float, ...]] = None,
random_flip = False,
)
| 25 | INTERNVIDEO_STD = (0.229, 0.224, 0.225) |
| 26 | |
| 27 | def image_transform( |
| 28 | image_size: int, |
| 29 | rescale_factor: float = 1.0, |
| 30 | mean: Optional[Tuple[float, ...]] = None, |
| 31 | std: Optional[Tuple[float, ...]] = None, |
| 32 | random_flip = False, |
| 33 | ): |
| 34 | mean = mean or OPENAI_DATASET_MEAN |
| 35 | if not isinstance(mean, (list, tuple)): |
| 36 | mean = (mean,) * 3 |
| 37 | |
| 38 | std = std or OPENAI_DATASET_STD |
| 39 | if not isinstance(std, (list, tuple)): |
| 40 | std = (std,) * 3 |
| 41 | |
| 42 | if isinstance(image_size, (list, tuple)) and image_size[0] == image_size[1]: |
| 43 | # for square size, pass size as int so that Resize() uses aspect preserving shortest edge |
| 44 | image_size = image_size[0] |
| 45 | |
| 46 | normalize = Normalize(mean=mean, std=std) |
| 47 | |
| 48 | transforms = [ |
| 49 | Resize(image_size, interpolation=InterpolationMode.BICUBIC), |
| 50 | CenterCrop(image_size), |
| 51 | RandomHorizontalFlip() if random_flip else Lambda(lambda x: x), |
| 52 | ] |
| 53 | |
| 54 | transforms.extend([ |
| 55 | _convert_to_rgb, |
| 56 | ToTensor(), |
| 57 | normalize, |
| 58 | ]) |
| 59 | return Compose(transforms) |
| 60 | |
| 61 | def frame_transform( |
| 62 | image_size: Union[int, Tuple[int, int]], |
nothing calls this directly
no outgoing calls
no test coverage detected