Skip to content

Commit

Permalink
openvino: choose better defaults for precision
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Jun 11, 2023
1 parent 19692d0 commit 1b5565b
Show file tree
Hide file tree
Showing 4 changed files with 39 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 @@ -40,5 +40,5 @@
"devDependencies": {
"@scrypted/sdk": "file:../../sdk"
},
"version": "0.1.22"
"version": "0.1.24"
}
40 changes: 35 additions & 5 deletions plugins/openvino/src/ov/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,28 @@ def __init__(self, nativeId: str | None = None):
available_devices = self.core.available_devices
print('available devices: %s' % available_devices)

xmlFile = self.downloadFile('https://raw.githubusercontent.com/koush/openvino-models/main/ssd_mobilenet_v1_coco/FP16/ssd_mobilenet_v1_coco.xml', 'ssd_mobilenet_v1_coco.xml')
mappingFile = self.downloadFile('https://raw.githubusercontent.com/koush/openvino-models/main/ssd_mobilenet_v1_coco/FP16/ssd_mobilenet_v1_coco.mapping', 'ssd_mobilenet_v1_coco.mapping')
labelsFile = self.downloadFile('https://raw.githubusercontent.com/koush/openvino-models/main/ssd_mobilenet_v1_coco/FP16/ssd_mobilenet_v1_coco.bin', 'ssd_mobilenet_v1_coco.bin')
mode = self.storage.getItem('mode')
if mode == 'Default':
mode = 'AUTO'
mode = mode or 'AUTO'

precision = self.storage.getItem('precision') or 'Default'
if precision == 'Default':
using_mode = mode
if using_mode == 'AUTO':
if 'GPU' in available_devices:
using_mode = 'GPU'
if using_mode == 'GPU':
precision = 'FP16'
else:
precision = 'FP32'

print(f'mode/precision: {mode}/{precision}')

xmlFile = self.downloadFile(f'https://raw.githubusercontent.com/koush/openvino-models/main/ssd_mobilenet_v1_coco/{precision}/ssd_mobilenet_v1_coco.xml', '{floating_point}/ssd_mobilenet_v1_coco.xml')
mappingFile = self.downloadFile(f'https://raw.githubusercontent.com/koush/openvino-models/main/ssd_mobilenet_v1_coco/{precision}/ssd_mobilenet_v1_coco.mapping', '{floating_point}/ssd_mobilenet_v1_coco.mapping')
labelsFile = self.downloadFile(f'https://raw.githubusercontent.com/koush/openvino-models/main/ssd_mobilenet_v1_coco/{precision}/ssd_mobilenet_v1_coco.bin', '{floating_point}/ssd_mobilenet_v1_coco.bin')

mode = self.storage.getItem('mode') or 'AUTO'
try:
self.compiled_model = self.core.compile_model(xmlFile, mode)
except:
Expand All @@ -57,18 +74,31 @@ 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]:
mode = self.storage.getItem('mode') or 'AUTO'
mode = self.storage.getItem('mode') or 'Default'
precision = self.storage.getItem('precision') or 'Default'
return [
{
'key': 'mode',
'title': 'Mode',
'description': 'AUTO, CPU, or GPU mode to use for detections. Requires plugin reload. Use CPU if the system has unreliable GPU drivers.',
'choices': [
'Default',
'AUTO',
'CPU',
'GPU',
],
'value': mode,
},
{
'key': 'precision',
'title': 'Precision',
'description': 'The model floating point precision. FP16 is recommended for GPU. FP32 is recommended for CPU.',
'choices': [
'Default',
'FP16',
'FP32',
],
'value': precision,
}
]

Expand Down
2 changes: 1 addition & 1 deletion plugins/tensorflow-lite/src/predict/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def downloadFile(self, url: str, filename: str):
fullpath = os.path.join(filesPath, filename)
if os.path.isfile(fullpath):
return fullpath
os.makedirs(filesPath, exist_ok=True)
os.makedirs(os.path.dirname(fullpath), exist_ok=True)
tmp = fullpath + '.tmp'
urllib.request.urlretrieve(url, tmp)
os.rename(tmp, fullpath)
Expand Down

0 comments on commit 1b5565b

Please sign in to comment.