From e8499a811a0608b5f580dd64ca853fe8217fd2a9 Mon Sep 17 00:00:00 2001 From: Pavel Esir Date: Mon, 26 Feb 2024 11:29:10 +0100 Subject: [PATCH] fix pip-conflicts --- .../287-grounded-segment-anything.ipynb | 118 ++++++++++++------ 1 file changed, 78 insertions(+), 40 deletions(-) diff --git a/notebooks/287-grounded-segment-anything/287-grounded-segment-anything.ipynb b/notebooks/287-grounded-segment-anything/287-grounded-segment-anything.ipynb index 0abefebd2f1..5d89a37ffb8 100644 --- a/notebooks/287-grounded-segment-anything/287-grounded-segment-anything.ipynb +++ b/notebooks/287-grounded-segment-anything/287-grounded-segment-anything.ipynb @@ -40,12 +40,12 @@ "outputs": [], "source": [ "%pip install -q \"torch==2.1.0\" \"torchvision==0.16.0\" --extra-index-url https://download.pytorch.org/whl/cpu\n", - "%pip install -q \"openvino-nightly>=2024.1.0.dev20240219\" opencv-python supervision transformers yapf pycocotools addict timm \"gradio==3.50.2\"" + "%pip install -q \"openvino-nightly>=2024.1.0.dev20240219\" opencv-python supervision transformers yapf pycocotools addict timm gradio" ] }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -69,7 +69,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -93,7 +93,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -102,7 +102,6 @@ "os.makedirs(IRS_PATH, exist_ok=True)\n", "os.makedirs(CKPT_BASE_PATH, exist_ok=True)\n", "\n", - "DEVICE = 'AUTO'\n", "PT_DEVICE = 'cpu'\n", "ov_dino_name = 'openvino_grounding_dino'\n", "ov_sam_name = 'openvino_segment_anything'\n", @@ -122,14 +121,22 @@ "metadata": {}, "outputs": [], "source": [ - "# todo: replace with cross platform download\n", - "!wget https://github.com/IDEA-Research/GroundingDINO/releases/download/v0.1.0-alpha/groundingdino_swint_ogc.pth -P {CKPT_BASE_PATH}\n", - "!wget https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth -P {CKPT_BASE_PATH}" + "# Fetch `notebook_utils` module\n", + "import urllib.request\n", + "urllib.request.urlretrieve(\n", + " url='https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/main/notebooks/utils/notebook_utils.py',\n", + " filename='notebook_utils.py'\n", + ")\n", + "\n", + "from notebook_utils import download_file\n", + "\n", + "download_file(\"https://github.com/IDEA-Research/GroundingDINO/releases/download/v0.1.0-alpha/groundingdino_swint_ogc.pth\", directory=CKPT_BASE_PATH)\n", + "download_file(\"https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth\", directory=CKPT_BASE_PATH)" ] }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -185,7 +192,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -227,13 +234,45 @@ "[back to top ⬆️](#Table-of-contents:)" ] }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "85f9a426083348879ed07ea433fa6332", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Dropdown(description='Device:', index=2, options=('CPU', 'GPU', 'AUTO'), value='AUTO')" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import ipywidgets\n", + "device_widget = ipywidgets.Dropdown(\n", + " options=core.available_devices + [\"AUTO\"],\n", + " value='AUTO',\n", + " description='Device:',\n", + " disabled=False,\n", + ")\n", + "device_widget" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "def build_compiled_model(model_config_path, ov_dino_model, device=DEVICE):\n", + "def build_compiled_model(model_config_path, ov_dino_model, device):\n", " from groundingdino.util import get_tokenlizer\n", " from groundingdino.util.slconfig import SLConfig\n", " \n", @@ -243,12 +282,13 @@ " model.max_text_len = args.max_text_len\n", " return model\n", "\n", - "ov_compiled_grounded_dino = build_compiled_model(GROUNDING_DINO_CONFIG_PATH, ov_dino_model)" + "device = device_widget.value\n", + "ov_compiled_grounded_dino = build_compiled_model(GROUNDING_DINO_CONFIG_PATH, ov_dino_model, device)" ] }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -344,7 +384,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -356,7 +396,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -379,11 +419,10 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ - "# classes_prompt = [\"The running dog\", 'grass']\n", "classes_prompt = [\"Horse\", \"Clouds\", \"Grasses\", \"Sky\", \"Hill\"]" ] }, @@ -421,7 +460,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -432,7 +471,7 @@ "" ] }, - "execution_count": 41, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -472,7 +511,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -525,7 +564,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -545,7 +584,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -560,11 +599,11 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ - "ov_sam_compiled = core.compile_model(ov_sam, device_name=DEVICE)" + "ov_sam_compiled = core.compile_model(ov_sam, device_name=device)" ] }, { @@ -577,7 +616,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -599,7 +638,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ @@ -615,7 +654,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -625,7 +664,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -636,7 +675,7 @@ "" ] }, - "execution_count": 49, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -672,7 +711,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ @@ -681,7 +720,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ @@ -778,13 +817,7 @@ "metadata": {}, "outputs": [], "source": [ - "no_gradio_queue = True\n", - "\n", - "block = gr.Blocks()\n", - "if not no_gradio_queue:\n", - " block = block.queue()\n", - "\n", - "with block:\n", + "with gr.Blocks() as demo:\n", " with gr.Row():\n", " with gr.Column():\n", " input_image = gr.Image(source='upload', type=\"pil\", value=f\"{repo_dir}/assets/demo1.jpg\", tool=\"sketch\")\n", @@ -807,8 +840,13 @@ " outputs=gallery\n", " )\n", "\n", - "block.queue(concurrency_count=100)\n", - "block.launch(server_name='0.0.0.0', server_port=7589, debug=True, share=False)" + "try:\n", + " demo.launch(debug=True, height=1000)\n", + "except Exception:\n", + " demo.launch(share=True, debug=True, height=1000)\n", + "# if you are launching remotely, specify server_name and server_port\n", + "# demo.launch(server_name='your server name', server_port='server port in int')\n", + "# Read more in the docs: https://gradio.app/docs/" ] }, {