Skip to content

Commit 350672e

Browse files
authored
reuse device widget (openvinotoolkit#2312)
1 parent eb75851 commit 350672e

File tree

67 files changed

+266
-802
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+266
-802
lines changed

.ci/patch_notebooks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
EXCLUDED_NOTEBOOKS = ["data-preparation-ct-scan.ipynb", "pytorch-monai-training.ipynb"]
1111

1212
DEVICE_WIDGET = "device = widgets.Dropdown("
13-
DEVICE_WIDGET_NEW = "device = device_widget("
13+
DEVICE_WIDGET_NEW = "device_widget("
1414

1515

1616
def disable_gradio_debug(nb, notebook_path):

notebooks/3D-pose-estimation-webcam/3D-pose-estimation.ipynb

+1-8
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,7 @@
212212
"metadata": {},
213213
"outputs": [],
214214
"source": [
215-
"core = ov.Core()\n",
216-
"\n",
217-
"device = widgets.Dropdown(\n",
218-
" options=core.available_devices + [\"AUTO\"],\n",
219-
" value=\"AUTO\",\n",
220-
" description=\"Device:\",\n",
221-
" disabled=False,\n",
222-
")\n",
215+
"device = utils.device_widget()\n",
223216
"\n",
224217
"device"
225218
]

notebooks/3D-segmentation-point-clouds/3D-segmentation-point-clouds.ipynb

+2-9
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
")\n",
8080
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
8181
"\n",
82-
"from notebook_utils import download_file"
82+
"from notebook_utils import download_file, device_widget"
8383
]
8484
},
8585
{
@@ -338,14 +338,7 @@
338338
}
339339
],
340340
"source": [
341-
"import ipywidgets as widgets\n",
342-
"\n",
343-
"device = widgets.Dropdown(\n",
344-
" options=core.available_devices + [\"AUTO\"],\n",
345-
" value=\"AUTO\",\n",
346-
" description=\"Device:\",\n",
347-
" disabled=False,\n",
348-
")\n",
341+
"device = device_widget()\n",
349342
"\n",
350343
"device"
351344
]

notebooks/action-recognition-webcam/action-recognition-webcam.ipynb

+1-9
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,7 @@
218218
"metadata": {},
219219
"outputs": [],
220220
"source": [
221-
"import ipywidgets as widgets\n",
222-
"\n",
223-
"core = ov.Core()\n",
224-
"device = widgets.Dropdown(\n",
225-
" options=core.available_devices + [\"AUTO\"],\n",
226-
" value=\"AUTO\",\n",
227-
" description=\"Device:\",\n",
228-
" disabled=False,\n",
229-
")\n",
221+
"device = utils.device_widget()\n",
230222
"\n",
231223
"device"
232224
]

notebooks/async-api/async-api.ipynb

+1-9
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,7 @@
164164
}
165165
],
166166
"source": [
167-
"import ipywidgets as widgets\n",
168-
"\n",
169-
"core = ov.Core()\n",
170-
"device = widgets.Dropdown(\n",
171-
" options=core.available_devices + [\"AUTO\"],\n",
172-
" value=\"CPU\",\n",
173-
" description=\"Device:\",\n",
174-
" disabled=False,\n",
175-
")\n",
167+
"device = utils.device_widget(default=\"CPU\")\n",
176168
"\n",
177169
"device"
178170
]

notebooks/blip-visual-language-processing/blip-visual-language-processing.ipynb

+5-14
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@
201201
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
202202
")\n",
203203
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
204-
"from notebook_utils import download_file\n",
204+
"from notebook_utils import download_file, device_widget, quantization_widget\n",
205205
"\n",
206206
"# get model and processor\n",
207207
"processor = BlipProcessor.from_pretrained(\"Salesforce/blip-vqa-base\")\n",
@@ -571,14 +571,7 @@
571571
}
572572
],
573573
"source": [
574-
"import ipywidgets as widgets\n",
575-
"\n",
576-
"device = widgets.Dropdown(\n",
577-
" options=core.available_devices + [\"AUTO\"],\n",
578-
" value=\"AUTO\",\n",
579-
" description=\"Device:\",\n",
580-
" disabled=False,\n",
581-
")\n",
574+
"device = device_widget()\n",
582575
"\n",
583576
"device"
584577
]
@@ -781,11 +774,7 @@
781774
}
782775
],
783776
"source": [
784-
"to_quantize = widgets.Checkbox(\n",
785-
" value=True,\n",
786-
" description=\"Quantization\",\n",
787-
" disabled=False,\n",
788-
")\n",
777+
"to_quantize = quantization_widget()\n",
789778
"\n",
790779
"to_quantize"
791780
]
@@ -1723,6 +1712,8 @@
17231712
}
17241713
],
17251714
"source": [
1715+
"import ipywidgets as widgets\n",
1716+
"\n",
17261717
"use_quantized_model = widgets.Checkbox(\n",
17271718
" description=\"Use quantized model\",\n",
17281719
" value=int8_model is not None,\n",

notebooks/ct-segmentation-quantize/ct-segmentation-quantize-nncf.ipynb

+2-10
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
"# Fetch `notebook_utils` module\n",
130130
"r = requests.get(url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\")\n",
131131
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
132-
"from notebook_utils import download_file\n",
132+
"from notebook_utils import download_file, device_widget\n",
133133
"\n",
134134
"if not Path(\"./custom_segmentation.py\").exists():\n",
135135
" download_file(url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/notebooks/ct-segmentation-quantize/custom_segmentation.py\")\n",
@@ -775,15 +775,7 @@
775775
"# By default, benchmark on MULTI:CPU,GPU if a GPU is available, otherwise on CPU.\n",
776776
"device_list = [\"MULTI:CPU,GPU\" if \"GPU\" in core.available_devices else \"AUTO\"]\n",
777777
"\n",
778-
"import ipywidgets as widgets\n",
779-
"\n",
780-
"device = widgets.Dropdown(\n",
781-
" options=core.available_devices + device_list,\n",
782-
" value=device_list[0],\n",
783-
" description=\"Device:\",\n",
784-
" disabled=False,\n",
785-
")\n",
786-
"\n",
778+
"device = device_widget(device_list[0], added=device_list)\n",
787779
"device"
788780
]
789781
},

notebooks/depth-anything/depth-anything-v2.ipynb

