Skip to content

Commit d29aba6

Browse files
authored
offline experience part 3 (#2706)
1 parent 4eaa0db commit d29aba6

File tree

67 files changed

+958
-825
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

+958
-825
lines changed

.ci/skipped_notebooks.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -569,4 +569,8 @@
569569
- macos-13
570570
- ubuntu-20.04
571571
- ubuntu-22.04
572-
- windows-2019
572+
- windows-2019
573+
- notebook: notebooks/paddle-to-openvino/paddle-to-openvino-classification.ipynb
574+
skips:
575+
- python:
576+
- '3.12'

notebooks/paddle-ocr-webcam/paddle-ocr-webcam.ipynb

+17-9
Original file line numberDiff line numberDiff line change
@@ -645,14 +645,19 @@
645645
],
646646
"source": [
647647
"# Download font and a character dictionary for printing OCR results.\n",
648-
"font_path = utils.download_file(\n",
649-
" url=\"https://raw.githubusercontent.com/Halfish/lstm-ctc-ocr/master/fonts/simfang.ttf\",\n",
650-
" directory=\"fonts\",\n",
651-
")\n",
652-
"character_dictionary_path = utils.download_file(\n",
653-
" url=\"https://raw.githubusercontent.com/WenmuZhou/PytorchOCR/master/torchocr/datasets/alphabets/ppocr_keys_v1.txt\",\n",
654-
" directory=\"fonts\",\n",
655-
")"
648+
"font_path = Path(\"fonts/simfang.ttf\")\n",
649+
"character_dictionary_path = Path(\"fonts/ppocr_keys_v1.txt\")\n",
650+
"\n",
651+
"if not font_path.exists():\n",
652+
" utils.download_file(\n",
653+
" url=\"https://raw.githubusercontent.com/Halfish/lstm-ctc-ocr/master/fonts/simfang.ttf\",\n",
654+
" directory=\"fonts\",\n",
655+
" )\n",
656+
"if not character_dictionary_path.exists():\n",
657+
" utils.download_file(\n",
658+
" url=\"https://raw.githubusercontent.com/WenmuZhou/PytorchOCR/master/torchocr/datasets/alphabets/ppocr_keys_v1.txt\",\n",
659+
" directory=\"fonts\",\n",
660+
" )"
656661
]
657662
},
658663
{
@@ -836,7 +841,10 @@
836841
"USE_WEBCAM = False\n",
837842
"\n",
838843
"cam_id = 0\n",
839-
"video_file = \"https://raw.githubusercontent.com/yoyowz/classification/master/images/test.mp4\"\n",
844+
"video_file = Path(\"test.mp4\")\n",
845+
"\n",
846+
"if not USE_WEBCAM and not video_file.exists():\n",
847+
" utils.download_file(\"https://raw.githubusercontent.com/yoyowz/classification/master/images/test.mp4\")\n",
840848
"\n",
841849
"source = cam_id if USE_WEBCAM else video_file\n",
842850
"\n",

notebooks/paddle-to-openvino/paddle-to-openvino-classification.ipynb

+22-16
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@
8686
"# Fetch `notebook_utils` module\n",
8787
"import requests\n",
8888
"\n",
89-
"r = requests.get(\n",
90-
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
91-
")\n",
89+
"if not Path(\"notebook_utils.py\").exists():\n",
90+
" r = requests.get(\n",
91+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
92+
" )\n",
9293
"\n",
93-
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
94+
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
9495
"\n",
9596
"from notebook_utils import download_file, device_widget\n",
9697
"\n",
@@ -133,25 +134,30 @@
133134
],
134135
"source": [
135136
"# Download the image from the openvino_notebooks storage\n",
136-
"img = download_file(\n",
137-
" \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/image/coco_close.png\",\n",
138-
" directory=\"data\",\n",
139-
")\n",
137+
"img = Path(\"data/coco_close.png\")\n",
138+
"\n",
139+
"if not img.exists():\n",
140+
" download_file(\n",
141+
" \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/image/coco_close.png\",\n",
142+
" directory=\"data\",\n",
143+
" )\n",
140144
"\n",
141145
"IMAGE_FILENAME = img.as_posix()\n",
142146
"\n",
143147
"MODEL_NAME = \"MobileNetV3_large_x1_0\"\n",
144148
"MODEL_DIR = Path(\"model\")\n",
145149
"if not MODEL_DIR.exists():\n",
146150
" MODEL_DIR.mkdir()\n",
147-
"MODEL_URL = \"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/{}_infer.tar\".format(MODEL_NAME)\n",
148-
"download_file(MODEL_URL, directory=MODEL_DIR)\n",
149-
"file = tarfile.open(MODEL_DIR / \"{}_infer.tar\".format(MODEL_NAME))\n",
150-
"res = file.extractall(MODEL_DIR)\n",
151-
"if not res:\n",
152-
" print(f'Model Extracted to \"./{MODEL_DIR}\".')\n",
153-
"else:\n",
154-
" print(\"Error Extracting the model. Please check the network.\")"
151+
"\n",
152+
"if not (MODEL_DIR / \"{}_infer\".format(MODEL_NAME)).exists():\n",
153+
" MODEL_URL = \"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/{}_infer.tar\".format(MODEL_NAME)\n",
154+
" download_file(MODEL_URL, directory=MODEL_DIR)\n",
155+
" file = tarfile.open(MODEL_DIR / \"{}_infer.tar\".format(MODEL_NAME))\n",
156+
" res = file.extractall(MODEL_DIR)\n",
157+
" if not res:\n",
158+
" print(f'Model Extracted to \"./{MODEL_DIR}\".')\n",
159+
" else:\n",
160+
" print(\"Error Extracting the model. Please check the network.\")"
155161
]
156162
},
157163
{

notebooks/parler-tts-text-to-speech/parler-tts-text-to-speech.ipynb

+5-6
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,11 @@
328328
"source": [
329329
"import requests\n",
330330
"\n",
331-
"r = requests.get(\n",
332-
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
333-
")\n",
334-
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
331+
"if not Path(\"notebook_utils.py\").exists():\n",
332+
" r = requests.get(\n",
333+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
334+
" )\n",
335+
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
335336
"\n",
336337
"from notebook_utils import device_widget\n",
337338
"\n",
@@ -537,8 +538,6 @@
537538
},
538539
"outputs": [],
539540
"source": [
540-
"import requests\n",
541-
"\n",
542541
"if not Path(\"gradio_helper.py\").exists():\n",
543542
" r = requests.get(url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/notebooks/parler-tts-text-to-speech/gradio_helper.py\")\n",
544543
" open(\"gradio_helper.py\", \"w\").write(r.text)\n",

notebooks/person-counting-webcam/person-counting.ipynb

+13-8
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,24 @@
266266
"metadata": {},
267267
"outputs": [],
268268
"source": [
269+
"import requests\n",
270+
"\n",
271+
"if not Path(\"notebook_utils.py\").exists():\n",
272+
" r = requests.get(\n",
273+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
274+
" )\n",
275+
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
276+
"\n",
277+
"from notebook_utils import download_file\n",
278+
"\n",
269279
"WEBCAM_INFERENCE = False\n",
270280
"\n",
271281
"if WEBCAM_INFERENCE:\n",
272282
" VIDEO_SOURCE = 0 # Webcam\n",
273283
"else:\n",
274-
" VIDEO_SOURCE = \"https://storage.openvinotoolkit.org/data/test_data/videos/people-detection.mp4\""
284+
" VIDEO_SOURCE = Path(\"people-detection.mp4\")\n",
285+
" if not VIDEO_SOURCE.exists():\n",
286+
" download_file(\"https://storage.openvinotoolkit.org/data/test_data/videos/people-detection.mp4\")"
275287
]
276288
},
277289
{
@@ -316,13 +328,6 @@
316328
}
317329
],
318330
"source": [
319-
"import requests\n",
320-
"\n",
321-
"r = requests.get(\n",
322-
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
323-
")\n",
324-
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
325-
"\n",
326331
"from notebook_utils import device_widget\n",
327332
"\n",
328333
"device = device_widget()\n",

notebooks/person-tracking-webcam/person-tracking.ipynb

+16-7
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@
120120
"outputs": [],
121121
"source": [
122122
"# Import local modules\n",
123+
"import requests\n",
123124
"\n",
124125
"if not Path(\"./notebook_utils.py\").exists():\n",
125126
" # Fetch `notebook_utils` module\n",
126-
" import requests\n",
127127
"\n",
128128
" r = requests.get(\n",
129129
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
@@ -174,18 +174,21 @@
174174
"precision = \"FP16\"\n",
175175
"# The name of the model from Open Model Zoo\n",
176176
"detection_model_name = \"person-detection-0202\"\n",
177-
"\n",
178-
"\n",
179177
"download_det_model_url = (\n",
180178
" f\"https://storage.openvinotoolkit.org/repositories/open_model_zoo/2023.0/models_bin/1/{detection_model_name}/{precision}/{detection_model_name}.xml\"\n",
181179
")\n",
180+
"detection_model_path = Path(base_model_dir) / detection_model_name / precision / f\"{detection_model_name}.xml\"\n",
182181
"\n",
183-
"detection_model_path = download_ir_model(download_det_model_url, Path(base_model_dir) / detection_model_name / precision)\n",
182+
"if not detection_model_path.exists():\n",
183+
"\n",
184+
" download_ir_model(download_det_model_url, Path(base_model_dir) / detection_model_name / precision)\n",
184185
"\n",
185186
"reidentification_model_name = \"person-reidentification-retail-0287\"\n",
186187
"download_reid_model_url = f\"https://storage.openvinotoolkit.org/repositories/open_model_zoo/2023.0/models_bin/1/{reidentification_model_name}/{precision}/{reidentification_model_name}.xml\"\n",
188+
"reidentification_model_path = Path(base_model_dir) / reidentification_model_name / precision / f\"{reidentification_model_name}.xml\"\n",
187189
"\n",
188-
"reidentification_model_path = download_ir_model(download_reid_model_url, Path(base_model_dir) / reidentification_model_name / precision)"
190+
"if not reidentification_model_path.exists():\n",
191+
" download_ir_model(download_reid_model_url, Path(base_model_dir) / reidentification_model_name / precision)"
189192
]
190193
},
191194
{
@@ -449,7 +452,9 @@
449452
"source": [
450453
"base_file_link = \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/image/person_\"\n",
451454
"image_indices = [\"1_1.png\", \"1_2.png\", \"2_1.png\"]\n",
452-
"image_paths = [utils.download_file(base_file_link + image_index, directory=\"data\") for image_index in image_indices]\n",
455+
"image_paths = [\n",
456+
" utils.download_file(base_file_link + image_index, directory=\"data\") for image_index in image_indices if not (Path(\"data\") / image_index).exists()\n",
457+
"]\n",
453458
"image1, image2, image3 = [cv2.cvtColor(cv2.imread(str(image_path)), cv2.COLOR_BGR2RGB) for image_path in image_paths]\n",
454459
"\n",
455460
"# Define titles with images.\n",
@@ -705,9 +710,13 @@
705710
"USE_WEBCAM = False\n",
706711
"\n",
707712
"cam_id = 0\n",
708-
"video_file = \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/video/people.mp4\"\n",
713+
"video_url = \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/video/people.mp4\"\n",
714+
"video_file = Path(\"people.mp4\")\n",
709715
"source = cam_id if USE_WEBCAM else video_file\n",
710716
"\n",
717+
"if not USE_WEBCAM and not video_file.exists():\n",
718+
" utils.download_file(video_url)\n",
719+
"\n",
711720
"run_person_tracking(source=source, flip=USE_WEBCAM, use_popup=False)"
712721
]
713722
}

