File size: 2,575 Bytes
6f72020
 
7e9d2f3
1f8126a
7e9d2f3
516f50c
 
 
 
1f8126a
516f50c
c1a53ad
 
 
 
 
 
 
1f8126a
 
 
 
 
7e9d2f3
c1a53ad
f531789
 
 
 
c1a53ad
 
f5241bd
 
 
 
c1a53ad
 
 
 
 
 
1d0844e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from transformers import pipeline
from PIL import Image
import gradio as gr
import numpy as np

# Load the Hugging Face depth estimation pipelines
pipe_base = pipeline(task="depth-estimation", model="LiheYoung/depth-anything-base-hf")
pipe_small = pipeline(task="depth-estimation", model="LiheYoung/depth-anything-small-hf")
pipe_intel = pipeline(task="depth-estimation", model="Intel/dpt-swinv2-tiny-256")
pipe_beit = pipeline(task="depth-estimation", model="Intel/dpt-beit-base-384")

def process_and_display(pipe, output_component):
    def process_image(image):
        depth_map = pipe(image)["depth"]
        normalized_depth = normalize_depth(depth_map)
        output_component.value = normalized_depth

    return process_image

def normalize_depth(depth_map):
    # Normalize depth map values to range [0, 255] for visualization
    normalized_depth = ((depth_map - depth_map.min()) / (depth_map.max() - depth_map.min())) * 255
    return normalized_depth.astype(np.uint8)

# Create Gradio output components for each pipeline
output_base = gr.Image(type="numpy", label="LiheYoung/depth-anything-base-hf")
output_small = gr.Image(type="numpy", label="LiheYoung/depth-anything-small-hf")
output_intel = gr.Image(type="numpy", label="Intel/dpt-swinv2-tiny-256")
output_beit = gr.Image(type="numpy", label="Intel/dpt-beit-base-384")

# Create Gradio interfaces for each pipeline
iface_base = gr.Interface(process_and_display(pipe_base, output_base), inputs=gr.Image(type="pil"), outputs=output_base, title="Depth Estimation - LiheYoung/depth-anything-base-hf")
iface_small = gr.Interface(process_and_display(pipe_small, output_small), inputs=gr.Image(type="pil"), outputs=output_small, title="Depth Estimation - LiheYoung/depth-anything-small-hf")
iface_intel = gr.Interface(process_and_display(pipe_intel, output_intel), inputs=gr.Image(type="pil"), outputs=output_intel, title="Depth Estimation - Intel/dpt-swinv2-tiny-256")
iface_beit = gr.Interface(process_and_display(pipe_beit, output_beit), inputs=gr.Image(type="pil"), outputs=output_beit, title="Depth Estimation - Intel/dpt-beit-base-384")

# Launch the Gradio interfaces
iface_base.launch()
iface_small.launch()
iface_intel.launch()
iface_beit.launch()



""" 
from transformers import pipeline
from PIL import Image
import requests

# load pipe
pipe = pipeline(task="depth-estimation", model="LiheYoung/depth-anything-small-hf")

# load image
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
image = Image.open(requests.get(url, stream=True).raw)

# inference
depth = pipe(image)["depth"]

"""