MCPcopy Create free account
hub / github.com/bic-L/MaxFormer / evaluate

Function evaluate

imagenet/utils.py:240–272  ·  view source on GitHub ↗
(data_loader, model, device)

Source from the content-addressed store, hash-verified

238
239@torch.no_grad()
240def evaluate(data_loader, model, device):
241 criterion = torch.nn.CrossEntropyLoss()
242
243 metric_logger = misc.MetricLogger(delimiter=" ")
244 header = 'Test:'
245
246 # switch to evaluation mode
247 model.eval()
248
249 for batch in metric_logger.log_every(data_loader, 500, header):
250 images = batch[0]
251 target = batch[-1]
252 images = images.to(device, non_blocking=True)
253 target = target.to(device, non_blocking=True)
254
255 # compute output
256 with torch.cuda.amp.autocast():
257 output = model(images)
258 loss = criterion(output, target)
259
260 acc1, acc5 = accuracy(output, target, topk=(1, 5))
261 functional.reset_net(model)
262
263 batch_size = images.shape[0]
264 metric_logger.update(loss=loss.item())
265 metric_logger.meters['acc1'].update(acc1.item(), n=batch_size)
266 metric_logger.meters['acc5'].update(acc5.item(), n=batch_size)
267 # gather the stats from all processes
268 metric_logger.synchronize_between_processes()
269 print('* Acc@1 {top1.global_avg:.3f} Acc@5 {top5.global_avg:.3f} loss {losses.global_avg:.3f}'
270 .format(top1=metric_logger.acc1, top5=metric_logger.acc5, losses=metric_logger.loss))
271
272 return {k: meter.global_avg for k, meter in metric_logger.meters.items()}

Callers 2

mainFunction · 0.90
mainFunction · 0.90

Calls 5

log_everyMethod · 0.95
updateMethod · 0.95
accuracyFunction · 0.90
printFunction · 0.70

Tested by 1

mainFunction · 0.72