Skip to content

offline experience part 3 #2706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .ci/skipped_notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,4 +569,8 @@
- macos-13
- ubuntu-20.04
- ubuntu-22.04
- windows-2019
- windows-2019
- notebook: notebooks/paddle-to-openvino/paddle-to-openvino-classification.ipynb
skips:
- python:
- '3.12'
26 changes: 17 additions & 9 deletions notebooks/paddle-ocr-webcam/paddle-ocr-webcam.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -645,14 +645,19 @@
],
"source": [
"# Download font and a character dictionary for printing OCR results.\n",
"font_path = utils.download_file(\n",
" url=\"https://raw.githubusercontent.com/Halfish/lstm-ctc-ocr/master/fonts/simfang.ttf\",\n",
" directory=\"fonts\",\n",
")\n",
"character_dictionary_path = utils.download_file(\n",
" url=\"https://raw.githubusercontent.com/WenmuZhou/PytorchOCR/master/torchocr/datasets/alphabets/ppocr_keys_v1.txt\",\n",
" directory=\"fonts\",\n",
")"
"font_path = Path(\"fonts/simfang.ttf\")\n",
"character_dictionary_path = Path(\"fonts/ppocr_keys_v1.txt\")\n",
"\n",
"if not font_path.exists():\n",
" utils.download_file(\n",
" url=\"https://raw.githubusercontent.com/Halfish/lstm-ctc-ocr/master/fonts/simfang.ttf\",\n",
" directory=\"fonts\",\n",
" )\n",
"if not character_dictionary_path.exists():\n",
" utils.download_file(\n",
" url=\"https://raw.githubusercontent.com/WenmuZhou/PytorchOCR/master/torchocr/datasets/alphabets/ppocr_keys_v1.txt\",\n",
" directory=\"fonts\",\n",
" )"
]
},
{
Expand Down Expand Up @@ -836,7 +841,10 @@
"USE_WEBCAM = False\n",
"\n",
"cam_id = 0\n",
"video_file = \"https://raw.githubusercontent.com/yoyowz/classification/master/images/test.mp4\"\n",
"video_file = Path(\"test.mp4\")\n",
"\n",
"if not USE_WEBCAM and not video_file.exists():\n",
" utils.download_file(\"https://raw.githubusercontent.com/yoyowz/classification/master/images/test.mp4\")\n",
"\n",
"source = cam_id if USE_WEBCAM else video_file\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@
"# Fetch `notebook_utils` module\n",
"import requests\n",
"\n",
"r = requests.get(\n",
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
")\n",
"if not Path(\"notebook_utils.py\").exists():\n",
" r = requests.get(\n",
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
" )\n",
"\n",
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
"\n",
"from notebook_utils import download_file, device_widget\n",
"\n",
Expand Down Expand Up @@ -133,25 +134,30 @@
],
"source": [
"# Download the image from the openvino_notebooks storage\n",
"img = download_file(\n",
" \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/image/coco_close.png\",\n",
" directory=\"data\",\n",
")\n",
"img = Path(\"data/coco_close.png\")\n",
"\n",
"if not img.exists():\n",
" download_file(\n",
" \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/image/coco_close.png\",\n",
" directory=\"data\",\n",
" )\n",
"\n",
"IMAGE_FILENAME = img.as_posix()\n",
"\n",
"MODEL_NAME = \"MobileNetV3_large_x1_0\"\n",
"MODEL_DIR = Path(\"model\")\n",
"if not MODEL_DIR.exists():\n",
" MODEL_DIR.mkdir()\n",
"MODEL_URL = \"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/{}_infer.tar\".format(MODEL_NAME)\n",
"download_file(MODEL_URL, directory=MODEL_DIR)\n",
"file = tarfile.open(MODEL_DIR / \"{}_infer.tar\".format(MODEL_NAME))\n",
"res = file.extractall(MODEL_DIR)\n",
"if not res:\n",
" print(f'Model Extracted to \"./{MODEL_DIR}\".')\n",
"else:\n",
" print(\"Error Extracting the model. Please check the network.\")"
"\n",
"if not (MODEL_DIR / \"{}_infer\".format(MODEL_NAME)).exists():\n",
" MODEL_URL = \"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/{}_infer.tar\".format(MODEL_NAME)\n",
" download_file(MODEL_URL, directory=MODEL_DIR)\n",
" file = tarfile.open(MODEL_DIR / \"{}_infer.tar\".format(MODEL_NAME))\n",
" res = file.extractall(MODEL_DIR)\n",
" if not res:\n",
" print(f'Model Extracted to \"./{MODEL_DIR}\".')\n",
" else:\n",
" print(\"Error Extracting the model. Please check the network.\")"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,11 @@
"source": [
"import requests\n",
"\n",
"r = requests.get(\n",
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
")\n",
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
"if not Path(\"notebook_utils.py\").exists():\n",
" r = requests.get(\n",
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
" )\n",
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
"\n",
"from notebook_utils import device_widget\n",
"\n",
Expand Down Expand Up @@ -537,8 +538,6 @@
},
"outputs": [],
"source": [
"import requests\n",
"\n",
"if not Path(\"gradio_helper.py\").exists():\n",
" r = requests.get(url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/notebooks/parler-tts-text-to-speech/gradio_helper.py\")\n",
" open(\"gradio_helper.py\", \"w\").write(r.text)\n",
Expand Down
21 changes: 13 additions & 8 deletions notebooks/person-counting-webcam/person-counting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,24 @@
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"\n",
"if not Path(\"notebook_utils.py\").exists():\n",
" r = requests.get(\n",
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
" )\n",
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
"\n",
"from notebook_utils import download_file\n",
"\n",
"WEBCAM_INFERENCE = False\n",
"\n",
"if WEBCAM_INFERENCE:\n",
" VIDEO_SOURCE = 0 # Webcam\n",
"else:\n",
" VIDEO_SOURCE = \"https://storage.openvinotoolkit.org/data/test_data/videos/people-detection.mp4\""
" VIDEO_SOURCE = Path(\"people-detection.mp4\")\n",
" if not VIDEO_SOURCE.exists():\n",
" download_file(\"https://storage.openvinotoolkit.org/data/test_data/videos/people-detection.mp4\")"
]
},
{
Expand Down Expand Up @@ -316,13 +328,6 @@
}
],
"source": [
"import requests\n",
"\n",
"r = requests.get(\n",
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
")\n",
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
"\n",
"from notebook_utils import device_widget\n",
"\n",
"device = device_widget()\n",
Expand Down
23 changes: 16 additions & 7 deletions notebooks/person-tracking-webcam/person-tracking.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@
"outputs": [],
"source": [
"# Import local modules\n",
"import requests\n",
"\n",
"if not Path(\"./notebook_utils.py\").exists():\n",
" # Fetch `notebook_utils` module\n",
" import requests\n",
"\n",
" r = requests.get(\n",
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
Expand Down Expand Up @@ -174,18 +174,21 @@
"precision = \"FP16\"\n",
"# The name of the model from Open Model Zoo\n",
"detection_model_name = \"person-detection-0202\"\n",
"\n",
"\n",
"download_det_model_url = (\n",
" f\"https://storage.openvinotoolkit.org/repositories/open_model_zoo/2023.0/models_bin/1/{detection_model_name}/{precision}/{detection_model_name}.xml\"\n",
")\n",
"detection_model_path = Path(base_model_dir) / detection_model_name / precision / f\"{detection_model_name}.xml\"\n",
"\n",
"detection_model_path = download_ir_model(download_det_model_url, Path(base_model_dir) / detection_model_name / precision)\n",
"if not detection_model_path.exists():\n",
"\n",
" download_ir_model(download_det_model_url, Path(base_model_dir) / detection_model_name / precision)\n",
"\n",
"reidentification_model_name = \"person-reidentification-retail-0287\"\n",
"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",
"reidentification_model_path = Path(base_model_dir) / reidentification_model_name / precision / f\"{reidentification_model_name}.xml\"\n",
"\n",
"reidentification_model_path = download_ir_model(download_reid_model_url, Path(base_model_dir) / reidentification_model_name / precision)"
"if not reidentification_model_path.exists():\n",
" download_ir_model(download_reid_model_url, Path(base_model_dir) / reidentification_model_name / precision)"
]
},
{
Expand Down Expand Up @@ -449,7 +452,9 @@
"source": [
"base_file_link = \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/image/person_\"\n",
"image_indices = [\"1_1.png\", \"1_2.png\", \"2_1.png\"]\n",
"image_paths = [utils.download_file(base_file_link + image_index, directory=\"data\") for image_index in image_indices]\n",
"image_paths = [\n",
" utils.download_file(base_file_link + image_index, directory=\"data\") for image_index in image_indices if not (Path(\"data\") / image_index).exists()\n",
"]\n",
"image1, image2, image3 = [cv2.cvtColor(cv2.imread(str(image_path)), cv2.COLOR_BGR2RGB) for image_path in image_paths]\n",
"\n",
"# Define titles with images.\n",
Expand Down Expand Up @@ -705,9 +710,13 @@
"USE_WEBCAM = False\n",
"\n",
"cam_id = 0\n",
"video_file = \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/video/people.mp4\"\n",
"video_url = \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/video/people.mp4\"\n",
"video_file = Path(\"people.mp4\")\n",
"source = cam_id if USE_WEBCAM else video_file\n",
"\n",
"if not USE_WEBCAM and not video_file.exists():\n",
" utils.download_file(video_url)\n",
"\n",
"run_person_tracking(source=source, flip=USE_WEBCAM, use_popup=False)"
]
}
Expand Down
10 changes: 8 additions & 2 deletions notebooks/phi-3-vision/phi-3-vision.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,14 @@
"import requests\n",
"from PIL import Image\n",
"\n",
"url = \"https://github.com/openvinotoolkit/openvino_notebooks/assets/29454499/d5fbbd1a-d484-415c-88cb-9986625b7b11\"\n",
"image = Image.open(requests.get(url, stream=True).raw)\n",
"image_path = Path(\"cat.png\")\n",
"\n",
"if not image_path.exists():\n",
" url = \"https://github.com/openvinotoolkit/openvino_notebooks/assets/29454499/d5fbbd1a-d484-415c-88cb-9986625b7b11\"\n",
" image = Image.open(requests.get(url, stream=True).raw)\n",
" image.save(image_path)\n",
"else:\n",
" image = Image.open(image_path)\n",
"\n",
"print(\"Question:\\n What is unusual on this picture?\")\n",
"image"
Expand Down
37 changes: 18 additions & 19 deletions notebooks/pix2struct-docvqa/pix2struct-docvqa.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,11 @@
"source": [
"import requests\n",
"\n",
"r = requests.get(\n",
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
")\n",
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
"if not Path(\"notebook_utils.py\").exists():\n",
" r = requests.get(\n",
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
" )\n",
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
"\n",
"from notebook_utils import device_widget\n",
"\n",
Expand Down Expand Up @@ -243,14 +244,23 @@
"\n",
"\n",
"def load_image(image_file):\n",
" response = requests.get(image_file)\n",
" image = Image.open(BytesIO(response.content)).convert(\"RGB\")\n",
" return image\n",
" if isinstance(image_file, str) and image_file.startswith(\"https://\"):\n",
" response = requests.get(image_file)\n",
" image = Image.open(BytesIO(response.content))\n",
" else:\n",
" image = Image.open(image_file)\n",
" return image.convert(\"RGB\")\n",
"\n",
"\n",
"test_image_path = Path(\"ov_docs.png\")\n",
"test_image_url = \"https://github.com/openvinotoolkit/openvino_notebooks/assets/29454499/aa46ef0c-c14d-4bab-8bb7-3b22fe73f6bc\"\n",
"\n",
"image = load_image(test_image_url)\n",
"if not test_image_path.exists():\n",
" image = load_image(test_image_url)\n",
" image.save(test_image_path)\n",
"else:\n",
" image = load_image(test_image_path)\n",
"\n",
"text = \"What performance hints do?\"\n",
"\n",
"inputs = processor(images=image, text=text, return_tensors=\"pt\")\n",
Expand Down Expand Up @@ -330,17 +340,6 @@
"# demo.launch(server_name='your server name', server_port='server port in int')\n",
"# Read more in the docs: https://gradio.app/docs/"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "582a1703",
"metadata": {},
"outputs": [],
"source": [
"# please uncomment and run this cell for stopping gradio interface\n",
"# demo.close()"
]
}
],
"metadata": {
Expand Down
Loading
Loading