(self, batch)
| 32 | self.alpha = alpha |
| 33 | |
| 34 | def __call__(self, batch): |
| 35 | if self.alpha > 0: |
| 36 | lam = torch.distributions.Beta(self.alpha, self.alpha).sample() |
| 37 | else: |
| 38 | lam = 1.0 |
| 39 | |
| 40 | batch_size = batch[0].size(0) |
| 41 | index = torch.randperm(batch_size) |
| 42 | |
| 43 | mixed_input = lam * batch[0] + (1 - lam) * batch[0][index, :] |
| 44 | y_a, y_b = batch[1], batch[1][index] |
| 45 | |
| 46 | return mixed_input, y_a, y_b, lam |
| 47 | |
| 48 | class RandomCutmix: |
| 49 | def __init__(self, alpha: float = 1.0): |