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

Function evaluate

event/train.py:277–300  ·  view source on GitHub ↗
(model, criterion, data_loader, device, print_freq=100, header='Test:')

Source from the content-addressed store, hash-verified

275
276
277def evaluate(model, criterion, data_loader, device, print_freq=100, header='Test:'):
278 model.eval()
279 metric_logger = utils.MetricLogger(delimiter=" ")
280 with torch.no_grad():
281 for image, target in metric_logger.log_every(data_loader, print_freq, header):
282 image = image.to(device, non_blocking=True)
283 target = target.to(device, non_blocking=True)
284 image = image.float()
285 output = model(image)
286
287 loss = criterion(output, target)
288 functional.reset_net(model)
289
290 acc1, acc5 = utils.accuracy(output, target, topk=(1, 5))
291 batch_size = image.shape[0]
292 metric_logger.update(loss=loss.item())
293 metric_logger.meters['acc1'].update(acc1.item(), n=batch_size)
294 metric_logger.meters['acc5'].update(acc5.item(), n=batch_size)
295 # gather the stats from all processes
296 metric_logger.synchronize_between_processes()
297
298 loss, acc1, acc5 = metric_logger.loss.global_avg, metric_logger.acc1.global_avg, metric_logger.acc5.global_avg
299 print(f' * Acc@1 = {acc1}, Acc@5 = {acc5}, loss = {loss}')
300 return loss, acc1, acc5
301
302
303def load_data(dataset, dataset_dir, distributed, T):

Callers 1

mainFunction · 0.70

Calls 4

log_everyMethod · 0.95
updateMethod · 0.95
printFunction · 0.70

Tested by

no test coverage detected