Skip to content

Commit 5f58a1c

Browse files
authored
improve offline experience (#2685)
CVS-160839
1 parent 64779f2 commit 5f58a1c

File tree

25 files changed

+358
-282
lines changed

25 files changed

+358
-282
lines changed

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@
6767
"# Fetch `notebook_utils` module\n",
6868
"import requests\n",
6969
"\n",
70-
"r = requests.get(\n",
71-
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
72-
")\n",
73-
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
70+
"if not Path(\"notebook_utils.py\").exists():\n",
71+
" r = requests.get(\n",
72+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
73+
" )\n",
74+
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
7475
"\n",
7576
"from notebook_utils import download_file, device_widget"
7677
]
@@ -103,12 +104,14 @@
103104
"# Set the data and model directories, model source URL and model filename\n",
104105
"MODEL_DIR = Path(\"model\")\n",
105106
"MODEL_DIR.mkdir(exist_ok=True)\n",
106-
"download_file(\n",
107-
" \"https://storage.googleapis.com/ailia-models/pointnet_pytorch/chair_100.onnx\",\n",
108-
" directory=Path(MODEL_DIR),\n",
109-
" show_progress=False,\n",
110-
")\n",
111-
"onnx_model_path = MODEL_DIR / \"chair_100.onnx\""
107+
"onnx_model_path = MODEL_DIR / \"chair_100.onnx\"\n",
108+
"\n",
109+
"if not onnx_model_path.exists():\n",
110+
" download_file(\n",
111+
" \"https://storage.googleapis.com/ailia-models/pointnet_pytorch/chair_100.onnx\",\n",
112+
" directory=Path(MODEL_DIR),\n",
113+
" show_progress=False,\n",
114+
" )"
112115
]
113116
},
114117
{
@@ -242,10 +245,13 @@
242245
],
243246
"source": [
244247
"# Download data from the openvino_notebooks storage\n",
245-
"point_data = download_file(\n",
246-
" \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/pts/chair.pts\",\n",
247-
" directory=\"data\",\n",
248-
")\n",
248+
"point_data_path = Path(\"data\") / \"chair.pts\"\n",
249+
"\n",
250+
"if not point_data_path.exists():\n",
251+
" point_data = download_file(\n",
252+
" \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/pts/chair.pts\",\n",
253+
" directory=\"data\",\n",
254+
" )\n",
249255
"\n",
250256
"points = load_data(str(point_data))\n",
251257
"X = points[:, 0]\n",

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@
101101
"# Fetch `notebook_utils` module\n",
102102
"import requests\n",
103103
"\n",
104-
"r = requests.get(\n",
105-
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
106-
")\n",
107-
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
104+
"if not Path(\"notebook_utils.py\").exists():\n",
105+
" r = requests.get(\n",
106+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
107+
" )\n",
108+
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
108109
"import notebook_utils as utils"
109110
]
110111
},
@@ -171,10 +172,12 @@
171172
"outputs": [],
172173
"source": [
173174
"# Download the text from the openvino_notebooks storage\n",
174-
"vocab_file_path = utils.download_file(\n",
175-
" \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/text/kinetics.txt\",\n",
176-
" directory=\"data\",\n",
177-
")\n",
175+
"\n",
176+
"if not (Path(\"data\") / \"kinetics.txt\").exists():\n",
177+
" vocab_file_path = utils.download_file(\n",
178+
" \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/text/kinetics.txt\",\n",
179+
" directory=\"data\",\n",
180+
" )\n",
178181
"\n",
179182
"with vocab_file_path.open(mode=\"r\") as f:\n",
180183
" labels = [line.strip() for line in f]\n",
@@ -726,7 +729,11 @@
726729
"USE_WEBCAM = False\n",
727730
"\n",
728731
"cam_id = 0\n",
729-
"video_file = \"https://archive.org/serve/ISSVideoResourceLifeOnStation720p/ISS%20Video%20Resource_LifeOnStation_720p.mp4\"\n",
732+
"video_url = \"https://archive.org/serve/ISSVideoResourceLifeOnStation720p/ISS%20Video%20Resource_LifeOnStation_720p.mp4\"\n",
733+
"video_file = Path(\"ISS%20Video%20Resource_LifeOnStation_720p.mp4\")\n",
734+
"\n",
735+
"if not USE_WEBCAM and video_file.exists():\n",
736+
" utils.download_file(video_url, filename=video_file.name)\n",
730737
"\n",
731738
"source = cam_id if USE_WEBCAM else video_file\n",
732739
"additional_options = {\"skip_first_frames\": 600, \"flip\": False} if not USE_WEBCAM else {\"flip\": True}\n",

notebooks/animate-anyone/animate-anyone.ipynb

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,14 @@
7878
"%pip install -q \"torch>=2.1\" torchvision einops omegaconf \"diffusers<=0.24\" \"huggingface-hub<0.26.0\" transformers av accelerate \"gradio>=4.19\" --extra-index-url \"https://download.pytorch.org/whl/cpu\"\n",
7979
"%pip install -q \"openvino>=2024.0\" \"nncf>=2.9.0\"\n",
8080
"\n",
81+
"helpers = [\"skip_kernel_extension.py\", \"notebook_utils.py\", \"cmd_helper.py\"]\n",
8182
"\n",
82-
"r = requests.get(\n",
83-
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/skip_kernel_extension.py\",\n",
84-
")\n",
85-
"open(\"skip_kernel_extension.py\", \"w\").write(r.text)\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)\n",
91-
"\n",
92-
"r = requests.get(\n",
93-
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/cmd_helper.py\",\n",
94-
")\n",
95-
"open(\"cmd_helper.py\", \"w\").write(r.text)\n",
83+
"for file_name in helpers:\n",
84+
" if not Path(file_name).exists():\n",
85+
" r = requests.get(\n",
86+
" url=f\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/{file_name}\",\n",
87+
" )\n",
88+
" open(file_name, \"w\").write(r.text)\n",
9689
"\n",
9790
"\n",
9891
"from cmd_helper import clone_repo\n",

notebooks/async-api/async-api.ipynb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,16 @@
7171
"import openvino as ov\n",
7272
"from IPython import display\n",
7373
"import matplotlib.pyplot as plt\n",
74+
"from pathlib import Path\n",
7475
"\n",
7576
"# Fetch the notebook utils script from the openvino_notebooks repo\n",
7677
"import requests\n",
7778
"\n",
78-
"r = requests.get(\n",
79-
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
80-
")\n",
81-
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
79+
"if not Path(\"notebook_utils.py\").exists():\n",
80+
" r = requests.get(\n",
81+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
82+
" )\n",
83+
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
8284
"\n",
8385
"import notebook_utils as utils"
8486
]

