MCPcopy Index your code
hub / github.com/whai362/PVT / evaluate

Function evaluate

classification/engine.py:71–100  ·  view source on GitHub ↗
(data_loader, model, device)

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.90

Calls 4

log_everyMethod · 0.95
updateMethod · 0.95
printFunction · 0.85

Tested by

no test coverage detected