Spaces:
Runtime error
Runtime error
File size: 1,282 Bytes
2a3d474 4a85e0a 2a3d474 4a85e0a 2a3d474 4a85e0a 0263ada 4a85e0a d33303c 4a85e0a 2a3d474 4a85e0a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import gradio as gr
import torch
from utils import colorize
from PIL import Image
import tempfile
DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
model = torch.hub.load('isl-org/ZoeDepth', "ZoeD_N", pretrained=True).to(DEVICE).eval()
def predict_depth(model, image):
depth = model.infer_pil(image)
return depth
def on_submit(image):
depth = predict_depth(model, image)
colored_depth = colorize(depth, cmap='gray_r')
tmp = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
raw_depth = Image.fromarray((depth*256).astype('uint16'))
raw_depth.save(tmp.name)
return [colored_depth, tmp.name]
iface = gr.Interface(
fn=on_submit,
inputs=gr.inputs.Image(type='pil', label="Input Image"),
outputs=[
gr.outputs.Image(type='numpy', label="Depth Map"),
gr.outputs.File(label="16-bit raw depth, multiplier:256")
],
title="# ZoeDepth",
description="""Unofficial demo for **ZoeDepth: Zero-shot Transfer by Combining Relative and Metric Depth**.""",
css="""
#img-display-container {
max-height: 50vh;
}
#img-display-input {
max-height: 40vh;
}
#img-display-output {
max-height: 40vh;
}
"""
)
if __name__ == '__main__':
iface.launch() |