| 10 | from torchvision.transforms import functional as F |
| 11 | |
| 12 | def 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 | |
| 33 | class Compose: |
| 34 | def __init__(self, transforms): |