@@ -135,26 +135,22 @@ def batch_detection(
135
135
136
136
class InlineDetectionPredictor (DetectionPredictor ):
137
137
model_loader_cls = InlineDetectionModelLoader
138
-
139
- def batch_generator (self , iterable , batch_size = None ):
140
- if batch_size is None :
141
- batch_size = self .get_batch_size ()
142
-
143
- for i in range (0 , len (iterable ), batch_size ):
144
- yield iterable [i :i + batch_size ]
145
138
146
139
def __call__ (self , images , text_boxes : List [List [List [float ]]], batch_size = None , include_maps = False ) -> List [TextDetectionResult ]:
147
140
detection_generator = self .batch_detection (images , batch_size = batch_size , static_cache = settings .DETECTOR_STATIC_CACHE )
148
- text_box_generator = self .batch_generator (text_boxes , batch_size = batch_size )
149
141
150
142
postprocessing_futures = []
151
143
max_workers = min (settings .DETECTOR_POSTPROCESSING_CPU_WORKERS , len (images ))
152
144
parallelize = not settings .IN_STREAMLIT and len (images ) >= settings .DETECTOR_MIN_PARALLEL_THRESH
153
145
executor = ThreadPoolExecutor if parallelize else FakeExecutor
146
+
147
+ image_idx = 0
154
148
with executor (max_workers = max_workers ) as e :
155
- for (preds , orig_sizes ), batch_text_boxes in zip (detection_generator , text_box_generator ):
156
- for pred , orig_size , image_text_boxes in zip (preds , orig_sizes , batch_text_boxes ):
157
- postprocessing_futures .append (e .submit (parallel_get_inline_boxes , pred , orig_size , image_text_boxes , include_maps ))
149
+ for (preds , orig_sizes ) in detection_generator :
150
+ for pred , orig_size in zip (preds , orig_sizes ):
151
+ postprocessing_futures .append (e .submit (parallel_get_inline_boxes , pred , orig_size , text_boxes [image_idx ], include_maps ))
152
+ image_idx += 1
158
153
159
154
assert len (postprocessing_futures ) == len (images ) == len (text_boxes ) # Ensure we have a 1:1 mapping
155
+
160
156
return [future .result () for future in postprocessing_futures ]
0 commit comments