MCPcopy Create free account
hub / github.com/geekcomputers/Python / get_transforms

Function get_transforms

ML/src/python/neuralforge/data/transforms.py:5–28  ·  view source on GitHub ↗
(image_size: int = 224, is_training: bool = True, mean=None, std=None)

Source from the content-addressed store, hash-verified

3from typing import List, Tuple
4
5def 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
30class RandomMixup:
31 def __init__(self, alpha: float = 1.0):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected