depthfm / README.md
Flor's picture
card: update from fastforks 1cbf1671
54659fb verified
|
Raw History Blame Contribute Delete
7.24 kB
---
library_name: "fastforks"
pipeline_tag: "depth-estimation"
license: "other"
license_name: "see-model-card"
license_link: "https://github.com/CompVis/depth-fm/blob/da632c8118e41cc64ca191a13314e2db1a7722d9/README.md"
tags:
- "depth"
- "mono-depth"
- "monocular-depth"
- "cuda"
- "pytorch"
- "fastforks"
- "fastforks-card"
---
# DepthFM (fastforks)
DepthFM (Gui et al. 2024): affine-invariant monocular depth by flow matching from the image latent to the depth latent; a Stable Diffusion 2.1 UNet fine-tuned to the flow, a few Euler steps, ensemble of noise samples (v1).
This repo is the model card only: it holds no weights. fastforks downloads the authors' weights from the links below and checks them against the SHA-256 in the model card. Code: <https://github.com/kleinicke/fastforks>. Kernels for the `kernels` backend: <https://huggingface.co/fastforks/kernels>. Original code: <https://github.com/CompVis/depth-fm> at `da632c8`.
Author weight repos: <https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5>.
Task: depth. Tier: experimental. Outputs: `depth`. Backends: `portable`, `kernels`.
Input: one RGB image. Output: a depth or inverse-depth map. `kind` (a card field, `result.kind`) says what the numbers mean: `metric` = metres; `scale_invariant`, `affine_invariant`, `affine_invariant_log` (log depth) and `affine_invariant_inverse` are relative (unknown scale or shift, not metres). Metric models that use the focal length take `model(image, intrinsics=K)` (K `[3, 3]`, pixels of the input): `metric3d-vit-large` and `da3metric-large` need it for correct metres (`da3metric-large`: metres = output x focal / 300; without `intrinsics=` a 300 px focal length is assumed, wrong for a real camera). `unidepth-v2-vitl14`, `unik3d-vitl`, `depth-pro` and MoGe estimate the camera themselves (given `intrinsics=` replace `fx`); `zoedepth-nk` and the relative models (`da3mono-large` too) take none. Normals-only models (`kind` `none`) return `result.normals` `[B, H, W, 3]` (unit vectors, camera frame: x right, y down, z forward).
## Variants
Weights are the authors' files (not hosted here). SHA-256 shortened to 12 hex digits; the full hashes are in [`card.toml`](https://github.com/kleinicke/fastforks/blob/main/src/fastforks/depth/models/depthfm/card.toml).
| variant | weights (author link) | SHA-256 | weights licence | commercial use |
|---|---|---|---|---|
| `depthfm-v1@1` | [depthfm-v1.ckpt](https://ommer-lab.com/files/depthfm/depthfm-v1.ckpt)<br>[vae/diffusion_pytorch_model.safetensors](https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/resolve/451f4fe16113bff5a5d2269ed5ad43b0592e9a14/vae/diffusion_pytorch_model.safetensors) | `8364b475b525`<br>`a2b5134f4dbc` | LicenseRef-CreativeML-OpenRAIL-PlusPlus-M AND LicenseRef-CreativeML-OpenRAIL-M | yes |
## Licence
Original-code strings, recorded as they are (research-use package; check them before any other use). Code: MIT. Licence files: `LICENSE`, `LICENSE-MODEL`, `LICENSE-VAE`.
Training data: Stable Diffusion 2.1 (LAION-5B subsets) fine-tuned on the synthetic Hypersim and Virtual KITTI 2 datasets per the DepthFM paper (arXiv 2403.13788).
- Licence note: The UNet is fine-tuned from Stable Diffusion 2.1 (OpenRAIL++-M) and runs with the Stable Diffusion 1.5 VAE (OpenRAIL-M): commercial use is allowed but with use restrictions that must be passed on; the training data terms are not checked.
Licence evidence: https://github.com/CompVis/depth-fm/blob/da632c8118e41cc64ca191a13314e2db1a7722d9/README.md (fine-tuned from Stable Diffusion v2-1; code MIT); SD2 licence text from https://huggingface.co/sd2-community/stable-diffusion-2/blob/2511124fabf8bf30c0ca9dccd9729e7f0f2fa669/LICENSE-MODEL, SD1.5 VAE licence https://github.com/CompVis/stable-diffusion/blob/21f890f9da3cfbeaba8e2ac3c425ee9e998d5229/LICENSE
## Input size
any H x W >= 1, resized or padded inside the model
Tested up to (portable, fp16, RTX 5060 Ti 16 GB): `depthfm-v1` 1024x1024 (9.8 GiB peak allocated, 15.0 reserved)
## Speed and memory
### Depth, synthetic
| model | input | time (ms): original fp32 | original | portable | kernels | kernels speed-up: vs original | vs portable | peak memory (MiB, allocated / reserved): original | portable | kernels |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| `depthfm-v1` | 994x1482 | – | – | 5662 | – | – | – | – | 13651 / 15150 | – |
### Startup and first call
| model | load (s): original | portable | kernels | first call (s): original | portable | kernels |
| --- | --- | --- | --- | --- | --- | --- |
| `depthfm-v1` | – | 3.58 | – | – | 6.00 | – |
### torch.compile and TensorRT
| model | input | time: portable | compile | TensorRT fp16 | kernels | preparation: compile (cold first call) | ONNX + engine build | peak MiB (alloc / reserved): portable | compile | kernels | TensorRT (engine + torch) |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| `depthfm-v1` | 994x1482 | 5662 ms | deferred (build >5 min) | deferred (build >5 min) | – | – | – | 13651 / 15150 | – | – | – |
Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).
Hardware, protocol and caveats: [benchmarks](https://github.com/kleinicke/fastforks/blob/main/docs/benchmarks.md) (RTX 5060 Ti 16 GB, sm_120). Original = the original code named above at the precision of portable (fp16, or `(fp32)` where fp16 is unsupported or not finite); original fp32 = its default fp32 run. Peak memory is the torch allocator's.
## Accuracy
### Parity with the original code
Every variant is checked against reference outputs of the original code at its pinned commit. CPU, float32: max |diff| <= 0.0001 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 1 % and p99 <= 3 % of the reference's median |value| (absolute error of the output `depth`).
## Limitations
- Flow model on a noised latent: the seeded noise comes from a CPU generator and differs from the original code's device generator for the same seed.
- A traced or exported module reuses the noise of its traced shape.
- The network input sides are rounded to multiples of 64, so the aspect ratio changes slightly.
## Usage
```python
from fastforks import depth
model = depth.load("depthfm-v1") # mode="auto": the preferred backend from recorded measurements
result = model("room.jpg")
result.depth # [H, W] float32 tensor; result.kind says what the maps mean
# models that take a camera: model("room.jpg", intrinsics=K), K [3, 3] in pixels
result.backend # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16')
```
Install with `pip install fastforks` (see <https://github.com/kleinicke/fastforks>). Other variants: `depthfm-v1`.
## Kernels backend
`depth.load("depthfm-v1", mode="kernels")` runs our CUDA kernels (`cudnn_hacc`). It needs a prebuilt kernel for your GPU architecture (downloaded from <https://huggingface.co/fastforks/kernels> on first use) and a recent NVIDIA driver; if there is none it raises `BackendUnavailableError` with the reason and never falls back silently. `mode="auto"` picks `kernels` when it can run and logs the choice.
<!-- staged from fastforks 1cbf1671 (2026-11-15) -->