CoolFace
Apppublic

souvikmaji22/depth-estimation

sourceHugging Faceupdated 2y agoView on Hugging Face
2likes
app.py33 linesDownload Raw Back to root
1import gradio as gr2from transformers import pipeline3import torch4import numpy as np5from PIL import Image6 7 8depth_estimator = pipeline(task="depth-estimation",9                        model="Intel/dpt-hybrid-midas")10if __name__ == "__main__":11    12    def launch(input_image):13        out = depth_estimator(input_image)14 15    # resize the prediction16        prediction = torch.nn.functional.interpolate(17            out["predicted_depth"].unsqueeze(1),18            size=input_image.size[::-1],19            mode="bicubic",20            align_corners=False,21        )22 23    # normalize the prediction24        output = prediction.squeeze().numpy()25        formatted = (output * 255 / np.max(output)).astype("uint8")26        depth = Image.fromarray(formatted)27        return depth28 29    iface = gr.Interface(launch,30                     inputs=gr.Image(type='pil'),31                     outputs=gr.Image(type='pil'))32 33    iface.launch()