File size: 4,551 Bytes
35cce87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
---
license: apache-2.0
library_name: litert
pipeline_tag: depth-estimation
base_model: depth-anything/Video-Depth-Anything-Small
tags:
- litert
- tflite
- fp32
- video-depth-estimation
- video-depth-anything
- relative-depth
---

# Video-Depth-Anything-Small for LiteRT

FP32 LiteRT/TFLite export of Video Depth Anything Small for temporally consistent relative-depth estimation. The ViT-S model processes one fixed **32-frame window** and retains the upstream temporal layers. It produces relative depth, not calibrated distances in metres.

Source checkpoint: [depth-anything/Video-Depth-Anything-Small](https://huggingface.co/depth-anything/Video-Depth-Anything-Small), revision [`256875362cff76724b920335dfb4b29dd611f66e`](https://huggingface.co/depth-anything/Video-Depth-Anything-Small/tree/256875362cff76724b920335dfb4b29dd611f66e).

## Model file

[Video-Depth-Anything-Small-fp32.tflite](Video-Depth-Anything-Small-fp32.tflite) · FP32 · 116.28 MB. The file hash is in [SHA256SUMS](SHA256SUMS).

The TFLite signature is `main`. All input and output tensors are `float32`; shapes are fixed. Image/video decoding, preprocessing, and application postprocessing run on the host.

| Direction | Name | Shape | Meaning |
| --- | --- | --- | --- |
| Input | `frames` | `[32, 3, 518, 518]` | 32 normalized RGB frames, TCHW; batch fixed to one clip |
| Output | `relative_depth` | `[1, 32, 518, 518]` | Relative-depth maps, batch × time × height × width |

## Preprocessing and outputs

Decode 32 consecutive RGB frames and apply a consistent center-square crop. Divide pixel values by 255, resize each crop to **518 × 518** with OpenCV cubic interpolation, and normalize with ImageNet mean `[0.485, 0.456, 0.406]` and standard deviation `[0.229, 0.224, 0.225]`. Stack in TCHW order; the public input has no batch dimension. For these square crops, the resize matches the upstream lower-bound transform with a multiple of 14.

This file implements a single 32-frame window. For longer videos, host code must manage overlapping windows, temporal scale/shift alignment, and output resizing. See the [upstream inference implementation](https://github.com/DepthAnything/Video-Depth-Anything/blob/4f5ae23172ba60fd7bc11ef671cca678842c7072/video_depth_anything/video_depth.py). The example below processes the first 32 frames and saves depth for their square crops.

## Run on CPU

```bash
pip install ai-edge-litert huggingface_hub numpy opencv-python-headless
```

```python
import numpy as np
from huggingface_hub import hf_hub_download
from ai_edge_litert.interpreter import Interpreter
import cv2

cap = cv2.VideoCapture("video.mp4")
frames = []
try:
    for _ in range(32):
        ok, bgr = cap.read()
        if not ok:
            raise ValueError("This example requires at least 32 frames")
        h, w = bgr.shape[:2]
        side = min(h, w)
        top, left = (h - side) // 2, (w - side) // 2
        crop = bgr[top:top + side, left:left + side]
        rgb = cv2.cvtColor(crop, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0
        rgb = cv2.resize(rgb, (518, 518), interpolation=cv2.INTER_CUBIC)
        rgb = (rgb - np.array([0.485, 0.456, 0.406])) / np.array([0.229, 0.224, 0.225])
        frames.append(np.ascontiguousarray(rgb.transpose(2, 0, 1), dtype=np.float32))
finally:
    cap.release()
frames = np.stack(frames)  # [32, 3, 518, 518], no extra batch dimension

model_path = hf_hub_download("litert-community/Video-Depth-Anything-Small", "Video-Depth-Anything-Small-fp32.tflite")
interpreter = Interpreter(model_path=model_path, num_threads=4)
interpreter.allocate_tensors()
run = interpreter.get_signature_runner("main")
depth = run(frames=frames)["relative_depth"][0]  # [32, 518, 518]
np.save("relative_depth.npy", depth)
```

## Source and license

Video Depth Anything is by Sili Chen and collaborators. See the [project](https://github.com/DepthAnything/Video-Depth-Anything) and [paper](https://arxiv.org/abs/2501.12375). The source implementation is pinned to revision `4f5ae23172ba60fd7bc11ef671cca678842c7072`. This repository contains the Apache-2.0 **Small** checkpoint.

This FP32 conversion uses the original pretrained weights with a fixed-shape TFLite interface. License: [Apache 2.0](LICENSE).

## Citation

```bibtex
@article{video_depth_anything,
  title={Video Depth Anything: Consistent Depth Estimation for Super-Long Videos},
  author={Chen, Sili and Guo, Hengkai and Zhu, Shengnan and Zhang, Feihu and Huang, Zilong and Feng, Jiashi and Kang, Bingyi},
  journal={arXiv:2501.12375},
  year={2025}
}
```