+7-16
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
")\n",
179179
"\n",
180180
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
181-
"from notebook_utils import download_file\n",
181+
"from notebook_utils import download_file, device_widget, quantization_widget\n",
182182
"\n",
183183
"download_file(\n",
184184
" \"https://github.com/openvinotoolkit/openvino_notebooks/assets/29454499/3f779fc1-c1b2-4dec-915a-64dae510a2bb\",\n",
@@ -383,16 +383,7 @@
383383
}
384384
],
385385
"source": [
386-
"import ipywidgets as widgets\n",
387-
"\n",
388-
"core = ov.Core()\n",
389-
"\n",
390-
"device = widgets.Dropdown(\n",
391-
" options=core.available_devices + [\"AUTO\"],\n",
392-
" value=\"AUTO\",\n",
393-
" description=\"Device:\",\n",
394-
" disabled=False,\n",
395-
")\n",
386+
"device = device_widget()\n",
396387
"\n",
397388
"device"
398389
]
@@ -404,6 +395,8 @@
404395
"metadata": {},
405396
"outputs": [],
406397
"source": [
398+
"core = ov.Core()\n",
399+
"\n",
407400
"compiled_model = core.compile_model(OV_DEPTH_ANYTHING_PATH, device.value)"
408401
]
409402
},
@@ -878,11 +871,7 @@
878871
}
879872
],
880873
"source": [
881-
"to_quantize = widgets.Checkbox(\n",
882-
" value=True,\n",
883-
" description=\"Quantization\",\n",
884-
" disabled=False,\n",
885-
")\n",
874+
"to_quantize = quantization_widget()\n",
886875
"\n",
887876
"to_quantize"
888877
]
@@ -1426,6 +1415,8 @@
14261415
}
14271416
],
14281417
"source": [
1418+
"import ipywidgets as widgets\n",
1419+
"\n",
14291420
"quantized_model_present = OV_DEPTH_ANYTHING_INT8_PATH.exists()\n",
14301421
"\n",
14311422
"use_quantized_model = widgets.Checkbox(\n",

notebooks/depth-anything/depth-anything.ipynb

+6-17
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@
201201
")\n",
202202
"\n",
203203
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
204-
"from notebook_utils import download_file\n",
204+
"from notebook_utils import download_file, device_widget, quantization_widget\n",
205205
"\n",
206206
"download_file(\n",
207207
" \"https://github.com/openvinotoolkit/openvino_notebooks/assets/29454499/3f779fc1-c1b2-4dec-915a-64dae510a2bb\",\n",
@@ -395,17 +395,7 @@
395395
}
396396
],
397397
"source": [
398-
"import ipywidgets as widgets\n",
399-
"\n",
400-
"core = ov.Core()\n",
401-
"\n",
402-
"device = widgets.Dropdown(\n",
403-
" options=core.available_devices + [\"AUTO\"],\n",
404-
" value=\"AUTO\",\n",
405-
" description=\"Device:\",\n",
406-
" disabled=False,\n",
407-
")\n",
408-
"\n",
398+
"device = device_widget()\n",
409399
"device"
410400
]
411401
},
@@ -416,6 +406,7 @@
416406
"metadata": {},
417407
"outputs": [],
418408
"source": [
409+
"core = ov.Core()\n",
419410
"compiled_model = core.compile_model(OV_DEPTH_ANYTHING_PATH, device.value)"
420411
]
421412
},
@@ -849,11 +840,7 @@
849840
}
850841
],
851842
"source": [
852-
"to_quantize = widgets.Checkbox(\n",
853-
" value=True,\n",
854-
" description=\"Quantization\",\n",
855-
" disabled=False,\n",
856-
")\n",
843+
"to_quantize = quantization_widget()\n",
857844
"\n",
858845
"to_quantize"
859846
]
@@ -1210,6 +1197,8 @@
12101197
"metadata": {},
12111198
"outputs": [],
12121199
"source": [
1200+
"import ipywidgets as widgets\n",
1201+
"\n",
12131202
"quantized_model_present = OV_DEPTH_ANYTHING_INT8_PATH.exists()\n",
12141203
"\n",
12151204
"use_quantized_model = widgets.Checkbox(\n",

notebooks/distilbert-sequence-classification/distilbert-sequence-classification.ipynb

+19-18
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,24 @@
7070
"import openvino as ov"
7171
]
7272
},
73+
{
74+
"cell_type": "code",
75+
"execution_count": null,
76+
"id": "7325aad7",
77+
"metadata": {},
78+
"outputs": [],
79+
"source": [
80+
"# Fetch `notebook_utils` module\n",
81+
"import requests\n",
82+
"\n",
83+
"r = requests.get(\n",
84+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
85+
")\n",
86+
"\n",
87+
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
88+
"from notebook_utils import download_file, device_widget"
89+
]
90+
},
7391
{
7492
"attachments": {},
7593
"cell_type": "markdown",
@@ -215,14 +233,7 @@
215233
}
216234
],
217235
"source": [
218-
"import ipywidgets as widgets\n",
219-
"\n",
220-
"device = widgets.Dropdown(\n",
221-
" options=core.available_devices + [\"AUTO\"],\n",
222-
" value=\"AUTO\",\n",
223-
" description=\"Device:\",\n",
224-
" disabled=False,\n",
225-
")\n",
236+
"device = device_widget()\n",
226237
"\n",
227238
"device"
228239
]
@@ -357,16 +368,6 @@
357368
"metadata": {},
358369
"outputs": [],
359370
"source": [
360-
"# Fetch `notebook_utils` module\n",
361-
"import requests\n",
362-
"\n",
363-
"r = requests.get(\n",
364-
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
365-
")\n",
366-
"\n",
367-
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
368-
"from notebook_utils import download_file\n",
369-
"\n",
370371
"# Download the text from the openvino_notebooks storage\n",
371372
"vocab_file_path = download_file(\n",
372373
" \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/text/food_reviews.txt\",\n",

notebooks/efficient-sam/efficient-sam.ipynb

+20-19
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,24 @@
101101
"%cd $repo_dir"
102102
]
103103
},
104+
{
105+
"cell_type": "code",
106+
"execution_count": null,
107+
"id": "2ca5e78a",
108+
"metadata": {},
109+
"outputs": [],
110+
"source": [
111+
"import requests\n",
112+
"\n",
113+
"r = requests.get(\n",
114+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
115+
")\n",
116+
"\n",
117+
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
118+
"\n",
119+
"from notebook_utils import download_file, device_widget, quantization_widget # noqa: F401"
120+
]
121+
},
104122
{
105123
"attachments": {},
106124
"cell_type": "markdown",
@@ -475,12 +493,7 @@
475493
}
476494
],
477495
"source": [
478-
"device = widgets.Dropdown(\n",
479-
" options=core.available_devices + [\"AUTO\"],\n",
480-
" value=\"AUTO\",\n",
481-
" description=\"Device:\",\n",
482-
" disabled=False,\n",
483-
")\n",
496+
"device = device_widget()\n",
484497
"\n",
485498
"device"
486499
]
@@ -609,11 +622,7 @@
609622
}
610623
],
611624
"source": [
612-
"to_quantize = widgets.Checkbox(\n",
613-
" value=True,\n",
614-
" description=\"Quantization\",\n",
615-
" disabled=False,\n",
616-
")\n",
625+
"to_quantize = quantization_widget()\n",
617626
"\n",
618627
"to_quantize"
619628
]
@@ -667,14 +676,6 @@
667676
"\n",
668677
"from zipfile import ZipFile\n",
669678
"\n",
670-
"r = requests.get(\n",
671-
" url='https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py',\n",
672-
")\n",
673-
"\n",
674-
"open('notebook_utils.py', 'w').write(r.text)\n",
675-
"\n",
676-
"from notebook_utils import download_file\n",
677-
"\n",
678679
"DATA_URL = \"https://ultralytics.com/assets/coco128.zip\"\n",
679680
"OUT_DIR = Path('.')\n",
680681
"\n",

0 commit comments

Comments
 (0)