(image_size: int = 224, is_training: bool = True, mean=None, std=None)
| 3 | from typing import List, Tuple |
| 4 | |
| 5 | def get_transforms(image_size: int = 224, is_training: bool = True, mean=None, std=None): |
| 6 | if mean is None: |
| 7 | mean = [0.485, 0.456, 0.406] |
| 8 | if std is None: |
| 9 | std = [0.229, 0.224, 0.225] |
| 10 | |
| 11 | if is_training: |
| 12 | return transforms.Compose([ |
| 13 | transforms.RandomResizedCrop(image_size, scale=(0.8, 1.0)), |
| 14 | transforms.RandomHorizontalFlip(p=0.5), |
| 15 | transforms.RandomVerticalFlip(p=0.1), |
| 16 | transforms.ColorJitter(brightness=0.2, contrast=0.2, saturation=0.2, hue=0.1), |
| 17 | transforms.RandomRotation(15), |
| 18 | transforms.ToTensor(), |
| 19 | transforms.Normalize(mean=mean, std=std), |
| 20 | transforms.RandomErasing(p=0.5, scale=(0.02, 0.33), ratio=(0.3, 3.3)) |
| 21 | ]) |
| 22 | else: |
| 23 | return transforms.Compose([ |
| 24 | transforms.Resize(int(image_size * 1.14)), |
| 25 | transforms.CenterCrop(image_size), |
| 26 | transforms.ToTensor(), |
| 27 | transforms.Normalize(mean=mean, std=std) |
| 28 | ]) |
| 29 | |
| 30 | class RandomMixup: |
| 31 | def __init__(self, alpha: float = 1.0): |
nothing calls this directly
no outgoing calls
no test coverage detected