def infer_epoch(self, valid_queue, model, criterion, device):
    expect(self._is_setup, 'trainer.setup should be called first')
    objs = utils.AverageMeter()
    top1 = utils.AverageMeter()
    top5 = utils.AverageMeter()
    objective_perfs = utils.OrderedStats()
    all_perfs = []
    model.eval()
    context = (torch.no_grad if self.eval_no_grad else nullcontext)
    with context():
        for (step, (inputs, target)) in enumerate(valid_queue):
            inputs = inputs.to(device)
            target = target.to(device)
            logits = model(inputs)
            loss = criterion(logits, target)
            perfs = self._perf_func(inputs, logits, target, model)
            all_perfs.append(perfs)
            (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):
                all_perfs_by_name = list(zip(*all_perfs))
                obj_perfs = {k: self.objective.aggregate_fn(k, False)(v) for (k, v) in zip(self._perf_names, all_perfs_by_name)}
                self.logger.info('valid %03d %e %f %f %s', step, objs.avg, top1.avg, top5.avg, '; '.join(['{}: {:.3f}'.format(perf_n, v) for (perf_n, v) in obj_perfs.items()]))
    all_perfs_by_name = list(zip(*all_perfs))
    obj_perfs = {k: self.objective.aggregate_fn(k, False)(v) for (k, v) in zip(self._perf_names, all_perfs_by_name)}
    return (top1.avg, objs.avg, obj_perfs)
def infer_epoch(self, valid_queue, model, criterion, device):
    expect(self._is_setup, 'trainer.setup should be called first')
    objs = utils.AverageMeter()
    top1 = utils.AverageMeter()
    top5 = utils.AverageMeter()
    objective_perfs = utils.OrderedStats()
    all_perfs = []
    model.eval()
    context = (torch.no_grad if self.eval_no_grad else nullcontext)
    with context():
        for (step, (inputs, target)) in enumerate(valid_queue):
            inputs = inputs.to(device)
            target = target.to(device)
            logits = model(inputs)
            loss = criterion(logits, target)
            perfs = self._perf_func(inputs, logits, target, model)
            all_perfs.append(perfs)
            (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):
                all_perfs_by_name = list(zip(*all_perfs))
                obj_perfs = {k: self.objective.aggregate_fn(k, False)(v) for (k, v) in zip(self._perf_names, all_perfs_by_name)}
                self.logger.info('valid %03d %e %f %f %s', step, objs.avg, top1.avg, top5.avg, '; '.join(['{}: {:.3f}'.format(perf_n, v) for (perf_n, v) in obj_perfs.items()]))
    all_perfs_by_name = list(zip(*all_perfs))
    obj_perfs = {k: self.objective.aggregate_fn(k, False)(v) for (k, v) in zip(self._perf_names, all_perfs_by_name)}
    return (top1.avg, objs.avg, obj_perfs)