Skip to content

Commit 6ed9e7b

Browse files
authored
Add device selection for Surya notebook (#1740)
1 parent 7347121 commit 6ed9e7b

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

notebooks/285-surya-line-level-text-detection/285-surya-line-level-text-detection.ipynb

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,45 @@
227227
"metadata": {},
228228
"source": [
229229
"## Run OpenVINO model\n",
230-
"[back to top ⬆️](#Table-of-contents:)"
230+
"[back to top ⬆️](#Table-of-contents:)\n",
231+
"\n",
232+
"Select device from dropdown list for running inference using OpenVINO"
233+
]
234+
},
235+
{
236+
"cell_type": "code",
237+
"execution_count": 7,
238+
"metadata": {},
239+
"outputs": [
240+
{
241+
"data": {
242+
"application/vnd.jupyter.widget-view+json": {
243+
"model_id": "a56d78fc8ba3470cbcca4840e8f05caa",
244+
"version_major": 2,
245+
"version_minor": 0
246+
},
247+
"text/plain": [
248+
"Dropdown(description='Device:', index=1, options=('CPU', 'AUTO'), value='AUTO')"
249+
]
250+
},
251+
"execution_count": 7,
252+
"metadata": {},
253+
"output_type": "execute_result"
254+
}
255+
],
256+
"source": [
257+
"import ipywidgets as widgets\n",
258+
"\n",
259+
"core = ov.Core()\n",
260+
"\n",
261+
"device = widgets.Dropdown(\n",
262+
" options=core.available_devices + [\"AUTO\"],\n",
263+
" value='AUTO',\n",
264+
" description='Device:',\n",
265+
" disabled=False,\n",
266+
")\n",
267+
"\n",
268+
"device"
231269
]
232270
},
233271
{
@@ -239,7 +277,7 @@
239277
},
240278
{
241279
"cell_type": "code",
242-
"execution_count": 7,
280+
"execution_count": 9,
243281
"metadata": {
244282
"id": "t_hOCui8YzZz"
245283
},
@@ -248,7 +286,7 @@
248286
"core = ov.Core()\n",
249287
"\n",
250288
"# Compile OpenVINO model for loading on device\n",
251-
"compiled_ov_model = core.compile_model(ov_model, \"CPU\")\n",
289+
"compiled_ov_model = core.compile_model(ov_model, device.value)\n",
252290
"\n",
253291
"\n",
254292
"class OVModelWrapperResult:\n",
@@ -258,7 +296,7 @@
258296
"\n",
259297
"class OVModelWrapper:\n",
260298
" dtype = torch.float32\n",
261-
" device = \"cpu\"\n",
299+
" device = model.device\n",
262300
"\n",
263301
" def __call__(self, **kwargs):\n",
264302
" # obtain output tensor for getting predictions\n",
@@ -275,7 +313,7 @@
275313
},
276314
{
277315
"cell_type": "code",
278-
"execution_count": 8,
316+
"execution_count": 10,
279317
"metadata": {
280318
"id": "5EuBpVt-aRcy"
281319
},

0 commit comments

Comments
 (0)