MCPcopy Create free account
hub / github.com/Kitware/COAT / mixup_data

Function mixup_data

utils/transforms.py:12–31  ·  view source on GitHub ↗
(images, alpha=0.8)

Source from the content-addressed store, hash-verified

10from torchvision.transforms import functional as F
11
12def mixup_data(images, alpha=0.8):
13 if alpha > 0. and alpha < 1.:
14 lam = random.uniform(alpha, 1)
15 else:
16 lam = 1.
17
18 batch_size = len(images)
19 min_x = 9999
20 min_y = 9999
21 for i in range(batch_size):
22 min_x = min(min_x, images[i].shape[1])
23 min_y = min(min_y, images[i].shape[2])
24
25 shuffle_images = deepcopy(images)
26 random.shuffle(shuffle_images)
27 mixed_images = deepcopy(images)
28 for i in range(batch_size):
29 mixed_images[i][:, :min_x, :min_y] = lam * images[i][:, :min_x, :min_y] + (1 - lam) * shuffle_images[i][:, :min_x, :min_y]
30
31 return mixed_images
32
33class Compose:
34 def __init__(self, transforms):

Callers 1

train_one_epochFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected