Skip to content

Commit

Permalink
openvino: use builtin async, log execution unit
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Sep 26, 2023
1 parent 8b7decd commit f9dda8d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions plugins/openvino/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/openvino/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@
"devDependencies": {
"@scrypted/sdk": "file:../../sdk"
},
"version": "0.1.42"
"version": "0.1.43"
}
9 changes: 3 additions & 6 deletions plugins/openvino/src/ov/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

import asyncio
import concurrent.futures
import json
import re
from typing import Any, Tuple
Expand Down Expand Up @@ -96,6 +94,7 @@ def __init__(self, nativeId: str | None = None):

try:
self.compiled_model = self.core.compile_model(xmlFile, mode)
print("EXECUTION_DEVICES", self.compiled_model.get_property("EXECUTION_DEVICES"))
except:
import traceback
traceback.print_exc()
Expand All @@ -114,8 +113,6 @@ def __init__(self, nativeId: str | None = None):
labels_contents = open(labelsFile, 'r').read()
self.labels = parse_label_contents(labels_contents)

self.executor = concurrent.futures.ThreadPoolExecutor(max_workers=1, thread_name_prefix="openvino", )

async def getSettings(self) -> list[Setting]:
mode = self.storage.getItem('mode') or 'Default'
model = self.storage.getItem('model') or 'Default'
Expand Down Expand Up @@ -181,7 +178,7 @@ def get_input_size(self) -> Tuple[int, int]:
return [self.model_dim, self.model_dim]

async def detect_once(self, input: Image.Image, settings: Any, src_size, cvss):
def predict():
async def predict():
infer_request = self.compiled_model.create_infer_request()
# the input_tensor can be created with the shared_memory=True parameter,
# but that seems to cause issues on some platforms.
Expand Down Expand Up @@ -259,7 +256,7 @@ def torelative(value: float):
return objs

try:
objs = await asyncio.get_event_loop().run_in_executor(self.executor, predict)
objs = await predict()
except:
import traceback
traceback.print_exc()
Expand Down

0 comments on commit f9dda8d

Please sign in to comment.