def train_epoch(self, train_queue, model, criterion, optimizer, device, epoch):
    expect(self._is_setup, 'trainer.setup should be called first')
    objs = utils.AverageMeter()
    top1 = utils.AverageMeter()
    top5 = utils.AverageMeter()
    model.train()
    for (step, (inputs, target)) in enumerate(train_queue):
        inputs = inputs.to(device)
        target = target.to(device)
        optimizer.zero_grad()
        if self.auxiliary_head:
            (logits, logits_aux) = model(inputs)
            loss = self._obj_loss(inputs, logits, target, model, add_evaluator_regularization=self.add_regularization)
            loss_aux = criterion(logits_aux, target)
            loss += (self.auxiliary_weight * loss_aux)
        else:
            logits = model(inputs)
            loss = self._obj_loss(inputs, logits, target, model, add_evaluator_regularization=self.add_regularization)
        loss.backward()
        if (isinstance(self.grad_clip, (int, float)) and (self.grad_clip > 0)):
            nn.utils.clip_grad_norm_(model.parameters(), self.grad_clip)
        optimizer.step()
        (prec1, prec5) = utils.accuracy(logits, target, topk=(1, 5))
        n = inputs.size(0)
        objs.update(loss.item(), n)
        top1.update(prec1.item(), n)
        top5.update(prec5.item(), n)
        del loss
        if ((step % self.report_every) == 0):
            self.logger.info('train %03d %.3f; %.2f%%; %.2f%%', step, objs.avg, top1.avg, top5.avg)
    return (top1.avg, objs.avg)
def train_epoch(self, train_queue, model, criterion, optimizer, device, epoch):
    expect(self._is_setup, 'trainer.setup should be called first')
    objs = utils.AverageMeter()
    top1 = utils.AverageMeter()
    top5 = utils.AverageMeter()
    model.train()
    for (step, (inputs, target)) in enumerate(train_queue):
        inputs = inputs.to(device)
        target = target.to(device)
        optimizer.zero_grad()
        if self.auxiliary_head:
            (logits, logits_aux) = model(inputs)
            loss = self._obj_loss(inputs, logits, target, model, add_evaluator_regularization=self.add_regularization)
            loss_aux = criterion(logits_aux, target)
            loss += (self.auxiliary_weight * loss_aux)
        else:
            logits = model(inputs)
            loss = self._obj_loss(inputs, logits, target, model, add_evaluator_regularization=self.add_regularization)
        loss.backward()
        if (isinstance(self.grad_clip, (int, float)) and (self.grad_clip > 0)):
            nn.utils.clip_grad_norm_(model.parameters(), self.grad_clip)
        optimizer.step()
        (prec1, prec5) = utils.accuracy(logits, target, topk=(1, 5))
        n = inputs.size(0)
        objs.update(loss.item(), n)
        top1.update(prec1.item(), n)
        top5.update(prec5.item(), n)
        del loss
        if ((step % self.report_every) == 0):
            self.logger.info('train %03d %.3f; %.2f%%; %.2f%%', step, objs.avg, top1.avg, top5.avg)
    return (top1.avg, objs.avg)