(input, target, alpha=1.0)
| 183 | |
| 184 | |
| 185 | def cutmix_data(input, target, alpha=1.0): |
| 186 | lam = np.random.beta(alpha, alpha) |
| 187 | rand_index = torch.randperm(input.size()[0]).cuda() |
| 188 | |
| 189 | target_a = target |
| 190 | target_b = target[rand_index] |
| 191 | |
| 192 | # generate mixed sample |
| 193 | bbx1, bby1, bbx2, bby2 = rand_bbox(input.size(), lam) |
| 194 | input[:, :, :, bbx1:bbx2, bby1:bby2] = input[rand_index, :, :, bbx1:bbx2, bby1:bby2] |
| 195 | # adjust lambda to exactly match pixel ratio |
| 196 | lam = 1 - ((bbx2 - bbx1) * (bby2 - bby1) / (input.size()[-1] * input.size()[-2])) |
| 197 | return input, target_a, target_b, lam |
| 198 | |
| 199 | |
| 200 | if __name__ == '__main__': |
nothing calls this directly
no test coverage detected