diff --git a/notebooks/controlnet-stable-diffusion/controlnet-stable-diffusion.ipynb b/notebooks/controlnet-stable-diffusion/controlnet-stable-diffusion.ipynb index 108f9dafadd..a85b63c213a 100644 --- a/notebooks/controlnet-stable-diffusion/controlnet-stable-diffusion.ipynb +++ b/notebooks/controlnet-stable-diffusion/controlnet-stable-diffusion.ipynb @@ -117,16 +117,31 @@ }, "outputs": [], "source": [ - "%pip install -q --extra-index-url https://download.pytorch.org/whl/cpu \"torch>=2.1\" \"torchvision\"\n", - "%pip install -q \"diffusers>=0.14.0\" \"matplotlib>=3.4\" \"transformers>=4.30.2\" \"controlnet-aux>=0.0.6\" \"gradio>=3.36\" --extra-index-url https://download.pytorch.org/whl/cpu\n", - "%pip install -q \"openvino>=2023.1.0\" \"datasets>=2.14.6\" \"nncf>=2.7.0\"\n", - "\n", "import requests\n", + "from pathlib import Path\n", + "\n", + "utility_files = [\"notebook_utils.py\", \"pip_helper.py\"]\n", + "\n", + "for utility in utility_files:\n", + " if not Path(utility).exists():\n", + " r = requests.get(f\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/{utility}\")\n", + " with open(utility, \"w\") as f:\n", + " f.write(r.text)\n", "\n", - "r = requests.get(\n", - " url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n", + "\n", + "from pip_helper import pip_install\n", + "\n", + "pip_install(\"torch>=2.1\", \"torchvision\", \"--extra-index-url\", \"https://download.pytorch.org/whl/cpu\")\n", + "pip_install(\n", + " \"diffusers>=0.14.0\",\n", + " \"matplotlib>=3.4\",\n", + " \"transformers>=4.30.2\",\n", + " \"controlnet-aux>=0.0.6\",\n", + " \"gradio>=3.36\",\n", + " \"--extra-index-url\",\n", + " \"https://download.pytorch.org/whl/cpu\",\n", ")\n", - "open(\"notebook_utils.py\", \"w\").write(r.text)" + "pip_install(\"openvino>=2023.1.0\", \"datasets>=2.14.6\", \"nncf>=2.7.0\", \"opencv-python\")" ] }, { @@ -221,14 +236,18 @@ } ], "source": [ - "import requests\n", "from PIL import Image\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", - "\n", + "from notebook_utils import download_file\n", "\n", "example_url = \"https://user-images.githubusercontent.com/29454499/224540208-c172c92a-9714-4a7b-857a-b1e54b4d4791.jpg\"\n", - "img = Image.open(requests.get(example_url, stream=True).raw)\n", + "\n", + "image_path = Path(\"example_image.jpg\")\n", + "if not image_path.exists():\n", + " download_file(image_path, filename=\"example_image.jpg\")\n", + "\n", + "img = Image.open(image_path)\n", "pose = pose_estimator(img)\n", "\n", "\n", @@ -1533,10 +1552,12 @@ "# Fetch `skip_kernel_extension` module\n", "import requests\n", "\n", - "r = requests.get(\n", - " url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/skip_kernel_extension.py\",\n", - ")\n", - "open(\"skip_kernel_extension.py\", \"w\").write(r.text)\n", + "\n", + "if not Path(\"skip_kernel_extension.py\").exists():\n", + " r = requests.get(\n", + " url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/skip_kernel_extension.py\",\n", + " )\n", + " open(\"skip_kernel_extension.py\", \"w\").write(r.text)\n", "\n", "int8_pipe = None\n", "\n", diff --git a/notebooks/sam2-video-segmentation/segment-anything-2-video.ipynb b/notebooks/sam2-video-segmentation/segment-anything-2-video.ipynb index 62bc5a1fde1..9fb9c965909 100644 --- a/notebooks/sam2-video-segmentation/segment-anything-2-video.ipynb +++ b/notebooks/sam2-video-segmentation/segment-anything-2-video.ipynb @@ -73,35 +73,15 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "id": "133014d4-6766-48c5-94b6-9c78b9dfe309", "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/openvino_notebooks/.venv/lib/python3.10/site-packages (0.1.10)\n", - "Requirement already satisfied: pillow>=9.4.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (10.4.0)\n", - "Requirement already satisfied: hydra-core>=1.3.2 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (1.3.2)\n", - "Requirement already satisfied: tqdm in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from iopath>=0.1.10) (4.66.4)\n", - "Requirement already satisfied: typing-extensions in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from iopath>=0.1.10) (4.12.2)\n", - "Requirement already satisfied: portalocker in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from iopath>=0.1.10) (2.10.1)\n", - "Requirement already satisfied: omegaconf<2.4,>=2.2 in /home/labuser/work/notebook/openvino_notebooks/.venv/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/openvino_notebooks/.venv/lib/python3.10/site-packages (from hydra-core>=1.3.2) (4.9.3)\n", - "Requirement already satisfied: packaging in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from hydra-core>=1.3.2) (24.1)\n", - "Requirement already satisfied: PyYAML>=5.1.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from omegaconf<2.4,>=2.2->hydra-core>=1.3.2) (6.0.1)\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" - ] - } - ], + "outputs": [], "source": [ - "%pip install -q \"gradio>=4.13\" \"openvino>=2024.4.0\" \"nncf>=2.13\" \"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 \"gradio>=4.13\" \"openvino>=2024.4.0\" \"nncf>=2.13\" \"torch>=2.3.1\" \"torchvision>=0.18.1\" 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", "\n", - "%pip install -q \"matplotlib>=3.4\"" + "%pip install -q \"matplotlib>=3.4\" \"opencv-python\"" ] }, { @@ -164,170 +144,7 @@ "execution_count": null, "id": "4490f645", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Found existing installation: SAM-2 1.0\n", - "Uninstalling SAM-2-1.0:\n", - " Successfully uninstalled SAM-2-1.0\n", - "Note: you may need to restart the kernel to use updated packages.\n", - "/home/labuser/work/notebook/openvino_notebooks/notebooks/segment-anything/sam2\n", - "HEAD is now at 0db838b Merge pull request #205 from facebookresearch/haitham/fix_hf_image_predictor\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages/IPython/core/magics/osm.py:417: UserWarning: This is now an optional IPython functionality, setting dhist requires you to install the `pickleshare` library.\n", - " self.shell.db['dhist'] = compress_dhist(dhist)[-100:]\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Obtaining file:///home/labuser/work/notebook/openvino_notebooks/notebooks/segment-anything/sam2\n", - " Installing build dependencies ... \u001b[?25ldone\n", - "\u001b[?25h Checking if build backend supports build_editable ... \u001b[?25ldone\n", - "\u001b[?25h Getting requirements to build editable ... \u001b[?25ldone\n", - "\u001b[?25h Preparing editable metadata (pyproject.toml) ... \u001b[?25ldone\n", - "\u001b[?25hRequirement already satisfied: torch>=2.3.1 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from SAM-2==1.0) (2.4.0+cpu)\n", - "Requirement already satisfied: torchvision>=0.18.1 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from SAM-2==1.0) (0.19.0+cpu)\n", - "Requirement already satisfied: numpy>=1.24.4 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from SAM-2==1.0) (1.26.4)\n", - "Requirement already satisfied: tqdm>=4.66.1 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from SAM-2==1.0) (4.66.4)\n", - "Requirement already satisfied: hydra-core>=1.3.2 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from SAM-2==1.0) (1.3.2)\n", - "Requirement already satisfied: iopath>=0.1.10 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from SAM-2==1.0) (0.1.10)\n", - "Requirement already satisfied: pillow>=9.4.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from SAM-2==1.0) (10.4.0)\n", - "Requirement already satisfied: matplotlib>=3.9.1 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from SAM-2==1.0) (3.9.1)\n", - "Requirement already satisfied: jupyter>=1.0.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from SAM-2==1.0) (1.0.0)\n", - "Requirement already satisfied: opencv-python>=4.7.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from SAM-2==1.0) (4.10.0.84)\n", - "Requirement already satisfied: omegaconf<2.4,>=2.2 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from hydra-core>=1.3.2->SAM-2==1.0) (2.3.0)\n", - "Requirement already satisfied: antlr4-python3-runtime==4.9.* in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from hydra-core>=1.3.2->SAM-2==1.0) (4.9.3)\n", - "Requirement already satisfied: packaging in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from hydra-core>=1.3.2->SAM-2==1.0) (24.1)\n", - "Requirement already satisfied: typing-extensions in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from iopath>=0.1.10->SAM-2==1.0) (4.12.2)\n", - "Requirement already satisfied: portalocker in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from iopath>=0.1.10->SAM-2==1.0) (2.10.1)\n", - "Requirement already satisfied: notebook in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyter>=1.0.0->SAM-2==1.0) (7.2.1)\n", - "Requirement already satisfied: qtconsole in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyter>=1.0.0->SAM-2==1.0) (5.5.2)\n", - "Requirement already satisfied: jupyter-console in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyter>=1.0.0->SAM-2==1.0) (6.6.3)\n", - "Requirement already satisfied: nbconvert in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyter>=1.0.0->SAM-2==1.0) (7.16.4)\n", - "Requirement already satisfied: ipykernel in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyter>=1.0.0->SAM-2==1.0) (6.29.5)\n", - "Requirement already satisfied: ipywidgets in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyter>=1.0.0->SAM-2==1.0) (8.1.3)\n", - "Requirement already satisfied: contourpy>=1.0.1 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from matplotlib>=3.9.1->SAM-2==1.0) (1.2.1)\n", - "Requirement already satisfied: cycler>=0.10 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from matplotlib>=3.9.1->SAM-2==1.0) (0.12.1)\n", - "Requirement already satisfied: fonttools>=4.22.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from matplotlib>=3.9.1->SAM-2==1.0) (4.53.1)\n", - "Requirement already satisfied: kiwisolver>=1.3.1 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from matplotlib>=3.9.1->SAM-2==1.0) (1.4.5)\n", - "Requirement already satisfied: pyparsing>=2.3.1 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from matplotlib>=3.9.1->SAM-2==1.0) (3.1.2)\n", - "Requirement already satisfied: python-dateutil>=2.7 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from matplotlib>=3.9.1->SAM-2==1.0) (2.9.0.post0)\n", - "Requirement already satisfied: filelock in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (3.15.4)\n", - "Requirement already satisfied: sympy in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (1.13.1)\n", - "Requirement already satisfied: networkx in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (3.3)\n", - "Requirement already satisfied: jinja2 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (3.1.4)\n", - "Requirement already satisfied: fsspec in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from torch>=2.3.1->SAM-2==1.0) (2024.5.0)\n", - "Requirement already satisfied: PyYAML>=5.1.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from omegaconf<2.4,>=2.2->hydra-core>=1.3.2->SAM-2==1.0) (6.0.1)\n", - "Requirement already satisfied: six>=1.5 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib>=3.9.1->SAM-2==1.0) (1.16.0)\n", - "Requirement already satisfied: comm>=0.1.1 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (0.2.2)\n", - "Requirement already satisfied: debugpy>=1.6.5 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (1.8.2)\n", - "Requirement already satisfied: ipython>=7.23.1 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (8.26.0)\n", - "Requirement already satisfied: jupyter-client>=6.1.12 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (8.6.2)\n", - "Requirement already satisfied: jupyter-core!=5.0.*,>=4.12 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (5.7.2)\n", - "Requirement already satisfied: matplotlib-inline>=0.1 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (0.1.7)\n", - "Requirement already satisfied: nest-asyncio in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (1.6.0)\n", - "Requirement already satisfied: psutil in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (6.0.0)\n", - "Requirement already satisfied: pyzmq>=24 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (26.0.3)\n", - "Requirement already satisfied: tornado>=6.1 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (6.4.1)\n", - "Requirement already satisfied: traitlets>=5.4.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from ipykernel->jupyter>=1.0.0->SAM-2==1.0) (5.14.3)\n", - "Requirement already satisfied: widgetsnbextension~=4.0.11 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from ipywidgets->jupyter>=1.0.0->SAM-2==1.0) (4.0.11)\n", - "Requirement already satisfied: jupyterlab-widgets~=3.0.11 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from ipywidgets->jupyter>=1.0.0->SAM-2==1.0) (3.0.11)\n", - "Requirement already satisfied: MarkupSafe>=2.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jinja2->torch>=2.3.1->SAM-2==1.0) (2.1.5)\n", - "Requirement already satisfied: prompt-toolkit>=3.0.30 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyter-console->jupyter>=1.0.0->SAM-2==1.0) (3.0.47)\n", - "Requirement already satisfied: pygments in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyter-console->jupyter>=1.0.0->SAM-2==1.0) (2.18.0)\n", - "Requirement already satisfied: beautifulsoup4 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from nbconvert->jupyter>=1.0.0->SAM-2==1.0) (4.12.3)\n", - "Requirement already satisfied: bleach!=5.0.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from nbconvert->jupyter>=1.0.0->SAM-2==1.0) (6.1.0)\n", - "Requirement already satisfied: defusedxml in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from nbconvert->jupyter>=1.0.0->SAM-2==1.0) (0.7.1)\n", - "Requirement already satisfied: jupyterlab-pygments in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from nbconvert->jupyter>=1.0.0->SAM-2==1.0) (0.3.0)\n", - "Requirement already satisfied: mistune<4,>=2.0.3 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from nbconvert->jupyter>=1.0.0->SAM-2==1.0) (3.0.2)\n", - "Requirement already satisfied: nbclient>=0.5.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from nbconvert->jupyter>=1.0.0->SAM-2==1.0) (0.10.0)\n", - "Requirement already satisfied: nbformat>=5.7 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from nbconvert->jupyter>=1.0.0->SAM-2==1.0) (5.10.4)\n", - "Requirement already satisfied: pandocfilters>=1.4.1 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from nbconvert->jupyter>=1.0.0->SAM-2==1.0) (1.5.1)\n", - "Requirement already satisfied: tinycss2 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from nbconvert->jupyter>=1.0.0->SAM-2==1.0) (1.3.0)\n", - "Requirement already satisfied: jupyter-server<3,>=2.4.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from notebook->jupyter>=1.0.0->SAM-2==1.0) (2.14.2)\n", - "Requirement already satisfied: jupyterlab-server<3,>=2.27.1 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from notebook->jupyter>=1.0.0->SAM-2==1.0) (2.27.3)\n", - "Requirement already satisfied: jupyterlab<4.3,>=4.2.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from notebook->jupyter>=1.0.0->SAM-2==1.0) (4.2.4)\n", - "Requirement already satisfied: notebook-shim<0.3,>=0.2 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from notebook->jupyter>=1.0.0->SAM-2==1.0) (0.2.4)\n", - "Requirement already satisfied: qtpy>=2.4.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from qtconsole->jupyter>=1.0.0->SAM-2==1.0) (2.4.1)\n", - "Requirement already satisfied: mpmath<1.4,>=1.1.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from sympy->torch>=2.3.1->SAM-2==1.0) (1.3.0)\n", - "Requirement already satisfied: webencodings in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from bleach!=5.0.0->nbconvert->jupyter>=1.0.0->SAM-2==1.0) (0.5.1)\n", - "Requirement already satisfied: decorator in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from ipython>=7.23.1->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (5.1.1)\n", - "Requirement already satisfied: jedi>=0.16 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from ipython>=7.23.1->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (0.19.1)\n", - "Requirement already satisfied: stack-data in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from ipython>=7.23.1->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (0.6.3)\n", - "Requirement already satisfied: exceptiongroup in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from ipython>=7.23.1->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (1.2.2)\n", - "Requirement already satisfied: pexpect>4.3 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from ipython>=7.23.1->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (4.9.0)\n", - "Requirement already satisfied: platformdirs>=2.5 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyter-core!=5.0.*,>=4.12->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (4.2.2)\n", - "Requirement already satisfied: anyio>=3.1.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (4.4.0)\n", - "Requirement already satisfied: argon2-cffi>=21.1 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (23.1.0)\n", - "Requirement already satisfied: jupyter-events>=0.9.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.10.0)\n", - "Requirement already satisfied: jupyter-server-terminals>=0.4.4 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.5.3)\n", - "Requirement already satisfied: overrides>=5.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (7.7.0)\n", - "Requirement already satisfied: prometheus-client>=0.9 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.20.0)\n", - "Requirement already satisfied: send2trash>=1.8.2 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (1.8.3)\n", - "Requirement already satisfied: terminado>=0.8.3 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.18.1)\n", - "Requirement already satisfied: websocket-client>=1.7 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (1.8.0)\n", - "Requirement already satisfied: async-lru>=1.0.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyterlab<4.3,>=4.2.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (2.0.4)\n", - "Requirement already satisfied: httpx>=0.25.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyterlab<4.3,>=4.2.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.27.0)\n", - "Requirement already satisfied: jupyter-lsp>=2.0.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyterlab<4.3,>=4.2.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (2.2.5)\n", - "Requirement already satisfied: setuptools>=40.1.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyterlab<4.3,>=4.2.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (59.6.0)\n", - "Requirement already satisfied: tomli>=1.2.2 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyterlab<4.3,>=4.2.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (2.0.1)\n", - "Requirement already satisfied: babel>=2.10 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (2.15.0)\n", - "Requirement already satisfied: json5>=0.9.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.9.25)\n", - "Requirement already satisfied: jsonschema>=4.18.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (4.23.0)\n", - "Requirement already satisfied: requests>=2.31 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (2.32.3)\n", - "Requirement already satisfied: fastjsonschema>=2.15 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from nbformat>=5.7->nbconvert->jupyter>=1.0.0->SAM-2==1.0) (2.20.0)\n", - "Requirement already satisfied: wcwidth in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from prompt-toolkit>=3.0.30->jupyter-console->jupyter>=1.0.0->SAM-2==1.0) (0.2.13)\n", - "Requirement already satisfied: soupsieve>1.2 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from beautifulsoup4->nbconvert->jupyter>=1.0.0->SAM-2==1.0) (2.5)\n", - "Requirement already satisfied: idna>=2.8 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from anyio>=3.1.0->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (3.7)\n", - "Requirement already satisfied: sniffio>=1.1 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from anyio>=3.1.0->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (1.3.1)\n", - "Requirement already satisfied: argon2-cffi-bindings in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from argon2-cffi>=21.1->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (21.2.0)\n", - "Requirement already satisfied: certifi in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from httpx>=0.25.0->jupyterlab<4.3,>=4.2.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (2024.7.4)\n", - "Requirement already satisfied: httpcore==1.* in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from httpx>=0.25.0->jupyterlab<4.3,>=4.2.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (1.0.5)\n", - "Requirement already satisfied: h11<0.15,>=0.13 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from httpcore==1.*->httpx>=0.25.0->jupyterlab<4.3,>=4.2.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.14.0)\n", - "Requirement already satisfied: parso<0.9.0,>=0.8.3 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jedi>=0.16->ipython>=7.23.1->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (0.8.4)\n", - "Requirement already satisfied: attrs>=22.2.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (23.2.0)\n", - "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (2023.12.1)\n", - "Requirement already satisfied: referencing>=0.28.4 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.35.1)\n", - "Requirement already satisfied: rpds-py>=0.7.1 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.19.1)\n", - "Requirement already satisfied: python-json-logger>=2.0.4 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyter-events>=0.9.0->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (2.0.7)\n", - "Requirement already satisfied: rfc3339-validator in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyter-events>=0.9.0->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.1.4)\n", - "Requirement already satisfied: rfc3986-validator>=0.1.1 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jupyter-events>=0.9.0->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (0.1.1)\n", - "Requirement already satisfied: ptyprocess>=0.5 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from pexpect>4.3->ipython>=7.23.1->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (0.7.0)\n", - "Requirement already satisfied: charset-normalizer<4,>=2 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from requests>=2.31->jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (2.1.1)\n", - "Requirement already satisfied: urllib3<3,>=1.21.1 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from requests>=2.31->jupyterlab-server<3,>=2.27.1->notebook->jupyter>=1.0.0->SAM-2==1.0) (2.2.2)\n", - "Requirement already satisfied: executing>=1.2.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from stack-data->ipython>=7.23.1->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (2.0.1)\n", - "Requirement already satisfied: asttokens>=2.1.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from stack-data->ipython>=7.23.1->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (2.4.1)\n", - "Requirement already satisfied: pure-eval in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from stack-data->ipython>=7.23.1->ipykernel->jupyter>=1.0.0->SAM-2==1.0) (0.2.3)\n", - "Requirement already satisfied: fqdn in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.9.0->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (1.5.1)\n", - "Requirement already satisfied: isoduration in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.9.0->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (20.11.0)\n", - "Requirement already satisfied: jsonpointer>1.13 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.9.0->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (3.0.0)\n", - "Requirement already satisfied: uri-template in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.9.0->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (1.3.0)\n", - "Requirement already satisfied: webcolors>=24.6.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.9.0->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (24.6.0)\n", - "Requirement already satisfied: cffi>=1.0.1 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from argon2-cffi-bindings->argon2-cffi>=21.1->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (1.16.0)\n", - "Requirement already satisfied: pycparser in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from cffi>=1.0.1->argon2-cffi-bindings->argon2-cffi>=21.1->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (2.22)\n", - "Requirement already satisfied: arrow>=0.15.0 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from isoduration->jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.9.0->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (1.3.0)\n", - "Requirement already satisfied: types-python-dateutil>=2.8.10 in /home/labuser/work/notebook/openvino_notebooks/.venv/lib/python3.10/site-packages (from arrow>=0.15.0->isoduration->jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.9.0->jupyter-server<3,>=2.4.0->notebook->jupyter>=1.0.0->SAM-2==1.0) (2.9.0.20240316)\n", - "Building wheels for collected packages: SAM-2\n", - " Building editable for SAM-2 (pyproject.toml) ... \u001b[?25ldone\n", - "\u001b[?25h Created wheel for SAM-2: filename=SAM_2-1.0-0.editable-py3-none-any.whl size=12339 sha256=2fa128d45045dc4e481cff0ca9a5281daaffbc6fc6dc23964130abeda83673b4\n", - " Stored in directory: /tmp/pip-ephem-wheel-cache-o5nqow6u/wheels/f7/c5/5e/5792e2709374e345e4c7222b9e2622418fe4dd89dd1c8514d3\n", - "Successfully built SAM-2\n", - "Installing collected packages: SAM-2\n", - "Successfully installed SAM-2-1.0\n", - "Note: you may need to restart the kernel to use updated packages.\n", - "/home/labuser/work/notebook/openvino_notebooks/notebooks/segment-anything\n" - ] - } - ], + "outputs": [], "source": [ "%env SAM2_BUILD_CUDA=0\n", "%cd sam2\n", @@ -942,7 +759,6 @@ " rval, frame = vcap.read()\n", " cv2.imwrite(os.path.join(self.work_dir_path, f\"{frame_idx}.jpg\"), frame)\n", " frame_idx += 1\n", - " cv2.waitKey(1)\n", " vcap.release()\n", "\n", " self.inference_state_ov = self.ov_predictor_video.init_state(video_path=self.work_dir_path)\n", diff --git a/notebooks/stable-diffusion-xl/segmind-vegart.ipynb b/notebooks/stable-diffusion-xl/segmind-vegart.ipynb index e4b2dc21974..c5c4a0324a2 100644 --- a/notebooks/stable-diffusion-xl/segmind-vegart.ipynb +++ b/notebooks/stable-diffusion-xl/segmind-vegart.ipynb @@ -63,8 +63,8 @@ "metadata": {}, "outputs": [], "source": [ - "%pip install -q --extra-index-url https://download.pytorch.org/whl/cpu\\\n", - "\"torch>=2.1\" transformers \"diffusers>=0.24.0\" \"git+https://github.com/huggingface/optimum-intel.git\" \"gradio>=4.19\" \"openvino>=2023.3.0\" \"peft>=0.6.2\"" + "%pip install -q --extra-index-url https://download.pytorch.org/whl/cpu \"torch>=2.1\" transformers \"diffusers>=0.24.0\"\n", + "%pip install -q --extra-index-url https://download.pytorch.org/whl/cpu \"git+https://github.com/huggingface/optimum-intel.git\" \"gradio>=4.19\" \"openvino>=2023.3.0\" \"peft>=0.6.2\"" ] }, { @@ -97,13 +97,18 @@ "adapter_id = \"segmind/Segmind-VegaRT\"\n", "pt_model_dir = Path(\"segmind-vegart\")\n", "\n", - "if not pt_model_dir.exists():\n", + "model_dir = Path(\"openvino-segmind-vegart\")\n", + "sdxl_model_id = pt_model_dir\n", + "tae_id = \"madebyollin/taesdxl\"\n", + "skip_convert_model = model_dir.exists()\n", + "\n", + "if not pt_model_dir.exists() and not skip_convert_model:\n", " pipe = AutoPipelineForText2Image.from_pretrained(model_id, torch_dtype=torch.float16, variant=\"fp16\")\n", " pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)\n", " pipe.load_lora_weights(adapter_id)\n", " pipe.fuse_lora()\n", "\n", - " pipe.save_pretrained(\"segmind-vegart\")\n", + " pipe.save_pretrained(pt_model_dir)\n", " del pipe\n", " gc.collect()" ] @@ -148,11 +153,12 @@ "outputs": [], "source": [ "from pathlib import Path\n", + "import requests\n", "\n", - "model_dir = Path(\"openvino-segmind-vegart\")\n", - "sdxl_model_id = \"./segmind-vegart\"\n", - "tae_id = \"madebyollin/taesdxl\"\n", - "skip_convert_model = model_dir.exists()" + "if not Path(\"cmd_helper.py\").exists():\n", + " r = requests.get(\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/cmd_helper.py\")\n", + " with open(\"cmd_helper.py\", \"w\") as f:\n", + " f.write(r.text)" ] }, { @@ -166,6 +172,7 @@ "import openvino as ov\n", "from diffusers import AutoencoderTiny\n", "import gc\n", + "from cmd_helper import optimum_cli\n", "\n", "\n", "class VAEEncoder(torch.nn.Module):\n", @@ -203,7 +210,7 @@ "\n", "\n", "if not skip_convert_model:\n", - " !optimum-cli export openvino --model $sdxl_model_id --task stable-diffusion-xl $model_dir --weight-format fp16\n", + " optimum_cli(sdxl_model_id, model_dir, additional_args={\"task\": \"text-to-image\", \"weight-format\": \"fp16\"})\n", " convert_tiny_vae(tae_id, model_dir)" ] }, @@ -256,12 +263,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", @@ -418,12 +424,12 @@ "outputs": [], "source": [ "# Fetch `skip_kernel_extension` module\n", - "import requests\n", "\n", - "r = requests.get(\n", - " url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/skip_kernel_extension.py\",\n", - ")\n", - "open(\"skip_kernel_extension.py\", \"w\").write(r.text)\n", + "if not Path(\"skip_kernel_extension.py\").exists():\n", + " r = requests.get(\n", + " url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/skip_kernel_extension.py\",\n", + " )\n", + " open(\"skip_kernel_extension.py\", \"w\").write(r.text)\n", "\n", "int8_pipe = None\n", "\n",