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"]
  • AutoModel loads the same class. output_hidden_states=True adds the 4 DINOv2 features the DPT head reads; return_dict=False returns a tuple.
  • post_process_depth_estimation resizes as the original run.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 repo LiheYoung/depth_anything_vits14 states 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
Safetensors
Model size
24.8M params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for bigshanedogg/Depth-Anything-V1-Small

Finetuned
(1)
this model