Skip to content

Commit

Permalink
Correct THROUGHPUT mode sort order
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
  • Loading branch information
glenn-jocher committed Mar 5, 2024
1 parent 1be6b7c commit f19995e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions ultralytics/nn/autobackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def __init__(
elif xml:
LOGGER.info(f"Loading {w} for OpenVINO inference...")
check_requirements("openvino>=2023.3")
import openvino as ov # noqa
import openvino as ov

core = ov.Core()
w = Path(w)
Expand Down Expand Up @@ -440,17 +440,19 @@ def forward(self, im, augment=False, visualize=False, embed=None):
im = im.cpu().numpy() # FP32

if self.inference_mode in {"THROUGHPUT", "CUMULATIVE_THROUGHPUT"}: # optimized for larger batch-sizes
results = [] # this list will be filled by the callback function
n = im.shape[0] # number of images in batch
results = [None] * n # preallocate list with None to match the number of images

Check warning on line 444 in ultralytics/nn/autobackend.py

View check run for this annotation

Codecov / codecov/patch

ultralytics/nn/autobackend.py#L443-L444

Added lines #L443 - L444 were not covered by tests

def callback(request, userdata):

Check warning on line 446 in ultralytics/nn/autobackend.py

View check run for this annotation

Codecov / codecov/patch

ultralytics/nn/autobackend.py#L446

Added line #L446 was not covered by tests
"""Callback function to handle the completion of an async inference request."""
results.append(request.results) # directly append the inference result to 'results'
"""Places result in preallocated list using userdata index."""
results[userdata] = request.results

Check warning on line 448 in ultralytics/nn/autobackend.py

View check run for this annotation

Codecov / codecov/patch

ultralytics/nn/autobackend.py#L448

Added line #L448 was not covered by tests

# Create AsyncInferQueue, set the callback and start asynchronous inference for each input image
async_queue = self.ov.runtime.AsyncInferQueue(self.ov_compiled_model)
async_queue.set_callback(callback)
for i, image in enumerate(im):
async_queue.start_async(inputs={self.input_name: image[None]}, userdata=i) # expand image to BCHW
for i in range(n):

Check warning on line 453 in ultralytics/nn/autobackend.py

View check run for this annotation

Codecov / codecov/patch

ultralytics/nn/autobackend.py#L451-L453

Added lines #L451 - L453 were not covered by tests
# Start async inference with userdata=i to specify the position in results list
async_queue.start_async(inputs={self.input_name: im[i : i + 1]}, userdata=i) # keep image as BCHW
async_queue.wait_all() # wait for all inference requests to complete
y = [list(r.values()) for r in results][0]

Check warning on line 457 in ultralytics/nn/autobackend.py

View check run for this annotation

Codecov / codecov/patch

ultralytics/nn/autobackend.py#L455-L457

Added lines #L455 - L457 were not covered by tests

Expand Down

0 comments on commit f19995e

Please sign in to comment.