MCPcopy
hub / github.com/pytorch/vision / evaluate

Function evaluate

references/detection/engine.py:76–115  ·  view source on GitHub ↗
(model, data_loader, device)

Source from the content-addressed store, hash-verified

74
75@torch.inference_mode()
76def evaluate(model, data_loader, device):
77 n_threads = torch.get_num_threads()
78 # FIXME remove this and make paste_masks_in_image run on the GPU
79 torch.set_num_threads(1)
80 cpu_device = torch.device("cpu")
81 model.eval()
82 metric_logger = utils.MetricLogger(delimiter=" ")
83 header = "Test:"
84
85 coco = get_coco_api_from_dataset(data_loader.dataset)
86 iou_types = _get_iou_types(model)
87 coco_evaluator = CocoEvaluator(coco, iou_types)
88
89 for images, targets in metric_logger.log_every(data_loader, 100, header):
90 images = list(img.to(device) for img in images)
91
92 if torch.cuda.is_available():
93 torch.cuda.synchronize()
94 model_time = time.time()
95 outputs = model(images)
96
97 outputs = [{k: v.to(cpu_device) for k, v in t.items()} for t in outputs]
98 model_time = time.time() - model_time
99
100 res = {target["image_id"]: output for target, output in zip(targets, outputs)}
101 evaluator_time = time.time()
102 coco_evaluator.update(res)
103 evaluator_time = time.time() - evaluator_time
104 metric_logger.update(model_time=model_time, evaluator_time=evaluator_time)
105
106 # gather the stats from all processes
107 metric_logger.synchronize_between_processes()
108 print("Averaged stats:", metric_logger)
109 coco_evaluator.synchronize_between_processes()
110
111 # accumulate predictions from all images
112 coco_evaluator.accumulate()
113 coco_evaluator.summarize()
114 torch.set_num_threads(n_threads)
115 return coco_evaluator

Callers 1

mainFunction · 0.90

Calls 13

log_everyMethod · 0.95
updateMethod · 0.95
updateMethod · 0.95
accumulateMethod · 0.95
summarizeMethod · 0.95
CocoEvaluatorClass · 0.90
_get_iou_typesFunction · 0.85
deviceMethod · 0.80
toMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…