notebooks/auto-device/auto-device.ipynb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,9 @@
307307
"# Fetch `notebook_utils` module\n",
308308
"import requests\n",
309309
"\n",
310-
"r = requests.get(url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\")\n",
311-
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
310+
"if not Path(\"notebook_utils.py\").exists():\n",
311+
" r = requests.get(url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\")\n",
312+
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
312313
"\n",
313314
"from notebook_utils import download_file"
314315
]
@@ -336,11 +337,14 @@
336337
"source": [
337338
"from PIL import Image\n",
338339
"\n",
339-
"# Download the image from the openvino_notebooks storage\n",
340-
"image_filename = download_file(\n",
341-
" \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/image/coco.jpg\",\n",
342-
" directory=\"data\",\n",
343-
")\n",
340+
"image_filename = Path(\"data/coco.jpg\")\n",
341+
"\n",
342+
"if not image_filename.exists():\n",
343+
" # Download the image from the openvino_notebooks storage\n",
344+
" image_filename = download_file(\n",
345+
" \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/image/coco.jpg\",\n",
346+
" directory=\"data\",\n",
347+
" )\n",
344348
"\n",
345349
"image = Image.open(str(image_filename))\n",
346350
"input_transform = torchvision.models.ResNet50_Weights.DEFAULT.transforms()\n",

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@
8383
"outputs": [],
8484
"source": [
8585
"import requests\n",
86+
"from pathlib import Path\n",
8687
"\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)"
88+
"if not Path(\"notebook_utils.py\").exists():\n",
89+
" r = requests.get(\n",
90+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
91+
" )\n",
92+
" open(\"notebook_utils.py\", \"w\").write(r.text)"
9193
]
9294
},
9395
{
@@ -670,7 +672,6 @@
670672
" encoded_text = np.ascontiguousarray(_tokenize(tokenizer, text)) + TEXT_ENCODING_OFFSET\n",
671673
" if len(encoded_text) > 256:\n",
672674
" p = round((len(encoded_text) - 256) / len(encoded_text) * 100, 1)\n",
673-
" logger.warning(f\"warning, text too long, lopping of last {p}%\")\n",
674675
" encoded_text = encoded_text[:256]\n",
675676
" encoded_text = np.pad(\n",
676677
" encoded_text,\n",

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@
6464
"import os\n",
6565
"import numpy as np\n",
6666
"from pathlib import Path\n",
67-
"\n",
68-
"from openvino.runtime import Core\n",
6967
"import openvino as ov\n",
7068
"import nncf\n",
7169
"import logging\n",
@@ -89,10 +87,12 @@
8987
"\n",
9088
"import requests\n",
9189
"\n",
92-
"r = requests.get(\n",
93-
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
94-
")\n",
95-
"open(\"notebook_utils.py\", \"w\").write(r.text)"
90+
"\n",
91+
"if not Path(\"notebook_utils.py\").exists():\n",
92+
" r = requests.get(\n",
93+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
94+
" )\n",
95+
" open(\"notebook_utils.py\", \"w\").write(r.text)"
9696
]
9797
},
9898
{
@@ -101,7 +101,7 @@
101101
"metadata": {},
102102
"outputs": [],
103103
"source": [
104-
"core = Core()\n",
104+
"core = ov.Core()\n",
105105
"tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)\n",
106106
"\n",
107107
"\n",
@@ -323,28 +323,28 @@
323323
],
324324
"source": [
325325
"# Load the Big Transfer model\n",
326-
"bit_model_url = \"https://www.kaggle.com/models/google/bit/frameworks/TensorFlow2/variations/m-r50x1/versions/1\"\n",
327-
"bit_m = hub.KerasLayer(bit_model_url, trainable=True)\n",
328-
"\n",
329326
"tf_model_dir = Path(\"bit_tf_model\")\n",
330327
"\n",
331-
"# Customize the model for the new task\n",
332-
"model = tf.keras.Sequential([bit_m, tf.keras.layers.Dense(NUM_CLASSES, activation=\"softmax\")])\n",
333-
"\n",
334-
"# Compile the model\n",
335-
"model.compile(\n",
336-
" optimizer=tf.keras.optimizers.Adam(learning_rate=LR),\n",
337-
" loss=\"categorical_crossentropy\",\n",
338-
" metrics=[\"accuracy\"],\n",
339-
")\n",
340-
"\n",
341-
"# Fine-tune the model\n",
342-
"model.fit(\n",
343-
" train_dataset.take(3000),\n",
344-
" epochs=FINE_TUNING_STEPS,\n",
345-
" validation_data=validation_dataset.take(1000),\n",
346-
")\n",
347-
"model.save(tf_model_dir, save_format=\"tf\")"
328+
"if not tf_model_dir.exists():\n",
329+
" bit_model_url = \"https://www.kaggle.com/models/google/bit/frameworks/TensorFlow2/variations/m-r50x1/versions/1\"\n",
330+
" bit_m = hub.KerasLayer(bit_model_url, trainable=True)\n",
331+
" # Customize the model for the new task\n",
332+
" model = tf.keras.Sequential([bit_m, tf.keras.layers.Dense(NUM_CLASSES, activation=\"softmax\")])\n",
333+
"\n",
334+
" # Compile the model\n",
335+
" model.compile(\n",
336+
" optimizer=tf.keras.optimizers.Adam(learning_rate=LR),\n",
337+
" loss=\"categorical_crossentropy\",\n",
338+
" metrics=[\"accuracy\"],\n",
339+
" )\n",
340+
"\n",
341+
" # Fine-tune the model\n",
342+
" model.fit(\n",
343+
" train_dataset.take(3000),\n",
344+
" epochs=FINE_TUNING_STEPS,\n",
345+
" validation_data=validation_dataset.take(1000),\n",
346+
" )\n",
347+
" model.save(tf_model_dir, save_format=\"tf\")"
348348
]
349349
},
350350
{

0 commit comments

Comments
 (0)