Skip to content

Commit

Permalink
Replace output file to avoid confusion (openvinotoolkit#2547)
Browse files Browse the repository at this point in the history
In gradio example one of the outputs is raw_depth file. It looks like an
empty image and causes confusion. It was replaced by result colored
depth image like in a slider.
  • Loading branch information
aleksandr-mokrov authored Nov 20, 2024
1 parent ef4b9b0 commit 6efac12
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
10 changes: 6 additions & 4 deletions notebooks/depth-anything/depth-anything-v2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
"%pip install -q \"typing-extensions>=4.9.0\" eval-type-backport \"gradio>=4.19\" gradio_imageslider\n",
"%pip install -q torch torchvision \"opencv-python\" huggingface_hub --extra-index-url https://download.pytorch.org/whl/cpu\n",
"\n",
"if platform.system() == \"Darwin\":\n",
" %pip install -q \"numpy<2.0.0\"\n",
"if platform.python_version_tuple()[1] in [\"8\", \"9\"]:\n",
" %pip install -q \"gradio-imageslider<=0.0.17\" \"typing-extensions>=4.9.0\""
]
Expand Down Expand Up @@ -1478,14 +1480,14 @@
" depth = predict_depth(compiled_model, image)\n",
" depth = cv2.resize(depth[0], (w, h), interpolation=cv2.INTER_LINEAR)\n",
"\n",
" raw_depth = Image.fromarray(depth.astype(\"uint16\"))\n",
" tmp = tempfile.NamedTemporaryFile(suffix=\".png\", delete=False)\n",
" raw_depth.save(tmp.name)\n",
"\n",
" depth = (depth - depth.min()) / (depth.max() - depth.min()) * 255.0\n",
" depth = depth.astype(np.uint8)\n",
" colored_depth = cv2.applyColorMap(depth, cv2.COLORMAP_INFERNO)[:, :, ::-1]\n",
"\n",
" colored_depth_img = Image.fromarray(colored_depth)\n",
" tmp = tempfile.NamedTemporaryFile(suffix=\".png\", delete=False)\n",
" colored_depth_img.save(tmp.name)\n",
"\n",
" return [(original_image, colored_depth), tmp.name]"
]
},
Expand Down
10 changes: 6 additions & 4 deletions notebooks/depth-anything/depth-anything.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
"%pip install -q \"typing-extensions>=4.9.0\" eval-type-backport \"gradio>=4.19\" \"matplotlib>=3.4\"\n",
"%pip install -q torch torchvision \"opencv-python\" huggingface_hub --extra-index-url https://download.pytorch.org/whl/cpu\n",
"\n",
"if platform.system() == \"Darwin\":\n",
" %pip install -q \"numpy<2.0.0\"\n",
"if platform.python_version_tuple()[1] in [\"8\", \"9\"]:\n",
" %pip install -q \"gradio-imageslider<=0.0.17\" \"typing-extensions>=4.9.0\""
]
Expand Down Expand Up @@ -1270,14 +1272,14 @@
" depth = predict_depth(compiled_model, image)\n",
" depth = cv2.resize(depth[0], (w, h), interpolation=cv2.INTER_LINEAR)\n",
"\n",
" raw_depth = Image.fromarray(depth.astype(\"uint16\"))\n",
" tmp = tempfile.NamedTemporaryFile(suffix=\".png\", delete=False)\n",
" raw_depth.save(tmp.name)\n",
"\n",
" depth = (depth - depth.min()) / (depth.max() - depth.min()) * 255.0\n",
" depth = depth.astype(np.uint8)\n",
" colored_depth = cv2.applyColorMap(depth, cv2.COLORMAP_INFERNO)[:, :, ::-1]\n",
"\n",
" colored_depth_img = Image.fromarray(colored_depth)\n",
" tmp = tempfile.NamedTemporaryFile(suffix=\".png\", delete=False)\n",
" colored_depth_img.save(tmp.name)\n",
"\n",
" return [(original_image, colored_depth), tmp.name]"
]
},
Expand Down
6 changes: 3 additions & 3 deletions notebooks/depth-anything/gradio_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def make_demo(fn: Callable, examples_dir: str):
with gr.Row():
input_image = gr.Image(label="Input Image", type="numpy", elem_id="img-display-input")
depth_image_slider = ImageSlider(label="Depth Map with Slider View", elem_id="img-display-output", position=0)
raw_file = gr.File(label="16-bit raw depth (can be considered as disparity)")
depth_image_file = gr.File(label="Depth Image")
submit = gr.Button("Submit")

submit.click(fn=fn, inputs=[input_image], outputs=[depth_image_slider, raw_file])
submit.click(fn=fn, inputs=[input_image], outputs=[depth_image_slider, depth_image_file])

if not Path(examples_dir).exists():
gr.Error(f"Examples directory {examples_dir} does not exist.")
Expand All @@ -37,7 +37,7 @@ def make_demo(fn: Callable, examples_dir: str):
examples = gr.Examples(
examples=example_files,
inputs=[input_image],
outputs=[depth_image_slider, raw_file],
outputs=[depth_image_slider, depth_image_file],
fn=fn,
cache_examples=False,
)
Expand Down

0 comments on commit 6efac12

Please sign in to comment.