MCPcopy Index your code
hub / github.com/microsoft/Cream / evaluate

Function evaluate

EfficientViT/classification/engine.py:77–106  ·  view source on GitHub ↗
(data_loader, model, device)

Source from the content-addressed store, hash-verified

75
76@torch.no_grad()
77def evaluate(data_loader, model, device):
78 criterion = torch.nn.CrossEntropyLoss()
79
80 metric_logger = utils.MetricLogger(delimiter=" ")
81 header = 'Test:'
82
83 # switch to evaluation mode
84 model.eval()
85
86 for images, target in metric_logger.log_every(data_loader, 10, header):
87 images = images.to(device, non_blocking=True)
88 target = target.to(device, non_blocking=True)
89
90 # compute output
91 with torch.cuda.amp.autocast():
92 output = model(images)
93 loss = criterion(output, target)
94
95 acc1, acc5 = accuracy(output, target, topk=(1, 5))
96
97 batch_size = images.shape[0]
98 metric_logger.update(loss=loss.item())
99 metric_logger.meters['acc1'].update(acc1.item(), n=batch_size)
100 metric_logger.meters['acc5'].update(acc5.item(), n=batch_size)
101 # gather the stats from all processes
102 metric_logger.synchronize_between_processes()
103 print('* Acc@1 {top1.global_avg:.3f} Acc@5 {top5.global_avg:.3f} loss {losses.global_avg:.3f}'
104 .format(top1=metric_logger.acc1, top5=metric_logger.acc5, losses=metric_logger.loss))
105
106 return {k: meter.global_avg for k, meter in metric_logger.meters.items()}

Callers 1

mainFunction · 0.90

Calls 7

log_everyMethod · 0.95
updateMethod · 0.95
accuracyFunction · 0.90
toMethod · 0.80
formatMethod · 0.80
printFunction · 0.70

Tested by

no test coverage detected