Skip to content

Commit 56db698

Browse files
committed
offline experience part 3
1 parent 93c5015 commit 56db698

File tree

18 files changed

+201
-162
lines changed

18 files changed

+201
-162
lines changed

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -640,14 +640,19 @@
640640
],
641641
"source": [
642642
"# Download font and a character dictionary for printing OCR results.\n",
643-
"font_path = utils.download_file(\n",
644-
" url=\"https://raw.githubusercontent.com/Halfish/lstm-ctc-ocr/master/fonts/simfang.ttf\",\n",
645-
" directory=\"fonts\",\n",
646-
")\n",
647-
"character_dictionary_path = utils.download_file(\n",
648-
" url=\"https://raw.githubusercontent.com/WenmuZhou/PytorchOCR/master/torchocr/datasets/alphabets/ppocr_keys_v1.txt\",\n",
649-
" directory=\"fonts\",\n",
650-
")"
643+
"font_path = Path(\"fonts/simfang.ttf\")\n",
644+
"character_dictionary_path = Path(\"fonts/ppocr_keys_v1.txt\")\n",
645+
"\n",
646+
"if not font_path.exists():\n",
647+
" utils.download_file(\n",
648+
" url=\"https://raw.githubusercontent.com/Halfish/lstm-ctc-ocr/master/fonts/simfang.ttf\",\n",
649+
" directory=\"fonts\",\n",
650+
" )\n",
651+
"if not character_dictionary_path.exists():\n",
652+
" 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+
" )"
651656
]
652657
},
653658
{
@@ -831,7 +836,10 @@
831836
"USE_WEBCAM = False\n",
832837
"\n",
833838
"cam_id = 0\n",
834-
"video_file = \"https://raw.githubusercontent.com/yoyowz/classification/master/images/test.mp4\"\n",
839+
"video_file = Path(\"test.mp4\")\n",
840+
"\n",
841+
"if not USE_WEBCAM and not video_file.exists():\n",
842+
" utils.download_file(\"https://raw.githubusercontent.com/yoyowz/classification/master/images/test.mp4\")\n",
835843
"\n",
836844
"source = cam_id if USE_WEBCAM else video_file\n",
837845
"\n",

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

Lines changed: 22 additions & 16 deletions
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"
9697
]
@@ -128,25 +129,30 @@
128129
],
129130
"source": [
130131
"# Download the image from the openvino_notebooks storage\n",
131-
"img = download_file(\n",
132-
" \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/image/coco_close.png\",\n",
133-
" directory=\"data\",\n",
134-
")\n",
132+
"img = Path(\"data/coco_cose.png\")\n",
133+
"\n",
134+
"if not img.exists():\n",
135+
" download_file(\n",
136+
" \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/image/coco_close.png\",\n",
137+
" directory=\"data\",\n",
138+
" )\n",
135139
"\n",
136140
"IMAGE_FILENAME = img.as_posix()\n",
137141
"\n",
138142
"MODEL_NAME = \"MobileNetV3_large_x1_0\"\n",
139143
"MODEL_DIR = Path(\"model\")\n",
140144
"if not MODEL_DIR.exists():\n",
141145
" MODEL_DIR.mkdir()\n",
142-
"MODEL_URL = \"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/{}_infer.tar\".format(MODEL_NAME)\n",
143-
"download_file(MODEL_URL, directory=MODEL_DIR)\n",
144-
"file = tarfile.open(MODEL_DIR / \"{}_infer.tar\".format(MODEL_NAME))\n",
145-
"res = file.extractall(MODEL_DIR)\n",
146-
"if not res:\n",
147-
" print(f'Model Extracted to \"./{MODEL_DIR}\".')\n",
148-
"else:\n",
149-
" print(\"Error Extracting the model. Please check the network.\")"
146+
"\n",
147+
"if not (MODEL_DIR / \"{}_infer\".format(MODEL_NAME)).exists():\n",
148+
" MODEL_URL = \"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/{}_infer.tar\".format(MODEL_NAME)\n",
149+
" download_file(MODEL_URL, directory=MODEL_DIR)\n",
150+
" file = tarfile.open(MODEL_DIR / \"{}_infer.tar\".format(MODEL_NAME))\n",
151+
" res = file.extractall(MODEL_DIR)\n",
152+
" if not res:\n",
153+
" print(f'Model Extracted to \"./{MODEL_DIR}\".')\n",
154+
" else:\n",
155+
" print(\"Error Extracting the model. Please check the network.\")"
150156
]
151157
},
152158
{

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

Lines changed: 5 additions & 6 deletions
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",
@@ -532,8 +533,6 @@
532533
},
533534
"outputs": [],
534535
"source": [
535-
"import requests\n",
536-
"\n",
537536
"if not Path(\"gradio_helper.py\").exists():\n",
538537
" r = requests.get(url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/notebooks/parler-tts-text-to-speech/gradio_helper.py\")\n",
539538
" open(\"gradio_helper.py\", \"w\").write(r.text)\n",

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

Lines changed: 13 additions & 8 deletions
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-detectio.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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,19 @@
169169
"precision = \"FP16\"\n",
170170
"# The name of the model from Open Model Zoo\n",
171171
"detection_model_name = \"person-detection-0202\"\n",
172+
"download_det_model_url = f\"https://storage.openvinotoolkit.org/repositories/open_model_zoo/2023.0/models_bin/1/{detection_model_name}/{precision}/{detection_model_name}.xml\"\n",
173+
"detection_model_path = Path(base_model_dir) / detection_model_name / precision / f\"{detection_model_name}.xml\"\n",
172174
"\n",
175+
"if not detection_model_path.exists():\n",
173176
"\n",
174-
"download_det_model_url = (\n",
175-
" f\"https://storage.openvinotoolkit.org/repositories/open_model_zoo/2023.0/models_bin/1/{detection_model_name}/{precision}/{detection_model_name}.xml\"\n",
176-
")\n",
177-
"\n",
178-
"detection_model_path = download_ir_model(download_det_model_url, Path(base_model_dir) / detection_model_name / precision)\n",
177+
" download_ir_model(download_det_model_url, Path(base_model_dir) / detection_model_name / precision)\n",
179178
"\n",
180179
"reidentification_model_name = \"person-reidentification-retail-0287\"\n",
181180
"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",
181+
"reidentification_model_path = Path(base_model_dir) / reidentification_model_name / precision / f\"{reidentification_model_name}.xml\"\n",
182182
"\n",
183-
"reidentification_model_path = download_ir_model(download_reid_model_url, Path(base_model_dir) / reidentification_model_name / precision)"
183+
"if not reidentification_model_path.exists():\n",
184+
" download_ir_model(download_reid_model_url, Path(base_model_dir) / reidentification_model_name / precision)"
184185
]
185186
},
186187
{
@@ -444,7 +445,7 @@
444445
"source": [
445446
"base_file_link = \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/image/person_\"\n",
446447
"image_indices = [\"1_1.png\", \"1_2.png\", \"2_1.png\"]\n",
447-
"image_paths = [utils.download_file(base_file_link + image_index, directory=\"data\") for image_index in image_indices]\n",
448+
"image_paths = [utils.download_file(base_file_link + image_index, directory=\"data\") for image_index in image_indices if not (Path(data) / image_indices).exists()]\n",
448449
"image1, image2, image3 = [cv2.cvtColor(cv2.imread(str(image_path)), cv2.COLOR_BGR2RGB) for image_path in image_paths]\n",
449450
"\n",
450451
"# Define titles with images.\n",
@@ -700,9 +701,13 @@
700701
"USE_WEBCAM = False\n",
701702
"\n",
702703
"cam_id = 0\n",
703-
"video_file = \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/video/people.mp4\"\n",
704+
"video_url = \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/video/people.mp4\"\n",
705+
"video_file = Path(\"people.mp4\")\n",
704706
"source = cam_id if USE_WEBCAM else video_file\n",
705707
"\n",
708+
"if not USE_WEBCAM and not video_file.exists():\n",
709+
" utils.download_file(video_url)\n",
710+
"\n",
706711
"run_person_tracking(source=source, flip=USE_WEBCAM, use_popup=False)"
707712
]
708713
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,14 @@
426426
"import requests\n",
427427
"from PIL import Image\n",
428428
"\n",
429-
"url = \"https://github.com/openvinotoolkit/openvino_notebooks/assets/29454499/d5fbbd1a-d484-415c-88cb-9986625b7b11\"\n",
430-
"image = Image.open(requests.get(url, stream=True).raw)\n",
429+
"image_path = Path(\"cat.png\")\n",
430+
"\n",
431+
"if not image_path.exists():\n",
432+
" url = \"https://github.com/openvinotoolkit/openvino_notebooks/assets/29454499/d5fbbd1a-d484-415c-88cb-9986625b7b11\"\n",
433+
" image = Image.open(requests.get(url, stream=True).raw)\n",
434+
" image.save(image_path)\n",
435+
"else:\n",
436+
" image = Image.open(image_path)\n",
431437
"\n",
432438
"print(\"Question:\\n What is unusual on this picture?\")\n",
433439
"image"

notebooks/pix2struct-docvqa/pix2struct-docvqa.ipynb

Lines changed: 19 additions & 21 deletions
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",
@@ -238,14 +239,22 @@
238239
"\n",
239240
"\n",
240241
"def load_image(image_file):\n",
241-
" response = requests.get(image_file)\n",
242-
" image = Image.open(BytesIO(response.content)).convert(\"RGB\")\n",
243-
" return image\n",
244-
"\n",
245-
"\n",
242+
" if isinstance(image_file, str) and image_file.startswith(\"https://\"):\n",
243+
" response = requests.get(image_file)\n",
244+
" image = Image.open(BytesIO(response.content))\n",
245+
" else:\n",
246+
" image = Image.open(image_file)\n",
247+
" return image.convert(\"RGB\")\n",
248+
"\n",
249+
"test_image_path = Path(\"ov_docs.png\")\n",
246250
"test_image_url = \"https://github.com/openvinotoolkit/openvino_notebooks/assets/29454499/aa46ef0c-c14d-4bab-8bb7-3b22fe73f6bc\"\n",
247251
"\n",
248-
"image = load_image(test_image_url)\n",
252+
"if not test_image_path.exists():\n",
253+
" image = load_image(test_image_url)\n",
254+
" image.save(test_image_path)\n",
255+
"else:\n",
256+
" image = load_image(test_image_path)\n",
257+
"\n",
249258
"text = \"What performance hints do?\"\n",
250259
"\n",
251260
"inputs = processor(images=image, text=text, return_tensors=\"pt\")\n",
@@ -325,17 +334,6 @@
325334
"# demo.launch(server_name='your server name', server_port='server port in int')\n",
326335
"# Read more in the docs: https://gradio.app/docs/"
327336
]
328-
},
329-
{
330-
"cell_type": "code",
331-
"execution_count": null,
332-
"id": "582a1703",
333-
"metadata": {},
334-
"outputs": [],
335-
"source": [
336-
"# please uncomment and run this cell for stopping gradio interface\n",
337-
"# demo.close()"
338-
]
339337
}
340338
],
341339
"metadata": {

0 commit comments

Comments
 (0)