Instructions to use bigshanedogg/Depth-Anything-V1-Small with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use bigshanedogg/Depth-Anything-V1-Small with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("depth-estimation", model="bigshanedogg/Depth-Anything-V1-Small", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("bigshanedogg/Depth-Anything-V1-Small", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Depth-Anything-V1-Small β transformers format (original code)
Unofficial transformers port of Depth Anything (v1) Small (LiheYoung/depth_anything_vits14) that runs the original
code. Loads with trust_remote_code. model.safetensors holds the tensors of the released pytorch_model.bin under
their original names (converted by save_pretrained, every tensor checked equal).
Not an official release. Depth Anything was created by Lihe Yang, Bingyi Kang, Zilong Huang, Xiaogang Xu, Jiashi Feng and Hengshuang Zhao β https://github.com/LiheYoung/Depth-Anything, paper "Depth Anything: Unleashing the Power of Large-Scale Unlabeled Data" (CVPR 2024, arXiv 2401.10891).
What it is
DepthAnythingV1ForDepthEstimation holds the official DPT_DINOv2's submodules (pretrained: DINOv2 ViT-S/14,
depth_head: DPT), computes depth with the official DPT_DINOv2.forward and returns the standard
DepthEstimatorOutput (predicted_depth). DINOv2 is the repo's local torchhub copy of facebookresearch/dinov2,
built with the hub's arguments (the official class calls torch.hub.load(..., source="local")). Code vendored from
LiheYoung/Depth-Anything @ 1d033367 into dav1_dinov2.py / dav1_dpt.py; edits: imports, and Block β
NestedTensorBlock where the original imported NestedTensorBlock as Block. DepthAnythingV1Processor
(processing_depth_anything_v1.py, processor_config.json) wraps DepthAnythingV1ImageProcessor, the transform of
the official run.py.
Verified against the official code (same process, V100, 3 images incl. non-square): preprocessing, predicted_depth
(also as a tuple) in fp32 and under fp16 autocast, the hidden states, and the post-processing to the original size are
bit-identical.
Usage
import torch
from PIL import Image
from transformers import AutoModelForDepthEstimation, AutoProcessor
model = AutoModelForDepthEstimation.from_pretrained("Depth-Anything-V1-Small", trust_remote_code=True).eval().cuda()
processor = AutoProcessor.from_pretrained("Depth-Anything-V1-Small", trust_remote_code=True)
image = Image.open("image.jpg") # or a path (read with cv2, as run.py)
inputs = processor(images=image, return_tensors="pt").to("cuda")
with torch.no_grad():
outputs = model(**inputs) # outputs.predicted_depth: (1, H', W') relative inverse depth
depth = processor.post_process_depth_estimation(outputs, target_sizes=[image.size[::-1]])[0]["predicted_depth"]
AutoModelloads the same class.output_hidden_states=Trueadds the 4 DINOv2 features the DPT head reads;return_dict=Falsereturns a tuple.post_process_depth_estimationresizes as the originalrun.py(bilinear,align_corners=False), not with transformers' bicubic.
Runtime packages beyond torch / transformers: opencv-python, torchvision, huggingface_hub (as the original).
Licensing
- Code and weights: Apache-2.0 β
LICENSE(LiheYoung/Depth-Anything). The weight repoLiheYoung/depth_anything_vits14states no license itself; the repository is Apache-2.0 and the transformers conversion of the same weights in the same organisation (LiheYoung/depth-anything-small-hf) is published as Apache-2.0. - DINOv2 code (torchhub copy): Apache-2.0, Meta β
LICENSE.dinov2. - Attribution, sources and the changes made here:
NOTICE.
Citation
If you use this model, please cite the original work, as its authors ask:
@inproceedings{depthanything,
title={Depth Anything: Unleashing the Power of Large-Scale Unlabeled Data},
author={Yang, Lihe and Kang, Bingyi and Huang, Zilong and Xu, Xiaogang and Feng, Jiashi and Zhao, Hengshuang},
booktitle={CVPR},
year={2024}
}
- Downloads last month
- 4
Model tree for bigshanedogg/Depth-Anything-V1-Small
Base model
LiheYoung/depth_anything_vits14