Skip to content

Commit 586f756

Browse files
committed
downloading model via notebook utils not omz
1 parent de82a90 commit 586f756

File tree

1 file changed

+49
-33
lines changed

1 file changed

+49
-33
lines changed

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

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@
4949
"metadata": {},
5050
"outputs": [],
5151
"source": [
52-
"%pip install pythreejs \"openvino-dev>=2023.1.0\""
52+
"%pip install -q pythreejs \"openvino-dev>=2023.1.0\"\n",
53+
"\n",
54+
"# Fetch `notebook_utils` module\n",
55+
"import urllib.request\n",
56+
"urllib.request.urlretrieve(\n",
57+
" url='https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/main/notebooks/utils/notebook_utils.py',\n",
58+
" filename='notebook_utils.py'\n",
59+
")"
5360
]
5461
},
5562
{
@@ -63,7 +70,7 @@
6370
},
6471
{
6572
"cell_type": "code",
66-
"execution_count": null,
73+
"execution_count": 2,
6774
"id": "316ad889-8514-430f-baf4-4f32abd43356",
6875
"metadata": {},
6976
"outputs": [],
@@ -72,14 +79,19 @@
7279
"import sys\n",
7380
"import time\n",
7481
"from pathlib import Path\n",
82+
"import tarfile\n",
7583
"\n",
7684
"import cv2\n",
7785
"import ipywidgets as widgets\n",
7886
"import numpy as np\n",
7987
"from IPython.display import clear_output, display\n",
8088
"import openvino as ov\n",
8189
"\n",
82-
"sys.path.append(\"../utils\")\n",
90+
"import torch\n",
91+
"import torch.onnx\n",
92+
"import torchvision.models as models\n",
93+
"from torch.autograd import Variable\n",
94+
"\n",
8395
"import notebook_utils as utils\n",
8496
"\n",
8597
"sys.path.append(\"./engine\")\n",
@@ -98,7 +110,7 @@
98110
"### Download the model\n",
99111
"[back to top ⬆️](#Table-of-contents:)\n",
100112
"\n",
101-
"We use `omz_downloader`, which is a command line tool from the `openvino-dev` package. `omz_downloader` automatically creates a directory structure and downloads the selected model."
113+
"Use the `download_file`, a function from the `notebook_utils` file. It automatically creates a directory structure and downloads the selected model. This step is skipped if the package is already downloaded and unpacked. The chosen model comes from the public directory, which means it must be converted into OpenVINO Intermediate Representation (OpenVINO IR)."
102114
]
103115
},
104116
{
@@ -109,25 +121,32 @@
109121
"outputs": [],
110122
"source": [
111123
"# directory where model will be downloaded\n",
112-
"base_model_dir = \"model\"\n",
124+
"base_model_dir = Path(\"model\")\n",
113125
"\n",
114126
"# model name as named in Open Model Zoo\n",
115-
"model_name = \"human-pose-estimation-3d-0001\"\n",
127+
"short_model_name = \"human-pose-estimation-3d\"\n",
128+
"model_name = f\"{short_model_name}-0001\"\n",
116129
"# selected precision (FP32, FP16)\n",
117130
"precision = \"FP32\"\n",
118131
"\n",
119-
"BASE_MODEL_NAME = f\"{base_model_dir}/public/{model_name}/{model_name}\"\n",
132+
"MAIN_MODEL_PATH=f\"{base_model_dir}/public/{model_name}\"\n",
133+
"BASE_MODEL_NAME = f\"{MAIN_MODEL_PATH}/{model_name}\"\n",
120134
"model_path = Path(BASE_MODEL_NAME).with_suffix(\".pth\")\n",
121135
"onnx_path = Path(BASE_MODEL_NAME).with_suffix(\".onnx\")\n",
122136
"\n",
123-
"ir_model_path = f\"model/public/{model_name}/{precision}/{model_name}.xml\"\n",
124-
"model_weights_path = f\"model/public/{model_name}/{precision}/{model_name}.bin\"\n",
137+
"archive_name=Path(f\"{short_model_name}.tar.gz\")\n",
138+
"model_url = f\"https://storage.openvinotoolkit.org/repositories/open_model_zoo/public/2022.1/{model_name}/{archive_name}\"\n",
139+
"\n",
140+
"downloaded_model_path= Path(MAIN_MODEL_PATH) / archive_name\n",
141+
"if not downloaded_model_path.exists():\n",
142+
" utils.download_file(model_url, downloaded_model_path.name, downloaded_model_path.parent)\n",
143+
"\n",
144+
"ir_model_path = Path(f\"model/public/{model_name}/{precision}/{model_name}.xml\")\n",
145+
"model_weights_path = Path(f\"model/public/{model_name}/{precision}/{model_name}.bin\")\n",
125146
"\n",
126147
"if not model_path.exists():\n",
127-
" download_command = (\n",
128-
" f\"omz_downloader \" f\"--name {model_name} \" f\"--output_dir {base_model_dir}\"\n",
129-
" )\n",
130-
" ! $download_command"
148+
" with tarfile.open(downloaded_model_path) as file:\n",
149+
" file.extractall(MAIN_MODEL_PATH)"
131150
]
132151
},
133152
{
@@ -145,7 +164,9 @@
145164
"cell_type": "code",
146165
"execution_count": null,
147166
"id": "c9bdfdee-c2ef-4710-96c1-8a6a896a8cba",
148-
"metadata": {},
167+
"metadata": {
168+
"scrolled": true
169+
},
149170
"outputs": [],
150171
"source": [
151172
"if not onnx_path.exists():\n",
@@ -204,7 +225,7 @@
204225
},
205226
{
206227
"cell_type": "code",
207-
"execution_count": null,
228+
"execution_count": 6,
208229
"id": "92a04102-aebf-4976-874b-b98dca97ec48",
209230
"metadata": {},
210231
"outputs": [],
@@ -257,7 +278,7 @@
257278
},
258279
{
259280
"cell_type": "code",
260-
"execution_count": null,
281+
"execution_count": 8,
261282
"id": "08f8055b-a6cf-4003-8232-6f73a86d6034",
262283
"metadata": {},
263284
"outputs": [],
@@ -306,7 +327,7 @@
306327
},
307328
{
308329
"cell_type": "code",
309-
"execution_count": null,
330+
"execution_count": 9,
310331
"id": "22fd3e08-ed3b-44ac-bd07-4a80130d6681",
311332
"metadata": {},
312333
"outputs": [],
@@ -394,7 +415,7 @@
394415
},
395416
{
396417
"cell_type": "code",
397-
"execution_count": null,
418+
"execution_count": 10,
398419
"id": "3be526d0-75ad-4bd1-85b1-ca8185eca918",
399420
"metadata": {
400421
"tags": []
@@ -587,7 +608,7 @@
587608
},
588609
{
589610
"cell_type": "code",
590-
"execution_count": null,
611+
"execution_count": 11,
591612
"id": "3f82e298-5912-48c7-90b5-339aea3c177d",
592613
"metadata": {
593614
"tags": []
@@ -603,6 +624,14 @@
603624
"\n",
604625
"run_pose_estimation(source=source, flip=isinstance(source, int), use_popup=False)"
605626
]
627+
},
628+
{
629+
"cell_type": "code",
630+
"execution_count": null,
631+
"id": "e3c77b7c-5211-4715-ad48-4ec38a82941c",
632+
"metadata": {},
633+
"outputs": [],
634+
"source": []
606635
}
607636
],
608637
"metadata": {
@@ -621,20 +650,7 @@
621650
"name": "python",
622651
"nbconvert_exporter": "python",
623652
"pygments_lexer": "ipython3",
624-
"version": "3.8.10"
625-
},
626-
"openvino_notebooks": {
627-
"imageUrl": "https://github.com/openvinotoolkit/openvino_notebooks/blob/main/notebooks/406-3D-pose-estimation-webcam/406-3D-pose-estimation.gif?raw=true",
628-
"tags": {
629-
"categories": [
630-
"Live Demos"
631-
],
632-
"libraries": [],
633-
"other": [],
634-
"tasks": [
635-
"Pose Estimation"
636-
]
637-
}
653+
"version": "3.11.5"
638654
},
639655
"widgets": {
640656
"application/vnd.jupyter.widget-state+json": {

0 commit comments

Comments
 (0)