MCPcopy Create free account
hub / github.com/lingeringlight/START / evaluate

Function evaluate

engine_dg.py:100–129  ·  view source on GitHub ↗
(data_loader, model, device, amp_autocast)

Source from the content-addressed store, hash-verified

98
99@torch.no_grad()
100def evaluate(data_loader, model, device, amp_autocast):
101 criterion = torch.nn.CrossEntropyLoss()
102
103 metric_logger = utils.MetricLogger(delimiter=" ")
104 header = 'Test:'
105
106 # switch to evaluation mode
107 model.eval()
108
109 for (images, target, _), _ in metric_logger.log_every(data_loader, 200, header):
110 images = images.to(device, non_blocking=True)
111
112 target = target.to(device, non_blocking=True)
113
114 with amp_autocast():
115 output = model(images)
116 loss = criterion(output, target)
117
118 acc1, acc5 = accuracy(output, target, topk=(1, 5))
119
120 batch_size = images.shape[0]
121 metric_logger.update(loss=loss.item())
122 metric_logger.meters['acc1'].update(acc1.item(), n=batch_size)
123 metric_logger.meters['acc5'].update(acc5.item(), n=batch_size)
124 # gather the stats from all processes
125 metric_logger.synchronize_between_processes()
126 print('* Acc@1 {top1.global_avg:.3f} Acc@5 {top5.global_avg:.3f} loss {losses.global_avg:.3f}'
127 .format(top1=metric_logger.acc1, top5=metric_logger.acc5, losses=metric_logger.loss))
128
129 return {k: meter.global_avg for k, meter in metric_logger.meters.items()}

Callers 2

mainFunction · 0.90
mainFunction · 0.90

Calls 4

log_everyMethod · 0.95
updateMethod · 0.95
printFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…