--- license: apache-2.0 library_name: transformers base_model: LiheYoung/depth_anything_vitb14 tags: - depth-anything - depth-estimation pipeline_tag: depth-estimation --- # Depth-Anything-V1-Base — transformers format (original code) Unofficial transformers port of **Depth Anything** (v1) Base (`LiheYoung/depth_anything_vitb14`) 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-B/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 ```python import torch from PIL import Image from transformers import AutoModelForDepthEstimation, AutoProcessor model = AutoModelForDepthEstimation.from_pretrained("Depth-Anything-V1-Base", trust_remote_code=True).eval().cuda() processor = AutoProcessor.from_pretrained("Depth-Anything-V1-Base", 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`](LICENSE) (LiheYoung/Depth-Anything). The weight repo `LiheYoung/depth_anything_vitb14` 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-base-hf`) is published as Apache-2.0. - DINOv2 code (torchhub copy): **Apache-2.0**, Meta — [`LICENSE.dinov2`](LICENSE.dinov2). - Attribution, sources and the changes made here: [`NOTICE`](NOTICE). ## Citation If you use this model, please cite the original work, as its authors ask: ```bibtex @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} } ```