Skip to content

Commit de3046b

Browse files
authored
device widget part 2 (openvinotoolkit#2321)
1 parent faa5036 commit de3046b

File tree

83 files changed

+903
-721
lines changed

Some content is hidden

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

83 files changed

+903
-721
lines changed

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

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"cells": [
33
{
4+
"attachments": {},
45
"cell_type": "markdown",
56
"id": "9de9a93e-9247-4799-a5bb-2ec1575ae8c2",
67
"metadata": {},
@@ -63,6 +64,7 @@
6364
]
6465
},
6566
{
67+
"attachments": {},
6668
"cell_type": "markdown",
6769
"id": "7925a51b-26ec-43c5-9660-0705c03d724d",
6870
"metadata": {},
@@ -80,10 +82,11 @@
8082
"metadata": {},
8183
"outputs": [],
8284
"source": [
83-
"%pip install pythreejs \"openvino-dev>=2024.0.0\" \"opencv-python\" \"torch\" \"onnx\" --extra-index-url https://download.pytorch.org/whl/cpu"
85+
"%pip install pythreejs \"openvino-dev>=2024.0.0\" \"opencv-python\" \"torch\" \"onnx<1.16.2\" --extra-index-url https://download.pytorch.org/whl/cpu"
8486
]
8587
},
8688
{
89+
"attachments": {},
8790
"cell_type": "markdown",
8891
"id": "5a9332fb-1cee-4faa-9555-731ddf0e0df7",
8992
"metadata": {},
@@ -129,6 +132,7 @@
129132
]
130133
},
131134
{
135+
"attachments": {},
132136
"cell_type": "markdown",
133137
"id": "c96ad61a-59ff-4873-b2f3-3994d6826f51",
134138
"metadata": {},
@@ -170,6 +174,7 @@
170174
]
171175
},
172176
{
177+
"attachments": {},
173178
"cell_type": "markdown",
174179
"id": "88f39f76-2f81-4c18-9fda-98ea6a944220",
175180
"metadata": {},
@@ -195,6 +200,7 @@
195200
]
196201
},
197202
{
203+
"attachments": {},
198204
"cell_type": "markdown",
199205
"id": "6458fe97-6e93-4357-bc9a-16394d962e56",
200206
"metadata": {},
@@ -218,6 +224,7 @@
218224
]
219225
},
220226
{
227+
"attachments": {},
221228
"cell_type": "markdown",
222229
"id": "986a07ac-d092-4254-848a-dd48f4934fb5",
223230
"metadata": {},
@@ -252,6 +259,7 @@
252259
]
253260
},
254261
{
262+
"attachments": {},
255263
"cell_type": "markdown",
256264
"id": "5c0ffd17-df71-4178-8df8-db4ccf431621",
257265
"metadata": {},
@@ -270,6 +278,7 @@
270278
]
271279
},
272280
{
281+
"attachments": {},
273282
"cell_type": "markdown",
274283
"id": "48eb5032-a06e-48c1-a3d6-f0fbad9924fb",
275284
"metadata": {},
@@ -316,6 +325,7 @@
316325
]
317326
},
318327
{
328+
"attachments": {},
319329
"cell_type": "markdown",
320330
"id": "6991403a-4f87-45be-9b3f-d30b23a46dbe",
321331
"metadata": {},
@@ -425,6 +435,7 @@
425435
]
426436
},
427437
{
438+
"attachments": {},
428439
"cell_type": "markdown",
429440
"id": "a6894ce8-ac91-464d-a7f7-54d09f399f4f",
430441
"metadata": {},
@@ -600,6 +611,7 @@
600611
]
601612
},
602613
{
614+
"attachments": {},
603615
"cell_type": "markdown",
604616
"id": "344840a6-9660-4a11-8b05-729ac2969e28",
605617
"metadata": {},
@@ -619,6 +631,7 @@
619631
]
620632
},
621633
{
634+
"attachments": {},
622635
"cell_type": "markdown",
623636
"id": "d2d1a143-afcb-4f22-a4cc-657a080b70bf",
624637
"metadata": {},

notebooks/amused-lightweight-text-to-image/amused-lightweight-text-to-image.ipynb

+25-13
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,22 @@
8080
"%pip install -q \"nncf>=2.9.0\" datasets"
8181
]
8282
},
83+
{
84+
"cell_type": "code",
85+
"execution_count": null,
86+
"id": "4c23018e",
87+
"metadata": {},
88+
"outputs": [],
89+
"source": [
90+
"# Fetch the notebook utils script from the openvino_notebooks repo\n",
91+
"import requests\n",
92+
"\n",
93+
"r = requests.get(\n",
94+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
95+
")\n",
96+
"open(\"notebook_utils.py\", \"w\").write(r.text)"
97+
]
98+
},
8399
{
84100
"attachments": {},
85101
"cell_type": "markdown",
@@ -496,16 +512,9 @@
496512
}
497513
],
498514
"source": [
499-
"import ipywidgets as widgets\n",
500-
"\n",
515+
"from notebook_utils import device_widget\n",
501516
"\n",
502-
"core = ov.Core()\n",
503-
"device = widgets.Dropdown(\n",
504-
" options=core.available_devices + [\"AUTO\"],\n",
505-
" value=\"AUTO\",\n",
506-
" description=\"Device:\",\n",
507-
" disabled=False,\n",
508-
")\n",
517+
"device = device_widget()\n",
509518
"\n",
510519
"device"
511520
]
@@ -522,6 +531,8 @@
522531
},
523532
"outputs": [],
524533
"source": [
534+
"core = ov.Core()\n",
535+
"\n",
525536
"ov_text_encoder = core.compile_model(TEXT_ENCODER_OV_PATH, device.value)\n",
526537
"ov_transformer = core.compile_model(TRANSFORMER_OV_PATH, device.value)\n",
527538
"ov_vqvae = core.compile_model(VQVAE_OV_PATH, device.value)"
@@ -755,10 +766,12 @@
755766
},
756767
"outputs": [],
757768
"source": [
769+
"from notebook_utils import quantization_widget\n",
770+
"\n",
758771
"QUANTIZED_TRANSFORMER_OV_PATH = Path(str(TRANSFORMER_OV_PATH).replace(\".xml\", \"_quantized.xml\"))\n",
759772
"\n",
760773
"skip_for_device = \"GPU\" in device.value\n",
761-
"to_quantize = widgets.Checkbox(value=not skip_for_device, description=\"Quantization\", disabled=skip_for_device)\n",
774+
"to_quantize = quantization_widget(not skip_for_device)\n",
762775
"to_quantize"
763776
]
764777
},
@@ -774,8 +787,6 @@
774787
},
775788
"outputs": [],
776789
"source": [
777-
"import requests\n",
778-
"\n",
779790
"r = requests.get(\n",
780791
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/skip_kernel_extension.py\",\n",
781792
")\n",
@@ -1067,6 +1078,8 @@
10671078
"metadata": {},
10681079
"outputs": [],
10691080
"source": [
1081+
"import ipywidgets as widgets\n",
1082+
"\n",
10701083
"quantized_model_present = QUANTIZED_TRANSFORMER_OV_PATH.exists()\n",
10711084
"\n",
10721085
"use_quantized_model = widgets.Checkbox(\n",
@@ -1085,7 +1098,6 @@
10851098
"metadata": {},
10861099
"outputs": [],
10871100
"source": [
1088-
"import requests\n",
10891101
"from pathlib import Path\n",
10901102
"\n",
10911103
"if not Path(\"gradio_helper.py\").exists():\n",

notebooks/animate-anyone/animate-anyone.ipynb

+8-8
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@
8686
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/skip_kernel_extension.py\",\n",
8787
")\n",
8888
"open(\"skip_kernel_extension.py\", \"w\").write(r.text)\n",
89+
"\n",
90+
"r = requests.get(\n",
91+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
92+
")\n",
93+
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
94+
"\n",
8995
"%load_ext skip_kernel_extension"
9096
]
9197
},
@@ -165,7 +171,6 @@
165171
"from diffusers.image_processor import VaeImageProcessor\n",
166172
"from transformers import CLIPImageProcessor\n",
167173
"import torch\n",
168-
"import ipywidgets as widgets\n",
169174
"\n",
170175
"from src.pipelines.pipeline_pose2vid_long import Pose2VideoPipeline\n",
171176
"from src.utils.util import get_fps, read_frames\n",
@@ -1116,14 +1121,9 @@
11161121
}
11171122
],
11181123
"source": [
1119-
"device = widgets.Dropdown(\n",
1120-
" options=core.available_devices + [\"AUTO\"],\n",
1121-
" value=\"AUTO\",\n",
1122-
" description=\"Device:\",\n",
1123-
" disabled=False,\n",
1124-
")\n",
1124+
"from notebook_utils import device_widget\n",
11251125
"\n",
1126-
"device"
1126+
"device = device_widget()"
11271127
]
11281128
},
11291129
{

notebooks/bark-text-to-audio/bark-text-to-audio.ipynb

+17-10
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@
7575
"%pip install -q \"git+https://github.com/suno-ai/bark.git\" --extra-index-url https://download.pytorch.org/whl/cpu"
7676
]
7777
},
78+
{
79+
"cell_type": "code",
80+
"execution_count": null,
81+
"id": "d44f17c4",
82+
"metadata": {},
83+
"outputs": [],
84+
"source": [
85+
"import requests\n",
86+
"\n",
87+
"r = requests.get(\n",
88+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
89+
")\n",
90+
"open(\"notebook_utils.py\", \"w\").write(r.text)"
91+
]
92+
},
7893
{
7994
"attachments": {},
8095
"cell_type": "markdown",
@@ -1020,17 +1035,9 @@
10201035
}
10211036
],
10221037
"source": [
1023-
"import ipywidgets as widgets\n",
1024-
"import openvino as ov\n",
1038+
"from notebook_utils import device_widget\n",
10251039
"\n",
1026-
"core = ov.Core()\n",
1027-
"\n",
1028-
"device = widgets.Dropdown(\n",
1029-
" options=core.available_devices + [\"AUTO\"],\n",
1030-
" value=\"AUTO\",\n",
1031-
" description=\"Device:\",\n",
1032-
" disabled=False,\n",
1033-
")\n",
1040+
"device = device_widget()\n",
10341041
"\n",
10351042
"device"
10361043
]

notebooks/big-transfer-quantization/tensorflow-bit-image-classification-nncf-quantization.ipynb

+12-10
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,14 @@
8888
"import tensorflow_hub as hub\n",
8989
"\n",
9090
"tfds.core.utils.gcs_utils._is_gcs_disabled = True\n",
91-
"os.environ[\"NO_GCE_CHECK\"] = \"true\""
91+
"os.environ[\"NO_GCE_CHECK\"] = \"true\"\n",
92+
"\n",
93+
"import requests\n",
94+
"\n",
95+
"r = requests.get(\n",
96+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
97+
")\n",
98+
"open(\"notebook_utils.py\", \"w\").write(r.text)"
9299
]
93100
},
94101
{
@@ -446,16 +453,9 @@
446453
"metadata": {},
447454
"outputs": [],
448455
"source": [
449-
"import ipywidgets as widgets\n",
450-
"\n",
451-
"core = ov.Core()\n",
456+
"from notebook_utils import device_widget\n",
452457
"\n",
453-
"device = widgets.Dropdown(\n",
454-
" options=core.available_devices + [\"AUTO\"],\n",
455-
" value=\"AUTO\",\n",
456-
" description=\"Device:\",\n",
457-
" disabled=False,\n",
458-
")\n",
458+
"device = device_widget()\n",
459459
"\n",
460460
"device"
461461
]
@@ -470,6 +470,8 @@
470470
},
471471
"outputs": [],
472472
"source": [
473+
"core = ov.Core()\n",
474+
"\n",
473475
"ov_fp32_model = core.read_model(ir_path)\n",
474476
"ov_fp32_model.reshape([1, IMG_SIZE[0], IMG_SIZE[1], 3])\n",
475477
"\n",

notebooks/clip-language-saliency-map/clip-language-saliency-map.ipynb

+8-8
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,12 @@
112112
"import torch\n",
113113
"import tqdm\n",
114114
"from PIL import Image\n",
115-
"from transformers import CLIPModel, CLIPProcessor"
115+
"from transformers import CLIPModel, CLIPProcessor\n",
116+
"\n",
117+
"r = requests.get(\n",
118+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
119+
")\n",
120+
"open(\"notebook_utils.py\", \"w\").write(r.text)"
116121
]
117122
},
118123
{
@@ -640,14 +645,9 @@
640645
}
641646
],
642647
"source": [
643-
"import ipywidgets as widgets\n",
648+
"from notebook_utils import device_widget\n",
644649
"\n",
645-
"device = widgets.Dropdown(\n",
646-
" options=core.available_devices + [\"AUTO\"],\n",
647-
" value=\"AUTO\",\n",
648-
" description=\"Device:\",\n",
649-
" disabled=False,\n",
650-
")\n",
650+
"device = device_widget()\n",
651651
"\n",
652652
"device"
653653
]

notebooks/clip-zero-shot-image-classification/clip-zero-shot-classification.ipynb

+10-8
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,14 @@
9595
"if platform.system() != \"Windows\":\n",
9696
" %pip install -q \"matplotlib>=3.4\"\n",
9797
"else:\n",
98-
" %pip install -q \"matplotlib>=3.4,<3.7\""
98+
" %pip install -q \"matplotlib>=3.4,<3.7\"\n",
99+
"\n",
100+
"import requests\n",
101+
"\n",
102+
"r = requests.get(\n",
103+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
104+
")\n",
105+
"open(\"notebook_utils.py\", \"w\").write(r.text)"
99106
]
100107
},
101108
{
@@ -325,14 +332,9 @@
325332
}
326333
],
327334
"source": [
328-
"import ipywidgets as widgets\n",
335+
"from notebook_utils import device_widget\n",
329336
"\n",
330-
"device = widgets.Dropdown(\n",
331-
" options=core.available_devices + [\"AUTO\"],\n",
332-
" value=\"AUTO\",\n",
333-
" description=\"Device:\",\n",
334-
" disabled=False,\n",
335-
")\n",
337+
"device = device_widget()\n",
336338
"\n",
337339
"device"
338340
]

0 commit comments

Comments
 (0)