Download tt-model.yaml from changh95/DepthPro2: direct link, hf CLI and curl.
- Browser
- Download file 42.2 kB
-
https://huggingface.co/changh95/DepthPro2/resolve/main/tt-model.yaml
- Command line
-
hf download hf://changh95/DepthPro2/tt-model.yaml
-
curl -L -o tt-model.yaml https://huggingface.co/changh95/DepthPro2/resolve/main/tt-model.yaml
42.2 kB
| # SPDX-License-Identifier: Apache-2.0 | |
| # tt-model-manager container manifest (schema 5.1): Apple Depth Pro 2 (S, B, L, H+ and the shared focal-length | |
| # estimator) on one Tenstorrent Blackhole p150. The published README.md is GENERATED from the `card:` block below by | |
| # `tt-model package`. | |
| # | |
| # Run EVERY tt-model command FROM THIS DIRECTORY: extra_code[].root resolves against the process CWD; --out must point | |
| # OUTSIDE this directory (package deletes <out>/<name> first). | |
| # ~/.local/share/uv/tools/tt-model/bin/python -c "from tt_kernel.container_manifest import load_container_manifest as L; L('tt-model.yaml', check_sources=True)" | |
| # sg docker -c "tt-model package --container tt-model.yaml --out <workspace>/build" | |
| # (serve + smoke + stop under the device lock, once per profile: code/scripts/container_smoke.sh <staged dir> 20000 --profile <p>) | |
| # tt-model push <staged dir> --publish # HF_TOKEN from the environment only | |
| schema: "5.1" | |
| repo: changh95/DepthPro2 | |
| name: depthpro2 # docker image / container / cache names must be lowercase | |
| # POINTERS, never baked into the image and never redistributed: `serve` / `pull --with-weights` download exactly these | |
| # files at these commits into the host HF cache (mounted at /hf). Apple's licence (research purposes only) travels | |
| # with every repo (LICENSE). The primary repo is the focal-length estimator every size shares; the four sizes are | |
| # auxiliary weights (tt-model exports them as TT_AUXILIARY_WEIGHTS=repo@rev,...; the server picks DEPTHPRO2_SIZE's). | |
| weights: | |
| repo: apple/DepthPro2-focal | |
| revision: 622659d44a2002cf9ae4333f2569afa938290d9a | |
| allow_patterns: [model.safetensors, config.json, LICENSE, README.md] # 94 MB | |
| auxiliary_weights: | |
| - repo: apple/DepthPro2-S | |
| revision: 903a1c1ade918831d138adcc4aedbcc8f4da0078 | |
| allow_patterns: [model.safetensors, config.json, LICENSE, README.md] # 97 MB | |
| - repo: apple/DepthPro2-B | |
| revision: 85e67fdfb7f5b36a6f6c4495e6789d331b1d8a04 | |
| allow_patterns: [model.safetensors, config.json, LICENSE, README.md] # 386 MB | |
| - repo: apple/DepthPro2-L | |
| revision: 849dc5461267e0bc006ec63ab46920ea1ed98702 | |
| allow_patterns: [model.safetensors, config.json, LICENSE, README.md] # 1.34 GB | |
| - repo: apple/DepthPro2-H | |
| revision: 68426c789f75a7c760273e857222625b4fe69576 | |
| allow_patterns: [model.safetensors, config.json, LICENSE, README.md] # 3.49 GB | |
| kind: tt-dit-server # the model's own FastAPI app under uvicorn (not an OpenAI-compatible API) | |
| arch: blackhole | |
| source: | |
| # tt-metal main 44d6650 (v0.80.0-dev20261006) WITH patches/tt-metal-eth-dispatch.patch and | |
| # patches/tt-metal-reshape-rm-sys1419.patch applied: a dirty tree, packaged as-is. torch 2.11.0 pin read from it. | |
| tt_metal: /home/ubuntu/experiments/tt-models/tt-metal | |
| # Schema minimum (>= 1 path relative to the tt-metal tree). The port imports nothing from tt-metal's models/. | |
| code: | |
| - models/common/lightweightmodule.py | |
| # The port itself: copied over /opt/tt-metal/<path> in the image (PYTHONPATH=/opt/tt-metal); code/ on the Hub | |
| # becomes exactly this set at every push. Never a tt-metal build input (pyproject.toml lives at the repo root). | |
| extra_code: | |
| - root: code | |
| paths: | |
| - tt_depthpro2 # API, server, smoke test, device programs, reference, tests, sample, licences | |
| - scripts/bench.py # latency per bucket and clip length (device, Python call, served) | |
| - scripts/bench_baseline.py # traced device time per stage (ENC / DEC / FOV / KV step) | |
| - scripts/make_sample_reference.py # regenerates the sample's stored CPU-reference outputs | |
| - scripts/make_demo.py # renders media/demo_sample.png from a served response | |
| - scripts/device_server_smoke.py # serving gate on the host: the app on the device vs goldens / CPU engine | |
| - scripts/container_smoke.sh # serve one profile, smoke, always stop | |
| - conftest.py | |
| - PYTHON.md | |
| ubuntu: "22.04" | |
| python: "3.12" | |
| runtime: | |
| app: tt_depthpro2.server.app:app | |
| mesh_shape_env: TT_MESH_SHAPE | |
| # On top of the kind defaults (fastapi, uvicorn, pydantic>=2, pillow) and the auto-pinned torch==2.11.0+cpu: every | |
| # third-party module on the serve path, pinned to the versions the host tests ran with. No video decoder: the | |
| # server takes frames (PNG / JPEG / a uint8 .npy); client.py decodes video files on the client. | |
| packages: | |
| - "numpy>=1.24.4,<2" | |
| - safetensors==0.8.0 | |
| - huggingface_hub==1.16.1 # snapshots of the pinned weights | |
| - pillow==12.3.0 # image decoding, 16-bit PNG output | |
| - fastapi==0.142.2 | |
| - uvicorn==0.54.0 | |
| serve: | |
| port: 20000 | |
| hardware: p150 | |
| mesh_device: P150 | |
| env: | |
| TT_WEIGHTS_REVISION: "622659d44a2002cf9ae4333f2569afa938290d9a" # == weights.revision (the focal estimator) | |
| TT_METAL_VISIBLE_DEVICES: "0" | |
| TT_DEVICE_ID: "0" | |
| # Apple's repos are public and ungated: never send a token. serve mounts the host HF cache (which may hold a | |
| # stored token file) at /hf, so huggingface_hub must not pick one up implicitly. | |
| HF_HUB_DISABLE_IMPLICIT_TOKEN: "1" | |
| # ETH dispatch: the 12x10 grid every published number uses; the smoke test fails on anything else. | |
| DEPTHPRO2_DISPATCH: "eth" | |
| DEPTHPRO2_NUM_CQS: "1" | |
| # The configuration, read once when the server starts (the device programs are compiled for it; a bad value | |
| # refuses to start). The profiles below set DEPTHPRO2_SIZE. | |
| DEPTHPRO2_SIZE: "L" | |
| DEPTHPRO2_RESOLUTIONS: "vga,vga_portrait" # 480x640 and 640x480; other sizes are resized to the nearest aspect | |
| DEPTHPRO2_WINDOW: "16" # video clip length (the official default) | |
| DEPTHPRO2_OVERLAP: "4" # buffered overlap (the official default) | |
| DEPTHPRO2_VIDEO_MODES: "auto" # buffered + unbuffered when the unbuffered caches fit 4 GB (they do | |
| # for every size at the default buckets / window: SERVING.md 4) | |
| DEPTHPRO2_KV_STREAMS: "1" # unbuffered streams open at once (one key-value cache per bucket) | |
| DEPTHPRO2_FOV: "1" | |
| DEPTHPRO2_TORCH_THREADS: "4" | |
| # The shipped engines (gated + soaked): encoder, decoder and focal-estimator trunk as persistent megakernels; | |
| # any stage can fall back to its tt-nn ops (e.g. DEPTHPRO2_ENGINE=enc=mk,dec=ttnn,fov=mk). | |
| DEPTHPRO2_ENGINE: "enc=mk,dec=mk,fov=mk" | |
| # Encoder megakernel numerics: high (the per-size defaults: fp32 LayerNorm output into QKV / FC1 and hi / lo | |
| # prefix keys on L) or fast (plain bf16 everywhere: changes L only; high costs L 5-18 % more encoder time). | |
| DEPTHPRO2_ENC_PRECISION: "high" | |
| serve_profiles: | |
| - name: s | |
| description: "Depth Pro 2 S (24M parameters): the fastest" | |
| env: {DEPTHPRO2_SIZE: "S"} | |
| - name: b | |
| description: "Depth Pro 2 B (97M parameters)" | |
| env: {DEPTHPRO2_SIZE: "B"} | |
| - name: l | |
| description: "Depth Pro 2 L (334M parameters): the default" | |
| env: {DEPTHPRO2_SIZE: "L"} | |
| - name: h | |
| description: "Depth Pro 2 H+ (872M parameters): the most accurate" | |
| env: {DEPTHPRO2_SIZE: "H"} | |
| default_profile: l | |
| # Build-time assertions, run INSIDE the finished image as uid 1000, without a device or weights. | |
| verify: | |
| # the image carries the ETH-dispatch patch (12x10 grid) and the SYS-1419 reshape guard | |
| - "assert 'single_chip_arch_1cq_no_dispatch_s' in open('/opt/tt-metal/tt_metal/impl/dispatch/topology.cpp').read()" | |
| - "assert 'dual_kernel_min_dram_dest_page_bytes' in open('/opt/tt-metal/ttnn/cpp/ttnn/operations/data_movement/reshape_view/device/reshape_rm_program_factory.cpp').read()" | |
| - "from tt_depthpro2.ttaw.device import eth_dispatch_patch_present as p; assert p(), 'ttaw does not see the ETH patch'" | |
| # the server imports without side effects; the mesh parser; the serve env resolves to the pinned configuration | |
| - "import sys, tt_depthpro2.server.app as a; assert a.app and 'ttnn' not in sys.modules and 'torch' not in sys.modules, 'the server module must import without ttnn / torch'" | |
| - "from tt_depthpro2.server.app import parse_mesh_shape as p; assert p('1x1') == p('(1, 1)') == p('1,1') == (1, 1)" | |
| - "from tt_depthpro2.server.app import load_config; c = load_config({'DEPTHPRO2_SIZE': 'L', 'DEPTHPRO2_RESOLUTIONS': 'vga,vga_portrait', 'DEPTHPRO2_WINDOW': '16', 'DEPTHPRO2_OVERLAP': '4', 'DEPTHPRO2_VIDEO_MODES': 'auto', 'DEPTHPRO2_KV_STREAMS': '1', 'DEPTHPRO2_FOV': '1', 'DEPTHPRO2_DISPATCH': 'eth', 'DEPTHPRO2_NUM_CQS': '1', 'DEPTHPRO2_ENGINE': 'enc=mk,dec=mk,fov=mk', 'TT_AUXILIARY_WEIGHTS': 'apple/DepthPro2-S@903a1c1ade918831d138adcc4aedbcc8f4da0078,apple/DepthPro2-B@85e67fdfb7f5b36a6f6c4495e6789d331b1d8a04,apple/DepthPro2-L@849dc5461267e0bc006ec63ab46920ea1ed98702,apple/DepthPro2-H@68426c789f75a7c760273e857222625b4fe69576', 'TT_MODEL_WEIGHTS_REVISION': '622659d44a2002cf9ae4333f2569afa938290d9a'}); m = c.model; assert m.engine == {'enc': 'mk', 'dec': 'mk', 'fov': 'mk'}, m.engine; assert (m.size, m.resolutions, m.window, m.overlap, m.video_modes, m.video_modes_auto, m.kv_streams, m.clip_lengths, m.fov, c.dispatch, c.num_command_queues, c.revision, c.fov_revision) == ('L', ((480, 640), (640, 480)), 16, 4, ('buffered', 'unbuffered'), True, 1, (1, 16), True, 'eth', 1, '849dc5461267e0bc006ec63ab46920ea1ed98702', '622659d44a2002cf9ae4333f2569afa938290d9a'), c" | |
| # a bad configuration refuses to start | |
| - "from tt_depthpro2.server.app import load_config as L\nfor bad in ({'DEPTHPRO2_SIZE': 'XL'}, {'DEPTHPRO2_RESOLUTIONS': '480x'}, {'DEPTHPRO2_WINDOW': '17'}, {'DEPTHPRO2_OVERLAP': '16'}, {'DEPTHPRO2_VIDEO_MODES': 'live'}, {'DEPTHPRO2_KV_STREAMS': '0'}, {'DEPTHPRO2_ENGINE': 'dec=gpu'}, {'DEPTHPRO2_ENC_PRECISION': 'medium'}, {'TT_MESH_SHAPE': '1x2'}):\n try:\n L(bad)\n except RuntimeError:\n continue\n raise AssertionError(bad)" | |
| # the weights pins (focal + the four sizes) | |
| - "from tt_depthpro2.config import WEIGHTS; assert WEIGHTS == {'focal': ('apple/DepthPro2-focal', '622659d44a2002cf9ae4333f2569afa938290d9a'), 'S': ('apple/DepthPro2-S', '903a1c1ade918831d138adcc4aedbcc8f4da0078'), 'B': ('apple/DepthPro2-B', '85e67fdfb7f5b36a6f6c4495e6789d331b1d8a04'), 'L': ('apple/DepthPro2-L', '849dc5461267e0bc006ec63ab46920ea1ed98702'), 'H': ('apple/DepthPro2-H', '68426c789f75a7c760273e857222625b4fe69576')}" | |
| # the API, the CPU engine, the streaming and the reference import (torch, no device) | |
| - "import tt_depthpro2.api, tt_depthpro2.cpu_engine, tt_depthpro2.streaming, tt_depthpro2.reference.model as R; assert R.SIZES['H'].swiglu and tt_depthpro2.api.plan_buffered_clips(10, 4, 1) == [4, 4, 4]" | |
| # the device module: the DepthPro2Device API the server uses, its sizing helpers, and the megakernel sources | |
| # (JIT-compiled at the first start) shipped as files | |
| - "from tt_depthpro2.tt.model import DepthPro2Device as D, trace_region_bytes, planned_frames, kv_state_bytes; import inspect; p = inspect.signature(D).parameters; assert D.supports_kv_cache and all(k in p for k in ('fov_shapes', 'clip_lengths', 'precision', 'kv_cache', 'kv_streams')) and hasattr(D, 'inverse_depth_step') and trace_region_bytes('L', [(480, 640), (640, 480)], [1, 16], kv_cache=True) > (64 << 20)" | |
| - "import importlib.util; from pathlib import Path; d = Path('/opt/tt-metal/tt_depthpro2/tt'); assert all((d / f'mk_enc/kernels/me_{r}.cpp').is_file() and (d / f'mk_dec/kernels/md_{r}.cpp').is_file() for r in ('brisc', 'ncrisc', 'trisc')) and all(importlib.util.find_spec(f'tt_depthpro2.tt.{m}') for m in ('mk_enc', 'mk_fov', 'mk_dec'))" | |
| - "from pathlib import Path; d = Path('/opt/tt-metal/tt_depthpro2/tt'); n = {p.name for p in (d / 'mk_enc' / 'kernels').iterdir()}; m = {p.name for p in (d / 'mk_dec' / 'kernels').iterdir()}; assert {'me_brisc.cpp', 'me_ncrisc.cpp', 'me_trisc.cpp', 'me_defs.hpp', 'me_dm.hpp'} <= n and {'md_brisc.cpp', 'md_ncrisc.cpp', 'md_trisc.cpp', 'md_defs.hpp'} <= m, (n, m)" | |
| # the default engines: the three megakernels; each stage can fall back to tt-nn | |
| # the encoder precision switch: high by default; fast maps to the megakernel's v1 options before any program is built | |
| - "from tt_depthpro2 import config as C; assert C.resolve_config(env={}).enc_precision == 'high' and C.resolve_config(env={'DEPTHPRO2_ENC_PRECISION': 'fast'}).enc_precision == 'fast' and C.mk_enc_options('fast', 'exp=1,inx32=1') == 'exp=1,inx32=0,klo=0' and C.mk_enc_options('high', 'inx32=0,klo=0') == ''; from tt_depthpro2.tt.mk_enc.program import env_options; import os; os.environ['DEPTHPRO2_MK_ENC_OPTS'] = C.mk_enc_options('fast'); assert env_options() == {'inx32': False, 'klo': 0}, env_options()" | |
| - "from tt_depthpro2.config import DEFAULT_ENGINE, resolve_config; assert DEFAULT_ENGINE == {'enc': 'mk', 'dec': 'mk', 'fov': 'mk'} and resolve_config(env={}).engine == DEFAULT_ENGINE and resolve_config(env={'DEPTHPRO2_ENGINE': 'dec=ttnn'}).engine == {'enc': 'mk', 'dec': 'ttnn', 'fov': 'mk'}" | |
| # the shipped sample (CC0), its stored CPU-reference outputs for every size, the licence notice, the scripts | |
| - "import hashlib, json; from pathlib import Path; d = Path('/opt/tt-metal/tt_depthpro2/samples/kropa_street'); assert hashlib.sha256((d / 'image.jpg').read_bytes()).hexdigest() == 'dee4f3aafb7a1724d251e9af56ad9cd5eebbb95289ff63f4cdc1a2e0609445ae' and (d / 'PROVENANCE.md').is_file() and all(json.loads((d / f'reference.{s}.json').read_text())['size'] == s and (d / f'reference.{s}.npy').is_file() for s in 'SBLH')" | |
| - "from pathlib import Path; d = Path('/opt/tt-metal/tt_depthpro2/licenses'); assert 'Apple Machine Learning Research Model is licensed under the Apple Machine Learning Research Model License Agreement.' in (d / 'NOTICE.md').read_text() and 'Research Purposes' in (d / 'APPLE_MLR_MODEL_LICENSE.txt').read_text() and (d / 'APPLE_SOFTWARE_LICENSE.txt').read_text().startswith('Copyright (C) 2026 Apple Inc.')" | |
| - "from pathlib import Path; assert all(Path('/opt/tt-metal', p).is_file() for p in ('tt_depthpro2/server/smoke_test.py', 'tt_depthpro2/server/client.py', 'scripts/bench.py', 'scripts/container_smoke.sh', 'scripts/make_sample_reference.py', 'scripts/make_demo.py', 'scripts/device_server_smoke.py'))" | |
| # the dependencies, at the versions the tests ran with | |
| - "import numpy; assert int(numpy.__version__.split('.')[0]) < 2, numpy.__version__" | |
| - "import safetensors, huggingface_hub, PIL, fastapi, uvicorn; assert (safetensors.__version__, PIL.__version__) == ('0.8.0', '12.3.0'), (safetensors.__version__, PIL.__version__)" | |
| - "import torch; assert torch.__version__.startswith('2.11.0'), torch.__version__" | |
| - "import ttnn; assert all(hasattr(ttnn, a) for a in ('DispatchCoreConfig', 'begin_trace_capture', 'end_trace_capture', 'execute_trace', 'release_trace', 'copy_host_to_device_tensor', 'generic_op'))" | |
| card: | |
| # Facts and measurements of the shipped package only (the model-card-standardizer field guide). | |
| attribution: >- | |
| Derived from Apple's [Depth Pro 2](https://huggingface.co/apple/DepthPro2) | |
| ([apple/DepthPro2-S](https://huggingface.co/apple/DepthPro2-S), [-B](https://huggingface.co/apple/DepthPro2-B), | |
| [-L](https://huggingface.co/apple/DepthPro2-L), [-H](https://huggingface.co/apple/DepthPro2-H) and the shared | |
| focal-length estimator [apple/DepthPro2-focal](https://huggingface.co/apple/DepthPro2-focal)), with unmodified | |
| weights downloaded from Apple's repositories. Official code: | |
| [apple-aiml-research/ml-depth-pro-2](https://github.com/apple-aiml-research/ml-depth-pro-2). This is a | |
| third-party port (a model derivative), not an Apple product, and is not affiliated with or endorsed by Apple. | |
| Apple Machine Learning Research Model is licensed under the Apple Machine Learning Research Model License | |
| Agreement. See the original model card for training details. | |
| description: >- | |
| Depth Pro 2 estimates metric depth (metres) and the camera's focal length from a single RGB image or from the | |
| frames of a video. Four sizes are served from one image, as the serve profiles `s`, `b`, `l` (default) and `h`: | |
| S (24M parameters), B (97M), L (334M) and H+ (872M). Each is a DINOv3 vision transformer with 16 x 16 patches and | |
| class / register tokens, in which some blocks attend across all frames of a clip, followed by a DPT decoder and | |
| head that output the focal-normalized inverse depth at the input resolution. A shared DINOv3 ViT-S with an | |
| attention head estimates the field of view, from which the focal length in pixels follows (median over a clip); | |
| metric depth is `f_px / (width * inverse_depth)`, infinite for sky. Inputs run at resolution buckets fixed when | |
| the server starts (480 x 640 and 640 x 480 by default; up to 8 buckets from presets such as 720p or 1080p, or any | |
| size); an input of another size is resized to the bucket of the nearest aspect ratio and the outputs are resized | |
| back. Videos run as overlapping clips of 16 frames (4 shared), cross-faded, as Apple's buffered streaming does, | |
| or frame by frame with a key-value cache of the previous frames (Apple's unbuffered streaming). | |
| The package includes the pre- and post-processing (EXIF orientation and 35 mm focal length, normalization, | |
| padding, the FOV resize, the focal-length median). Decoding, resizing and post-processing run on the host CPU; the | |
| network runs on the device as three persistent megakernels, the encoder, the decoder and the focal-length | |
| estimator's trunk (one program each per input shape, replayed from traces). | |
| intended_use: >- | |
| Non-commercial scientific research with Depth Pro 2's metric depth and focal-length estimates on images and | |
| video, for example studying the model's outputs, comparing implementations, or offline experiments, one request | |
| at a time. Apple's licence limits every use of the weights and of models derived from them to research purposes. | |
| prerequisites: | | |
| - Read and accept the [Apple Machine Learning Research Model License Agreement](https://huggingface.co/apple/DepthPro2/blob/main/LICENSE) (research purposes only) before downloading the weights | |
| - About 5.4 GB of free disk for the weights of all four sizes and the focal-length estimator (fetched once into the Hugging Face cache, whichever profile is served), plus the container image | |
| quickstart: | | |
| Send the sample image shipped in this repo (a 640 x 480 CC0 street photo) to `/predict` (JSON) and to | |
| `/predict_png` (raw file in, 16-bit depth PNG out), on the port `tt serve` reported: | |
| ```bash | |
| curl -sLO https://huggingface.co/changh95/DepthPro2/resolve/main/code/tt_depthpro2/samples/kropa_street/image.jpg | |
| python3 -c "import base64, json; json.dump({'image': base64.b64encode(open('image.jpg', 'rb').read()).decode()}, open('req.json', 'w'))" | |
| curl -s localhost:20000/predict -H 'Content-Type: application/json' -d @req.json -o resp.json | |
| curl -s localhost:20000/predict_png --data-binary @image.jpg -o depth16.png # uint16 = round(depth_m * 1000) | |
| python3 -c "import base64, io, json, numpy as np; r = json.load(open('resp.json')); d = np.load(io.BytesIO(base64.b64decode(r['depth']['data']))); print(d.shape, r['focallength_px'], r['stats_m'])" | |
| ``` | |
| usage: | | |
| `POST /predict` takes one base64 image and returns its depth map; `POST /predict_png` takes the raw image file and | |
| returns a 16-bit depth PNG; `POST /predict_video` takes the frames of a clip or video and returns one depth map | |
| per frame. `GET /health` reports readiness, `GET /info` the weights and their commits, the device, the engines, | |
| the configuration and the limits, `GET /config` the configuration only; `GET /v1/models` is a stub, not a chat | |
| API. | |
| | request field (`POST /predict`) | meaning | | |
| | --- | --- | | |
| | `image` | base64 image file (PNG, JPEG or any format Pillow reads), 16 to 8192 px per side, at most 50 megapixels; turned upright per its EXIF orientation | | |
| | `f_px` (optional) | the focal length in pixels of the image; default: the image's EXIF 35 mm-equivalent focal length, else the model's estimate | | |
| | `use_exif` (optional) | `true` (default): use the EXIF focal length when `f_px` is not given | | |
| | `output_format` (optional) | `npy16` (default: base64 float16 `.npy`), `npy32` (float32), `png16` (base64 16-bit PNG, `uint16 = round(depth_m * png_scale)`, 0 = infinite) or `none` (statistics only) | | |
| | `include_inverse_depth` (optional) | also return the focal-normalized inverse depth | | |
| | `png_scale` (optional) | `png16`: units per metre, default 1000 (millimetres; 65.535 m saturates) | | |
| `POST /predict_png` takes the image file as the body and the query parameters `f_px`, `png_scale` and `use_exif`; | |
| the focal length, the statistics and the timing come back in `X-Focal-Length-Px`, `X-Stats-M`, `X-Timing-Ms` and | |
| further `X-*` headers. | |
| | request field (`POST /predict_video`) | meaning | | |
| | --- | --- | | |
| | `frames` or `clip` | base64 image files in order, or one base64 uint8 `(T, H, W, 3)` `.npy` / `.npz`; one size per video; at most 64 frames per request | | |
| | `mode` (optional) | `buffered` (default: clips of 16 frames overlapping by 4, cross-faded; one focal length per video, from the first 16 frames), `unbuffered` (each frame attends a key-value cache of the previous 15 frames and is returned at once), `clip` (the frames as one clip that attends to itself, 1 to 16 frames) | | |
| | `stream` (optional) | `{"id": "<any>", "end": false}` keeps a buffered or unbuffered stream open across requests for long or live videos; each request returns the frames it finishes, `end: true` returns the rest and closes it; one unbuffered stream at a time by default | | |
| | `f_px`, `window`, `overlap`, `output_format`, `include_inverse_depth` (optional) | as above; `window` / `overlap` at most the server's | | |
| Response of `/predict` for the sample image as served on the p150 (depth data elided, values rounded, profile | |
| `l`): | |
| ```json | |
| {"model": "depthpro2", "size": "L", "frames": 1, "input_size": [480, 640], "bucket": [480, 640], | |
| "device_size": [480, 640], "resized": false, "focallength_px": 490.04, "focal_source": "fov", | |
| "fov_deg": [[65.85, 52.19]], | |
| "depth": {"format": "npy", "dtype": "float16", "shape": [480, 640], "data": "...", "units": "m"}, | |
| "stats_m": {"pixels": 307200, "infinite_pixels": 32160, "min": 1.43, "p05": 1.68, "median": 6.96, | |
| "p95": 29.6, "max": 44182.7}, | |
| "timing_ms": {"decode": "...", "preprocess": "...", "device": "...", "fov": "...", "postprocess": "...", | |
| "encode": "...", "total": "..."}} | |
| ``` | |
| - `depth` is metres along the optical axis at the input size; `inf` (`infinite_pixels`) marks sky, where the | |
| network's inverse depth is 0. Decode with `np.load(io.BytesIO(base64.b64decode(depth["data"])))`; values | |
| above 65504 m read as `inf` in the float16 encoding (`npy32` keeps them). | |
| - `focallength_px` is in input pixels; `focal_source` is `request`, `exif` or `fov`. `fov_deg` is the estimated | |
| horizontal and vertical field of view per frame. | |
| - An input of exactly a bucket's size runs natively (`resized: false`); any other size is resized to the bucket | |
| of the nearest aspect ratio and back (`resized: true`). `/info` lists the buckets. | |
| - `timing_ms` is measured in the server: decoding, pre-processing, the device run, the focal-length estimate, | |
| post-processing and response encoding. | |
| - Errors: HTTP 400 with the reason for an image that cannot be decoded or is out of the size range, a | |
| non-positive `f_px`, frames of different sizes, a clip length the device programs were not built for, or a | |
| disabled video mode; 422 for an unknown field or a value of the wrong type; 429 when too many video streams are | |
| open; 503 while the server starts; 500 with the exception text on a device failure. | |
| - A Python API with the same outputs (`tt_depthpro2.DepthPro2`: `infer`, `infer_clip`, `infer_video`, `stream`) | |
| is described in [`code/PYTHON.md`](code/PYTHON.md); it needs a tt-metal build with the two patches in | |
| [`patches/`](patches/). | |
| ### Configuration | |
| The server builds its device programs for one configuration when it starts; change it with environment variables | |
| in the container's launch command (`tt-model serve --print` prints it) and start it again. `GET /config` reports | |
| it. | |
| | item | environment variable | values | default | | |
| | --- | --- | --- | --- | | |
| | model size | `DEPTHPRO2_SIZE` (the serve profiles set it) | `S`, `B`, `L`, `H` | `L` (profile `l`) | | |
| | resolution buckets | `DEPTHPRO2_RESOLUTIONS` | up to 8 of `HxW` (32 to 4096 px per side) or `qvga`, `vga`, `square`, `720p`, `1080p` and their `_portrait` forms | `vga,vga_portrait` | | |
| | video clip length | `DEPTHPRO2_WINDOW` | 1 to 16 | 16 | | |
| | buffered overlap | `DEPTHPRO2_OVERLAP` | 0 to window - 1 | 4 | | |
| | further clip lengths | `DEPTHPRO2_CLIP_LENGTHS` | `auto` (1 and the window), `all`, or a list | `auto` | | |
| | focal-length estimator | `DEPTHPRO2_FOV` | 1 / 0 | 1 | | |
| | video modes | `DEPTHPRO2_VIDEO_MODES` | `buffered`, `unbuffered`, both, or `auto` | `auto`: both when the key-value caches fit 4 GiB of device memory | | |
| | unbuffered streams open at once | `DEPTHPRO2_KV_STREAMS` | 1 to 8 (one cache per bucket each) | 1 | | |
| | device engines | `DEPTHPRO2_ENGINE` | per stage `mk` (megakernel) or `ttnn` (tt-nn operations), e.g. `dec=ttnn`; stages not named keep the default | `enc=mk,dec=mk,fov=mk` | | |
| | encoder precision | `DEPTHPRO2_ENC_PRECISION` | `high`: on L, float32 LayerNorm output into the attention and MLP input matmuls and two-part (hi / lo) prefix keys; `fast`: the plain bfloat16 encoder on L too (`high` costs L 5-18 % more encoder time); S, B, H+ and the focal-length estimator run the same either way | `high` | | |
| Every bucket adds device programs and their start-up time; any clip length up to the window runs on the window's | |
| program. The unbuffered key-value caches take device memory per bucket and stream (window 16): | |
| | size | per 480 x 640 bucket | default (2 buckets, 1 stream) | per 1080 x 1920 bucket | | |
| | --- | --- | --- | --- | | |
| | S | 108 MiB | 217 MiB | 720 MiB | | |
| | B | 217 MiB | 434 MiB | 1.41 GiB | | |
| | L | 578 MiB | 1.13 GiB | 3.75 GiB | | |
| | H+ | 993 MiB | 1.94 GiB | 6.45 GiB (above the `auto` budget: buffered only) | | |
| ### Example output | |
|  | |
| 92 frames (7.4 s at 12.5 frames/s) of a walk down Trubarjeva street in Ljubljana, resized to the 480 x 640 bucket | |
| and sent to this package's container (profile `l`) as one buffered `/predict_video` stream (16-frame clips | |
| overlapping by 4). Left: the input; right: the inverse depth it returned, on one logarithmic colour scale for the | |
| whole clip (near = red, far = blue, sky = black). Also as [MP4](media/demo_tt.mp4) (1280 x 512, H.264). Source | |
| video: "Walking down the Trubarjeva street" by Sounds of Changes, | |
| [Wikimedia Commons](https://commons.wikimedia.org/wiki/File:Walking_down_the_Trubarjeva_street.webm), | |
| [CC BY 3.0](https://creativecommons.org/licenses/by/3.0/), trimmed, cropped, resized and shown with the model's | |
| output; its author does not endorse this work. Attributions for every file in `media/`: | |
| [`media/ATTRIBUTION.md`](media/ATTRIBUTION.md). | |
|  | |
| The shipped sample image (CC0) and the inverse depth `/predict` returned for it on profile `l` (the response | |
| shown above), with the focal length and the depth range in the caption. | |
| # To fill from the device gates and bench.py (SPEC section 5), one row per size where it applies: | |
| # ACCURACY_TABLE: | eval | S | B | L | H+ | cases | rows: inverse-depth PCC (min over img_vga, img_375x500_pad, | |
| # clip4_240x320), depth AbsRel vs Apple float32 next to Apple's own bf16 drift, f_px relative error, buffered | |
| # video stream_buf_w4o1_n10 (S), the shipped sample vs the stored CPU reference. | |
| # SPEED_TABLE: | speed (batch 1, warm) | input | S | B | L | H+ | rows: device time per image 480x640 (trace | |
| # replay), per 16-frame clip (frames/s), FOV; Python infer(); served /predict timing_ms.total and client round | |
| # trip; then one measurement sentence (host, bench.py arguments, iterations). | |
| performance: | | |
| Agreement with Apple's own float32 code on the CPU (same weights and inputs) of the shipped engines (encoder, | |
| decoder and focal-estimator megakernels), per size, with Apple's own bfloat16 run (its default on GPUs) in | |
| parentheses: | |
| | eval | S | B | L | H+ | frames | | |
| | --- | --- | --- | --- | --- | --- | | |
| | Inverse depth PCC, a 480 x 640 image | 0.999996 | 0.999997 | 0.999999 | 0.999999 | 1 | | |
| | Depth AbsRel, a 480 x 640 image | 0.0035 (0.0039) | 0.0025 (0.0021) | 0.0014 (0.0035) | 0.0024 (0.0016) | 1 | | |
| | Inverse depth PCC / depth AbsRel, a 4-frame 240 x 320 clip (frames attending each other) | 0.999998 / 0.0062 (0.0055) | 0.999998 / 0.0037 (0.0032) | 0.999999 / 0.0018 (0.0042) | 0.999998 / 0.0019 (0.0020) | 4 | | |
| | Inverse depth PCC / depth AbsRel, a 375 x 500 image (padded to 384 x 512) | 0.99961 / 0.0179 (0.0133) | 0.99992 / 0.0094 (0.0079) | 0.9913 [1] / 0.0049 (0.0052) | 0.99993 / 0.0057 (0.0050) | 1 | | |
| | Focal length error: 480 x 640 image / 4-frame clip / 375 x 500 image | 0.05 % / 0.16 % / 1.0 % (0.12 % / 0.13 % / 1.45 %) | same estimator | same estimator | same estimator | 6 | | |
| | Inverse depth PCC, every frame of a 16-frame 480 x 640 clip, a 5-frame clip and a 20-frame buffered video (lowest frame, vs this package's float32 CPU reference) | 0.99998 | 0.999996 | 0.999997 | 0.999998 | 41 | | |
| | Unbuffered video, every frame (key-value cache; 6 frames of 480 x 640, vs this package's float32 CPU reference) | 0.999988 | 0.999995 | 0.999997 | 0.999998 | 6 | | |
| AbsRel is the mean relative depth error over the pixels within 100 times the nearest distance, with Apple's | |
| focal length. Apple's float32 output exists for every case except the 375 x 500 image at L and H+, which is | |
| compared with this package's float32 CPU reference (equal to Apple's float32 code to a relative error of 1e-5, | |
| this image included); the numbers in parentheses are Apple's own code run in bfloat16 on the same inputs. The | |
| focal-length estimator is shared by every size. [1] L's prediction for this image is nearly flat (its inverse | |
| depth varies by about 6 % across the image, against 33-42 % for the other sizes), so its PCC is low (0.991 here, | |
| against 0.9995 for Apple's own bfloat16 run), but its depth AbsRel (0.0049) is within Apple's own bfloat16 AbsRel | |
| (0.0052). | |
| Determinism: the encoder megakernel gave bit-identical outputs over 1000 trace replays (after 10 to 21 launches) | |
| at each soaked configuration (S at 480 x 640 with 1 and 16 frames, B with 1, L with 1, 4 and 16, H+ with 1 and 4 | |
| and at 736 x 1280), as did the focal-estimator trunk, with no hang; the decoder megakernel over 22 launches and 1000 trace replays at each of 15 configurations (every | |
| size at 640 x 480 with 1 and 16 frames; 480 x 640 with 16 frames for S, L and H+, with 4 frames for B and H+, with | |
| 1 frame for H+; 736 x 1280 for L), with no hang, and over 500 trace replays at each of 20 (every size at 480 x 640 | |
| with 1, 4 and 16 frames, 736 x 1280 and 1088 x 1920). | |
| | speed (batch 1, warm) | input | S | B | L | H+ | | |
| | --- | --- | --- | --- | --- | --- | | |
| | Device time, encoder megakernel: 1 frame / 16-frame clip | 480 x 640 | 4.2 / 158 ms | 8.2 / 325 ms | 23.2 / 947 ms | 42.2 / 1933 ms | | |
| | Device time, decoder megakernel: 1 frame / 16 frames | 480 x 640 | 1.5 / 11.3 ms | 3.3 / 22.3 ms | 8.1 / 62.2 ms | 8.3 / 63.8 ms | | |
| | Device time, focal-estimator megakernel: 1 / 4 frames | 480 x 640 | 5.7 / 18.3 ms | same | same | same | | |
| | Device time per image (encoder + decoder) | 480 x 640 | 5.7 ms | 11.5 ms | 31.4 ms | 51.8 ms | | |
| | Device time per 16-frame clip (frames/s) | 16 x 480 x 640 | 170 ms (94) | 347 ms (46) | 1.01 s (15.9) | 2.00 s (8.0) | | |
| | Served `POST /predict`, server `timing_ms.total` (focal estimated) | the sample, 640 x 480 JPEG | 40 ms | 44 ms | 67 ms | 84 ms | | |
| | Served `POST /predict`, client round trip on loopback | the sample | 57 ms | 62 ms | 85 ms | 102 ms | | |
| | Served `POST /predict_video`, one 16-frame clip, client round trip | 16 frames of 480 x 640 | 1.63 s | 1.69 s | 2.32 s | 3.34 s | | |
| | Served `POST /predict_video`, a 5-frame clip (runs on the 16-frame program), client round trip | 5 frames of 480 x 640 | 0.73 s | 0.78 s | 1.12 s | 1.65 s | | |
| | Served `POST /predict_video`, buffered video of 20 frames (two 16-frame clips), client round trip | 20 frames of 480 x 640 | 2.26 s | 2.53 s | 3.89 s | 5.73 s | | |
| | Served unbuffered stream, one frame per request (tt-nn encoder step, decoder megakernel, 16-frame cache), client round trip | 480 x 640 frames | 87-101 ms | 115-130 ms | 200-228 ms | 305-347 ms | | |
| | Server start-up in the container (compile and capture every program): a restart with the kernel cache of an earlier start / the first start (empty kernel cache) | default configuration | 20 s / 169 s | 27 s / 172 s | 38 s / 186 s | 58 s / 211 s | | |
| Device times: traced replays back to back on one p150, 20 per configuration, with the default encoder precision | |
| `high` (the decoder rows from the decoder megakernel's release benchmark; per image and per clip: encoder and | |
| decoder replayed together). Served rows: | |
| requests to the HTTP server of this package with its default configuration (buckets 480 x 640 and 640 x 480, | |
| window 16, unbuffered video on) on the same p150 in an 8-vCPU AMD EPYC-Rome host | |
| (`code/scripts/device_server_smoke.py`: 10 requests of the sample, one of each video request; the video requests | |
| returned float32 depth and inverse depth for every frame, which is part of their time). A served request adds | |
| image decoding, resizing, the focal estimate when no `f_px` is sent and the response encoding on the host CPU. | |
| Start-up: the server's own "ready in" time in the container started by `tt serve`, per profile; the first start | |
| compiles the device kernels into the container's kernel cache, which `tt serve` keeps for later starts. | |
| limitations: | | |
| - Research use only: Apple's licence allows the weights, and models derived from them such as this package, to be | |
| used exclusively for non-commercial scientific research; no commercial use, product development or use in a | |
| commercial product or service. Not for safety-critical uses (driving, robot control, medical or industrial | |
| measurement): the depth is an estimate from one camera, unvalidated for such uses, on the device and on Apple's | |
| code alike. | |
| - Inputs of a size that is not a configured bucket are resized to the bucket of the nearest aspect ratio and the | |
| outputs are resized back, so their results approximate what the network gives at the input's own size (an | |
| aspect ratio far from every bucket is stretched, and a small image upscaled to a larger bucket changes the | |
| focal-length estimate). Configure your camera's native resolution as a bucket (`DEPTHPRO2_RESOLUTIONS`) for the | |
| most faithful results. | |
| - Accuracy outside the gate images: on an independent held-out set (10 inputs: outdoor, indoor, portrait, | |
| telephoto and near-flat images plus a 4- and an 8-frame clip; 40 cases over the four sizes, scored against | |
| Apple's float32 output with the same gates), 38 of 40 pass (S 10, B 9, L 10, H+ 9). The two misses: B on a | |
| sky-and-water landscape, depth AbsRel 0.013 against a budget of 0.010 (Apple's own bfloat16: 0.004), a uniform | |
| 1.5 % depth scale offset; H+ on a 4-frame close-up clip, inverse-depth PCC 0.993 against 0.999, where Apple's own | |
| bfloat16 run reaches only 0.995 (its depth AbsRel, 0.014, is lower than that run's 0.017). The closest passes | |
| are S on the 8-frame clip (AbsRel 0.024 within 0.026) and L on a bright-background beach portrait (0.025 | |
| within 0.035; Apple's bfloat16 0.018). On four further inputs, used to | |
| tune L's encoder precision and so not held out, L reaches an inverse-depth PCC of 0.99957 on Apple's | |
| `images.jpg` at 480 x 640, while S's depth AbsRel on that photo is 0.027, 2.05 times Apple's own bfloat16 error | |
| (0.0133), just over the 2x target. | |
| - The resolution buckets and the video window are fixed when the server starts. A clip shorter than the window | |
| runs on the window's device program and takes as long as a full window. | |
| - Buffered video returns a frame only once its clip is predicted, so it lags the input by up to a window; | |
| unbuffered video returns each frame at once but sees only earlier frames, and one unbuffered stream is open at | |
| a time by default (more need `DEPTHPRO2_KV_STREAMS`; a stream beyond it is refused with HTTP 429). The | |
| unbuffered frame-by-frame steps run the encoder in tt-nn operations (the encoder megakernel has no key-value | |
| cache path), so they are slower per frame than an image. | |
| - The tt-nn decoder remains selectable (`DEPTHPRO2_ENGINE=dec=ttnn`), as does each stage's tt-nn implementation. | |
| - The tt-nn encoder (the unbuffered steps, and `enc=ttnn`) uses tt-nn's scaled-dot-product attention, which | |
| returned wrong rows when its batch x heads exceeded 24 (tt-nn encoder clips of 16 frames at 480 x 640 or of 4 | |
| frames for H+); the package runs those attentions in tt-nn's windowed mode, which is correct and gives the same | |
| results. | |
| - Batch 1; requests are served one at a time. One p150 only: the image runs device dispatch on the chip's Ethernet | |
| cores, so multi-chip meshes are not supported. | |
| - Precision: bfloat16 weights and activations on the device with float32 accumulation, residual streams, | |
| normalisation statistics and positional rotations, against Apple's float32 reference (Apple evaluates in | |
| bfloat16 on GPUs); Expected performance gives the measured agreement. | |
| - All four sizes' weights are downloaded whichever profile is served. The focal length comes from the image's EXIF | |
| data when present (35 mm-equivalent focal length), which can be wrong for cropped or digitally zoomed images: | |
| pass `f_px` or `use_exif: false` then. | |
| licensing: | | |
| - Weights (not redistributed here; `tt serve` downloads them from Apple's repositories at these commits): | |
| [apple/DepthPro2-focal](https://huggingface.co/apple/DepthPro2-focal) `622659d4`, | |
| [apple/DepthPro2-S](https://huggingface.co/apple/DepthPro2-S) `903a1c1a`, | |
| [apple/DepthPro2-B](https://huggingface.co/apple/DepthPro2-B) `85e67fdf`, | |
| [apple/DepthPro2-L](https://huggingface.co/apple/DepthPro2-L) `849dc546`, | |
| [apple/DepthPro2-H](https://huggingface.co/apple/DepthPro2-H) `68426c78`, under the | |
| [Apple Machine Learning Research Model License Agreement](https://huggingface.co/apple/DepthPro2/blob/main/LICENSE): | |
| **research purposes only**. Apple Machine Learning Research Model is licensed under the Apple Machine Learning | |
| Research Model License Agreement. A copy of the agreement and the notices are in | |
| [`code/tt_depthpro2/licenses/`](code/tt_depthpro2/licenses/NOTICE.md). | |
| - This package is a model derivative of Depth Pro 2 and is identified as such. Its modifications: the inference | |
| code is re-implemented (the network and the pre- and post-processing written anew; the video streaming logic | |
| follows the structure of Apple's `streaming.py`, see below); on the device the network runs in bfloat16 in | |
| tt-nn operations and custom device kernels; inputs are resized to fixed resolution buckets. The weights are | |
| loaded unmodified. Apple's name is used only to identify the original model; Apple does not endorse this | |
| package. | |
| - The video streaming logic (`code/tt_depthpro2/streaming.py`) follows the structure of Apple's `streaming.py` | |
| from [apple-aiml-research/ml-depth-pro-2](https://github.com/apple-aiml-research/ml-depth-pro-2) (Copyright (C) | |
| 2026 Apple Inc.), used under Apple's software licence, a copy of which is | |
| [`code/tt_depthpro2/licenses/APPLE_SOFTWARE_LICENSE.txt`](code/tt_depthpro2/licenses/APPLE_SOFTWARE_LICENSE.txt). | |
| - Port, server and scripts (`code/`, except as noted above) and the tt-metal patches in [`patches/`](patches/): | |
| Apache-2.0. | |
| - Sample `code/tt_depthpro2/samples/kropa_street/image.jpg`: "Kropa, cobblestone side street 01" by Ajznponar, | |
| [Wikimedia Commons](https://commons.wikimedia.org/wiki/File:Kropa,_cobblestone_side_street_01.jpg), CC0 1.0 | |
| (public domain dedication), resized to 640 x 480 without its EXIF data; the `reference.*` files next to it hold | |
| this package's float32 CPU outputs for it. | |
| - Demo media: `media/demo_tt.gif` and `media/demo_tt.mp4` are rendered from "Walking down the Trubarjeva street" | |
| by Sounds of Changes ([Wikimedia Commons](https://commons.wikimedia.org/wiki/File:Walking_down_the_Trubarjeva_street.webm), | |
| [CC BY 3.0](https://creativecommons.org/licenses/by/3.0/)), trimmed, cropped, resized and shown with the | |
| model's output, and are distributed under CC BY 3.0; the author does not endorse this work. | |
| `media/demo_sample.png` shows the CC0 sample above with its output. Attributions: | |
| [`media/ATTRIBUTION.md`](media/ATTRIBUTION.md). | |
| related: | | |
| - [changh95/depth-anything-3-p150](https://huggingface.co/changh95/depth-anything-3-p150): Depth Anything 3 metric depth on p150. | |
| license: | |
| id: other | |
| name: Apple AMLR | |
| link: https://huggingface.co/apple/DepthPro2/blob/main/LICENSE | |
| pipeline_tag: depth-estimation | |
| base_model: | |
| - apple/DepthPro2-L | |
| - apple/DepthPro2-S | |
| - apple/DepthPro2-B | |
| - apple/DepthPro2-H | |
| - apple/DepthPro2-focal | |