@@ -97,30 +97,40 @@ def run_pytorch_fp(model_path, batch_size, num_runs, timeout, images_path, anno_
9797 # Ultralytics sets it to True by default. This way we suppress the logging by default while still allowing the user
9898 # to set it to True if needed
9999 from utils .pytorch import PyTorchRunner
100- from ultralytics .utils .nms import non_max_suppression
101100
102101 def run_single_pass (pytorch_runner , coco ):
103102 shape = (640 , 640 )
104- inp = torch .stack (coco .get_input_array (shape ))
105- output = pytorch_runner .run (batch_size , inp )
106- output = non_max_suppression (output )
103+ dset = coco .get_input_array (shape )
104+ outputs = []
105+ for inp in dset :
106+ output , * _ = pytorch_runner .run (1 , inp )
107+ outputs .append (output )
108+ assert len (outputs ) == batch_size
107109
108110 for i in range (batch_size ):
109- for d in range (output [i ].shape [0 ]):
111+ for b in range (len (outputs [i ].boxes )):
112+ bbox = outputs [i ].boxes .xywh [b ]
113+ cls = int (outputs [i ].boxes .cls [b ])
110114 coco .submit_bbox_prediction (
111115 i ,
112- coco .convert_bbox_to_coco_order (output [ i ][ d ][: 4 ]. tolist () ),
113- output [ i ][ d ][ 4 ]. item () ,
114- coco .translate_cat_id_to_coco (output [ i ][ d ][ 5 ]. item () )
116+ coco .convert_bbox_to_coco_order (bbox ),
117+ cls ,
118+ coco .translate_cat_id_to_coco (cls )
115119 )
116120
117121 dataset = COCODataset (batch_size , "RGB" , "COCO_val2014_000000000000" , images_path ,
118122 anno_path , pre_processing = "PyTorch_objdet" , sort_ascending = True , order = "NCHW" )
119123
120124 from ultralytics import YOLO
125+ import numpy as np
121126 model = YOLO (model_path )
122127
123- runner = PyTorchRunner (model .model ,
128+ # make sure that model.predictor exists
129+ dummy_input = np .zeros ((640 , 640 , 3 ), dtype = np .uint8 )
130+ model .predict (dummy_input )
131+ assert model .predictor is not None
132+
133+ runner = PyTorchRunner (model ,
124134 disable_jit_freeze = disable_jit_freeze ,
125135 example_inputs = torch .stack (dataset .get_input_array ((640 , 640 ))))
126136
0 commit comments