Skip to content

Commit

Permalink
fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
sbalandi committed Sep 19, 2024
1 parent a598335 commit c5458c9
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 41 deletions.
20 changes: 15 additions & 5 deletions .ci/patch_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ def disable_skip_ext(nb, notebook_path, test_device=""):
skip_for_device = None if test_device else False
for cell in nb["cells"]:
if test_device is not None and skip_for_device is None:
if 'skip_for_device = "{}" in device.value'.format(test_device.upper()) in cell["source"] and (
"to_quantize = widgets.Checkbox(value=not skip_for_device" in cell["source"]
or "to_quantize = quantization_widget(not skip_for_device" in cell["source"]
if (
'skip_for_device = "{}" in device.value'.format(test_device.upper()) in cell["source"]
and (
"to_quantize = widgets.Checkbox(value=not skip_for_device" in cell["source"]
or "to_quantize = quantization_widget(not skip_for_device" in cell["source"]
)
or ("to_quantize = quantization_widget(False" in cell["source"])
):
skip_for_device = True

Expand Down Expand Up @@ -152,7 +156,11 @@ def patch_notebooks(notebooks_dir, test_device="", skip_ov_install=False):
if test_device and (DEVICE_WIDGET in cell["source"] or DEVICE_WIDGET_NEW in cell["source"]):
device_found = True
if not DEVICE_WIDGET_NEW in cell["source"]:
cell["source"] = re.sub(r"value=.*,", f"value='{test_device.upper()}',", cell["source"])
cell["source"] = re.sub(
r"value=.*,",
f"value='{test_device.upper()}',",
cell["source"],
)
cell["source"] = re.sub(
r"options=",
f"options=['{test_device.upper()}'] + ",
Expand All @@ -161,7 +169,9 @@ def patch_notebooks(notebooks_dir, test_device="", skip_ov_install=False):
print(f"Replaced testing device to {test_device}")
else:
cell["source"] = re.sub(
r"device_widget\(.*\)", f"device_widget(default='{test_device.upper()}', added=['{test_device.upper()}'])", cell["source"]
r"device_widget\(.*\)",
f"device_widget(default='{test_device.upper()}', added=['{test_device.upper()}'])",
cell["source"],
)
replace_dict = cell.get("metadata", {}).get("test_replace")
if replace_dict is not None:
Expand Down
37 changes: 28 additions & 9 deletions notebooks/segment-anything/segment-anything-2-image.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@
"[back to top ⬆️](#Table-of-contents:)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c60c39ac",
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"from pathlib import Path\n",
"\n",
"r = requests.get(\n",
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/pip_helper.py\",\n",
")\n",
"open(\"pip_helper.py\", \"w\").write(r.text)"
]
},
{
"cell_type": "code",
"execution_count": 1,
Expand Down Expand Up @@ -107,19 +123,20 @@
],
"source": [
"import platform\n",
"from pip_helper import pip_install\n",
"\n",
"%pip install -q \"gradio>=4.13\" \"openvino>=2024.3.0\" \"nncf>=2.12\" \"torch>=2.3.1\" \"torchvision>=0.18.1\" opencv-python tqdm numpy --extra-index-url https://download.pytorch.org/whl/cpu\n",
"%pip install \"iopath>=0.1.10\" \"pillow>=9.4.0\" \"hydra-core>=1.3.2\"\n",
"pip_install(\"-q\", \"gradio>=4.19\", \"openvino>=2024.3.0\", \"nncf>=2.12\", \"torch>=2.3.1\", \"torchvision>=0.18.1\", \"opencv-python\", \"tqdm\", \"numpy\", \"--extra-index-url\", \"https://download.pytorch.org/whl/cpu\")\n",
"pip_install(\"-q\", \"iopath>=0.1.10\", \"pillow>=9.4.0\", \"hydra-core>=1.3.2\")\n",
"\n",
"if platform.system() != \"Windows\":\n",
" %pip install -q \"matplotlib>=3.4\"\n",
" pip_install(\"-q\", \"matplotlib>=3.4\")\n",
"else:\n",
" %pip install -q \"matplotlib>=3.4,<3.7\""
" pip_install(\"-q\", \"matplotlib>=3.4,<3.7\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"id": "662e0f0d",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -160,14 +177,17 @@
],
"source": [
"import sys\n",
"import os\n",
"\n",
"sam2_dir = Path(\"segment-anything-2\")\n",
"\n",
"if not sam2_dir.exists():\n",
" !git clone https://github.com/facebookresearch/segment-anything-2.git\n",
" exit_code = os.system(\"git clone https://github.com/facebookresearch/segment-anything-2.git\")\n",
" if exit_code != 0:\n",
" raise Exception(\"Failed to clone the repository!\")\n",
"\n",
"# append to sys.path so that modules from the repo could be imported\n",
"sys.path.append(str(sam2_dir))\n",
"sys.path.insert(0, str(sam2_dir.resolve()))\n",
"\n",
"%env SAM2_BUILD_CUDA=0"
]
Expand Down Expand Up @@ -1442,8 +1462,7 @@
"source": [
"from notebook_utils import quantization_widget\n",
"\n",
"skip_for_device = \"CPU\" in device.value\n",
"to_quantize = quantization_widget(not skip_for_device)\n",
"to_quantize = quantization_widget(False)\n",
"to_quantize"
]
},
Expand Down
62 changes: 35 additions & 27 deletions notebooks/segment-anything/segment-anything-2-video.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -74,39 +74,47 @@
{
"cell_type": "code",
"execution_count": 1,
"id": "133014d4-6766-48c5-94b6-9c78b9dfe309",
"id": "5e135f71",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Note: you may need to restart the kernel to use updated packages.\n",
"Requirement already satisfied: iopath>=0.1.10 in /home/labuser/work/notebook/sam2/lib/python3.10/site-packages (0.1.10)\n",
"Requirement already satisfied: pillow>=9.4.0 in /home/labuser/work/notebook/sam2/lib/python3.10/site-packages (10.4.0)\n",
"Requirement already satisfied: hydra-core>=1.3.2 in /home/labuser/work/notebook/sam2/lib/python3.10/site-packages (1.3.2)\n",
"Requirement already satisfied: tqdm in /home/labuser/work/notebook/sam2/lib/python3.10/site-packages (from iopath>=0.1.10) (4.66.5)\n",
"Requirement already satisfied: portalocker in /home/labuser/work/notebook/sam2/lib/python3.10/site-packages (from iopath>=0.1.10) (2.10.1)\n",
"Requirement already satisfied: typing-extensions in /home/labuser/work/notebook/sam2/lib/python3.10/site-packages (from iopath>=0.1.10) (4.12.2)\n",
"Requirement already satisfied: packaging in /home/labuser/work/notebook/sam2/lib/python3.10/site-packages (from hydra-core>=1.3.2) (24.1)\n",
"Requirement already satisfied: omegaconf<2.4,>=2.2 in /home/labuser/work/notebook/sam2/lib/python3.10/site-packages (from hydra-core>=1.3.2) (2.3.0)\n",
"Requirement already satisfied: antlr4-python3-runtime==4.9.* in /home/labuser/work/notebook/sam2/lib/python3.10/site-packages (from hydra-core>=1.3.2) (4.9.3)\n",
"Requirement already satisfied: PyYAML>=5.1.0 in /home/labuser/work/notebook/sam2/lib/python3.10/site-packages (from omegaconf<2.4,>=2.2->hydra-core>=1.3.2) (6.0.2)\n",
"Note: you may need to restart the kernel to use updated packages.\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
"data": {
"text/plain": [
"332"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import requests\n",
"from pathlib import Path\n",
"\n",
"r = requests.get(\n",
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/pip_helper.py\",\n",
")\n",
"open(\"pip_helper.py\", \"w\").write(r.text)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "133014d4-6766-48c5-94b6-9c78b9dfe309",
"metadata": {},
"outputs": [],
"source": [
"import platform\n",
"from pip_helper import pip_install\n",
"\n",
"%pip install -q \"gradio>=4.13\" \"openvino>=2024.3.0\" \"nncf>=2.12\" \"torch>=2.3.1\" \"torchvision>=0.18.1\" opencv-python tqdm numpy --extra-index-url https://download.pytorch.org/whl/cpu\n",
"%pip install \"iopath>=0.1.10\" \"pillow>=9.4.0\" \"hydra-core>=1.3.2\"\n",
"pip_install(\"-q\", \"gradio>=4.19\", \"openvino>=2024.3.0\", \"nncf>=2.12\", \"torch>=2.3.1\", \"torchvision>=0.18.1\", \"opencv-python\", \"tqdm\", \"numpy\", \"--extra-index-url\", \"https://download.pytorch.org/whl/cpu\")\n",
"pip_install(\"-q\", \"iopath>=0.1.10\", \"pillow>=9.4.0\", \"hydra-core>=1.3.2\")\n",
"\n",
"if platform.system() != \"Windows\":\n",
" %pip install -q \"matplotlib>=3.4\"\n",
" pip_install(\"-q\", \"matplotlib>=3.4\")\n",
"else:\n",
" %pip install -q \"matplotlib>=3.4,<3.7\""
" pip_install(\"-q\", \"matplotlib>=3.4,<3.7\")"
]
},
{
Expand All @@ -116,9 +124,6 @@
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"from pathlib import Path\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",
Expand Down Expand Up @@ -152,14 +157,17 @@
],
"source": [
"import sys\n",
"import os\n",
"\n",
"sam2_dir = Path(\"segment-anything-2\")\n",
"\n",
"if not sam2_dir.exists():\n",
" !git clone https://github.com/facebookresearch/segment-anything-2.git\n",
" exit_code = os.system(\"git clone https://github.com/facebookresearch/segment-anything-2.git\")\n",
" if exit_code != 0:\n",
" raise Exception(\"Failed to clone the repository!\")\n",
"\n",
"# append to sys.path so that modules from the repo could be imported\n",
"sys.path.append(str(sam2_dir))\n",
"sys.path.insert(0, str(sam2_dir.resolve()))\n",
"\n",
"%env SAM2_BUILD_CUDA=0"
]
Expand Down

0 comments on commit c5458c9

Please sign in to comment.