66import torchvision
77from sotabenchapi .check import in_check_mode
88from sotabenchapi .client import Client
9+ import time
910
1011from pycocotools import mask as coco_mask
1112from pycocotools .coco import COCO
1213
13- from torchbench .utils import calculate_run_hash
14+ from torchbench .utils import calculate_run_hash , AverageMeter
1415from torchbench .datasets import CocoDetection
1516
1617from .coco_eval import CocoEvaluator
@@ -198,20 +199,28 @@ def evaluate_detection_coco(
198199 iou_types = ['bbox' ]
199200 coco_evaluator = CocoEvaluator (coco , iou_types )
200201
202+ inference_time = AverageMeter ()
203+
201204 iterator = tqdm .tqdm (test_loader , desc = "Evaluation" , mininterval = 5 )
202205
206+ end = time .time ()
207+
203208 with torch .no_grad ():
204209 for i , (input , target ) in enumerate (iterator ):
205210 input , target = send_data_to_device (input , target , device = device )
206211 original_output = model (input )
212+
213+ inference_time .update (time .time () - end )
214+
207215 output , target = model_output_transform (original_output , target )
216+
208217 result = {
209218 tar ["image_id" ].item (): out for tar , out in zip (target , output )
210219 }
211220 coco_evaluator .update (result )
212221
213-
214222 if i == 0 : # for sotabench.com caching of evaluation
223+ memory_allocated = torch .cuda .memory_allocated (device = device )
215224 run_hash = calculate_run_hash ([], original_output )
216225 # if we are in check model we don't need to go beyond the first
217226 # batch
@@ -230,11 +239,17 @@ def evaluate_detection_coco(
230239 )
231240 return cached_res , run_hash
232241
242+ end = time .time ()
243+
233244 coco_evaluator .synchronize_between_processes ()
234245 coco_evaluator .accumulate ()
235246 coco_evaluator .summarize ()
236247
237- return (get_coco_metrics (coco_evaluator ), run_hash )
248+ device_metrics = {
249+ 'Tasks Per Second' : test_loader .batch_size / inference_time .avg ,
250+ 'Memory Allocated' : memory_allocated }
251+
252+ return (get_coco_metrics (coco_evaluator ), device_metrics , run_hash )
238253
239254
240255def evaluate_detection_voc (
0 commit comments