(self, minibatches, unlabeled=None)
| 416 | super(Mixup, self).__init__(input_shape, num_classes, num_domains, hparams) |
| 417 | |
| 418 | def update(self, minibatches, unlabeled=None): |
| 419 | objective = 0 |
| 420 | |
| 421 | for (xi, yi), (xj, yj) in random_pairs_of_minibatches(minibatches): |
| 422 | lam = np.random.beta(self.hparams["mixup_alpha"], self.hparams["mixup_alpha"]) |
| 423 | |
| 424 | x = lam * xi + (1 - lam) * xj |
| 425 | predictions = self.predict(x) |
| 426 | |
| 427 | objective += lam * F.cross_entropy(predictions, yi) |
| 428 | objective += (1 - lam) * F.cross_entropy(predictions, yj) |
| 429 | |
| 430 | objective /= len(minibatches) |
| 431 | |
| 432 | self.optimizer.zero_grad() |
| 433 | objective.backward() |
| 434 | self.optimizer.step() |
| 435 | |
| 436 | return {'loss': objective.item()} |
| 437 | |
| 438 | |
| 439 | class GroupDRO(ERM): |
nothing calls this directly
no test coverage detected