def process_train(self, *args): super(MixupAcc, self).process_train(*args) state = args[0] target1, target2 = state[torchbearer.Y_TRUE] _state = args[0].copy() _state[torchbearer.Y_TRUE] = target1 acc1 = self.cat_acc.process(_state) _state = args[0].copy() _state[torchbearer.Y_TRUE] = target2 acc2 = self.cat_acc.process(_state) return acc1 * state[torchbearer.MIXUP_LAMBDA] + acc2 * ( 1 - state[torchbearer.MIXUP_LAMBDA])
def __init__(self, alpha=1.0, lam=RANDOM): super(Mixup, self).__init__() self.alpha = alpha self.lam = lam self.distrib = Beta(self.alpha, self.alpha)
def process_validate(self, *args): super(MixupAcc, self).process_validate(*args) return self.cat_acc.process(*args)
def __init__(self): super(MixupAcc, self).__init__('mixup_acc') self.cat_acc = CategoricalAccuracy().root