Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from PIL import Image
|
3 |
+
from diffusers import DiffusionPipeline
|
4 |
+
from diffusers.utils import load_image
|
5 |
+
|
6 |
+
pipe = DiffusionPipeline.from_pretrained(
|
7 |
+
"Bingxin/Marigold",
|
8 |
+
custom_pipeline="marigold_depth_estimation"
|
9 |
+
# torch_dtype=torch.float16, # (optional) Run with half-precision (16-bit float).
|
10 |
+
)
|
11 |
+
|
12 |
+
pipe.to("cuda")
|
13 |
+
|
14 |
+
img_path_or_url = "https://share.phys.ethz.ch/~pf/bingkedata/marigold/pipeline_example.jpg"
|
15 |
+
image: Image.Image = load_image(img_path_or_url)
|
16 |
+
|
17 |
+
pipeline_output = pipe(
|
18 |
+
image, # Input image.
|
19 |
+
# denoising_steps=10, # (optional) Number of denoising steps of each inference pass. Default: 10.
|
20 |
+
# ensemble_size=10, # (optional) Number of inference passes in the ensemble. Default: 10.
|
21 |
+
# processing_res=768, # (optional) Maximum resolution of processing. If set to 0: will not resize at all. Defaults to 768.
|
22 |
+
# match_input_res=True, # (optional) Resize depth prediction to match input resolution.
|
23 |
+
# batch_size=0, # (optional) Inference batch size, no bigger than `num_ensemble`. If set to 0, the script will automatically decide the proper batch size. Defaults to 0.
|
24 |
+
# color_map="Spectral", # (optional) Colormap used to colorize the depth map. Defaults to "Spectral".
|
25 |
+
# show_progress_bar=True, # (optional) If true, will show progress bars of the inference progress.
|
26 |
+
)
|
27 |
+
|
28 |
+
depth: np.ndarray = pipeline_output.depth_np # Predicted depth map
|
29 |
+
depth_colored: Image.Image = pipeline_output.depth_colored # Colorized prediction
|
30 |
+
|
31 |
+
# Save as uint16 PNG
|
32 |
+
depth_uint16 = (depth * 65535.0).astype(np.uint16)
|
33 |
+
Image.fromarray(depth_uint16).save("./depth_map.png", mode="I;16")
|
34 |
+
|
35 |
+
# Save colorized depth map
|
36 |
+
depth_colored.save("./depth_colored.png")
|