Views
No views yet
1from transformers import pipeline
2from PIL import Image
3import requests
4# load pipe
5pipe = pipeline(task="depth-estimation", model="xingyang1/Distill-Any-Depth-Small-hf")
6# load image
7url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
8image = Image.open(requests.get(url, stream=True).raw)
9# inference
10depth = pipe(image)["depth"]1from transformers import AutoImageProcessor, AutoModelForDepthEstimation
2import torch
3import numpy as np
4from PIL import Image
5import requests
6
7url = "http://images.cocodataset.org/val2017/000000039769.jpg"
8image = Image.open(requests.get(url, stream=True).raw)
9
10image_processor = AutoImageProcessor.from_pretrained("xingyang1/Distill-Any-Depth-Small-hf")
11model = AutoModelForDepthEstimation.from_pretrained("xingyang1/Distill-Any-Depth-Small-hf")
12
13# prepare image for the model
14inputs = image_processor(images=image, return_tensors="pt")
15
16with torch.no_grad():
17 outputs = model(**inputs)
18
19# interpolate to original size and visualize the prediction
20post_processed_output = image_processor.post_process_depth_estimation(
21 outputs,
22 target_sizes=[(image.height, image.width)],
23)
24
25predicted_depth = post_processed_output[0]["predicted_depth"]
26depth = (predicted_depth - predicted_depth.min()) / (predicted_depth.max() - predicted_depth.min())
27depth = depth.detach().cpu().numpy() * 255
28depth = Image.fromarray(depth.astype("uint8"))
29)1@article{he2025distill,
2 title = {Distill Any Depth: Distillation Creates a Stronger Monocular Depth Estimator},
3 author = {Xiankang He and Dongyan Guo and Hongji Li and Ruibo Li and Ying Cui and Chi Zhang},
4 year = {2025},
5 journal = {arXiv preprint arXiv: 2502.19204}
6}