MCPcopy Create free account
hub / github.com/alexrame/fishr / update

Method update

domainbed/algorithms.py:418–436  ·  view source on GitHub ↗
(self, minibatches, unlabeled=None)

Source from the content-addressed store, hash-verified

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
439class GroupDRO(ERM):

Callers

nothing calls this directly

Calls 2

predictMethod · 0.45

Tested by

no test coverage detected