notebooks/phi-3-vision/phi-3-vision.ipynb

+8-2
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,14 @@
431431
"import requests\n",
432432
"from PIL import Image\n",
433433
"\n",
434-
"url = \"https://github.com/openvinotoolkit/openvino_notebooks/assets/29454499/d5fbbd1a-d484-415c-88cb-9986625b7b11\"\n",
435-
"image = Image.open(requests.get(url, stream=True).raw)\n",
434+
"image_path = Path(\"cat.png\")\n",
435+
"\n",
436+
"if not image_path.exists():\n",
437+
" url = \"https://github.com/openvinotoolkit/openvino_notebooks/assets/29454499/d5fbbd1a-d484-415c-88cb-9986625b7b11\"\n",
438+
" image = Image.open(requests.get(url, stream=True).raw)\n",
439+
" image.save(image_path)\n",
440+
"else:\n",
441+
" image = Image.open(image_path)\n",
436442
"\n",
437443
"print(\"Question:\\n What is unusual on this picture?\")\n",
438444
"image"

notebooks/pix2struct-docvqa/pix2struct-docvqa.ipynb

+18-19
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,11 @@
154154
"source": [
155155
"import requests\n",
156156
"\n",
157-
"r = requests.get(\n",
158-
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
159-
")\n",
160-
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
157+
"if not Path(\"notebook_utils.py\").exists():\n",
158+
" r = requests.get(\n",
159+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
160+
" )\n",
161+
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
161162
"\n",
162163
"from notebook_utils import device_widget\n",
163164
"\n",
@@ -243,14 +244,23 @@
243244
"\n",
244245
"\n",
245246
"def load_image(image_file):\n",
246-
" response = requests.get(image_file)\n",
247-
" image = Image.open(BytesIO(response.content)).convert(\"RGB\")\n",
248-
" return image\n",
247+
" if isinstance(image_file, str) and image_file.startswith(\"https://\"):\n",
248+
" response = requests.get(image_file)\n",
249+
" image = Image.open(BytesIO(response.content))\n",
250+
" else:\n",
251+
" image = Image.open(image_file)\n",
252+
" return image.convert(\"RGB\")\n",
249253
"\n",
250254
"\n",
255+
"test_image_path = Path(\"ov_docs.png\")\n",
251256
"test_image_url = \"https://github.com/openvinotoolkit/openvino_notebooks/assets/29454499/aa46ef0c-c14d-4bab-8bb7-3b22fe73f6bc\"\n",
252257
"\n",
253-
"image = load_image(test_image_url)\n",
258+
"if not test_image_path.exists():\n",
259+
" image = load_image(test_image_url)\n",
260+
" image.save(test_image_path)\n",
261+
"else:\n",
262+
" image = load_image(test_image_path)\n",
263+
"\n",
254264
"text = \"What performance hints do?\"\n",
255265
"\n",
256266
"inputs = processor(images=image, text=text, return_tensors=\"pt\")\n",
@@ -330,17 +340,6 @@
330340
"# demo.launch(server_name='your server name', server_port='server port in int')\n",
331341
"# Read more in the docs: https://gradio.app/docs/"
332342
]
333-
},
334-
{
335-
"cell_type": "code",
336-
"execution_count": null,
337-
"id": "582a1703",
338-
"metadata": {},
339-
"outputs": [],
340-
"source": [
341-
"# please uncomment and run this cell for stopping gradio interface\n",
342-
"# demo.close()"
343-
]
344343
}
345344
],
346345
"metadata": {

0 commit comments

Comments
 (0)