RamAnanth1/ZoeDepth
30
1import gradio as gr 2import torch3from utils import get_image_from_url, colorize4from PIL import Image5import matplotlib.pyplot as plt6 7title = "Interactive demo: ZoeDepth"8description = "Unofficial Gradio Demo for using ZoeDepth: Zero-shot Transfer by Combining Relative and Metric Depth. ZoeDepth is a technique that lets you perform metric depth estimation from a single image. For more information, please refer to the <a href='https://arxiv.org/abs/2302.12288' style='text-decoration: underline;' target='_blank'> paper</a> or the <a href='https://github.com/isl-org/ZoeDepth' style='text-decoration: underline;' target='_blank'> Github </a> implementation. </p> To use it, simply upload an image or use one of the examples below and click 'Submit'. Results will show up in a few seconds."9examples = [["example.png"],["example_2.png"]]10repo = "isl-org/ZoeDepth"11# Zoe_N12model_zoe_n = torch.hub.load(repo, "ZoeD_NK", pretrained=True)13DEVICE = "cuda" if torch.cuda.is_available() else "cpu"14zoe = model_zoe_n.to(DEVICE)15 16def process_image(image):17 depth = zoe.infer_pil(image) # as numpy18 colored_depth = colorize(depth, cmap = 'magma_r')19 return colored_depth20 21interface = gr.Interface(fn=process_image, 22 inputs=[gr.Image(type="pil")],23 outputs=[gr.Image(type="pil", label ="Depth")24 ],25 title=title,26 description=description,27 examples = examples28 )29 30interface.launch(debug=True)