Skip to content

Repository files navigation

🎬 StreamDepth: Real-Time Streaming Video Depth Estimation

Non-Streaming Teacherμ—μ„œ Streaming Student둜의 Knowledge Distillation을 ν†΅ν•œ
μ‹€μ‹œκ°„ 슀트리밍 λΉ„λ””μ˜€ 깊이 μΆ”μ •

Python PyTorch License

πŸš€ Quick Start β€’ πŸ“– Method β€’ πŸ”¬ Results β€’ πŸ“Š Benchmark


🎯 Overview

StreamDepthλŠ” λΉ„λ””μ˜€ 깊이 μΆ”μ •(Video Depth Estimation)을 μ‹€μ‹œκ°„ 슀트리밍 ν™˜κ²½μ—μ„œ μˆ˜ν–‰ν•  수 μžˆλ„λ‘ μ„€κ³„λœ ν”„λ ˆμž„μ›Œν¬μž…λ‹ˆλ‹€.

기쑴의 Video Depth Estimation λͺ¨λΈλ“€μ€ 전체 λΉ„λ””μ˜€ 클립(batch)을 ν•œ λ²ˆμ— μ²˜λ¦¬ν•΄μ•Ό ν•˜λ―€λ‘œ, μ‹€μ‹œκ°„ μ• ν”Œλ¦¬μΌ€μ΄μ…˜(μžμœ¨μ£Όν–‰, AR/VR, λ‘œλ΄‡ λΉ„μ „ λ“±)에 μ μš©ν•˜κΈ° μ–΄λ ΅μŠ΅λ‹ˆλ‹€. λ³Έ ν”„λ‘œμ νŠΈλŠ” Knowledge Distillation 기법을 ν™œμš©ν•˜μ—¬, Non-streaming Teacher λͺ¨λΈμ˜ μ„±λŠ₯을 μœ μ§€ν•˜λ©΄μ„œλ„ ν”„λ ˆμž„ λ‹¨μœ„ μ‹€μ‹œκ°„ 좔둠이 κ°€λŠ₯ν•œ Streaming Student λͺ¨λΈμ„ ν•™μŠ΅ν•©λ‹ˆλ‹€.

Architecture Overview
StreamDepth μ•„ν‚€ν…μ²˜: Teacher(Clip-based) β†’ Student(Frame-by-frame Streaming)

✨ Key Features

  • πŸ”΄ Real-time Streaming: ν”„λ ˆμž„ λ‹¨μœ„ 순차적 μΆ”λ‘ μœΌλ‘œ μ‹€μ‹œκ°„ 처리 κ°€λŠ₯
  • πŸ“š Knowledge Distillation: Non-streaming Teacher의 지식을 Streaming Student둜 효과적으둜 전이
  • 🎯 Temporal Consistency: Causal Attentionκ³Ό Hidden State Caching으둜 μ‹œκ°„μ  일관성 μœ μ§€
  • ⚑ Efficient Inference: μŠ¬λΌμ΄λ”© μœˆλ„μš° μΊμ‹œ 기반의 효율적인 λ©”λͺ¨λ¦¬ 관리

πŸ—οΈ Architecture

Non-Streaming vs Streaming

ꡬ뢄 Non-Streaming (Teacher) Streaming (Student)
μž…λ ₯ 전체 λΉ„λ””μ˜€ 클립 [B, T, C, H, W] 단일 ν”„λ ˆμž„ [B, 1, C, H, W]
Attention Bidirectional (μ–‘λ°©ν–₯) Causal (단방ν–₯)
μΆ”λ‘  방식 Batch 처리 Frame-by-frame
μ‹€μ‹œκ°„ 적용 ❌ λΆˆκ°€λŠ₯ βœ… κ°€λŠ₯
λ©”λͺ¨λ¦¬ T에 λΉ„λ‘€ν•˜μ—¬ 증가 κ³ μ • (μΊμ‹œ μœˆλ„μš°)

Model Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      StreamDepth Architecture                   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚   Input Frame    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                           β”‚
β”‚   [B,1,3,H,W] ──▢│   DINOv2 Encoder │──▢ Spatial Features       β”‚
β”‚                  β”‚   (ViT-S/L)      β”‚    [B,1,C,h,w]            β”‚
β”‚                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                           β”‚
β”‚                           β”‚                                     β”‚
β”‚                           β–Ό                                     β”‚
β”‚                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                           β”‚
β”‚                  β”‚  DPT Temporal    β”‚                           β”‚
β”‚   Cached States ─│  Head (Causal)   │─▢ Depth Map [B,1,H,W]     β”‚
β”‚   [T-1 frames]   β”‚  + Motion Module β”‚                           β”‚
β”‚                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                           β”‚
β”‚                           β”‚                                     β”‚
β”‚                           β–Ό                                     β”‚
β”‚                    Hidden State Cache                           β”‚
β”‚                    (Sliding Window)                             β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“– Method

Knowledge Distillation Framework

StreamDepthλŠ” 3κ°€μ§€ 핡심 손싀 ν•¨μˆ˜λ₯Ό 톡해 Teacherμ—μ„œ Student둜 지식을 μ „λ‹¬ν•©λ‹ˆλ‹€:

Output-level KD Loss

Teacher와 Student의 **μ΅œμ’… 좜λ ₯(depth map)**을 직접 λΉ„κ΅ν•©λ‹ˆλ‹€:

$$L_{KD} = \frac{1}{N}\sum_{i} |d_{student}^{(i)} - d_{teacher}^{(i)}| \cdot \mathbb{1}_{valid}$$

Feature Similarity Loss (DistilHuBERT Style)

쀑간 λ ˆμ΄μ–΄μ˜ νŠΉμ§• ν‘œν˜„μ„ μ •ν•©ν•˜μ—¬ Teacher의 ν‘œν˜„λ ₯을 μ „λ‹¬ν•©λ‹ˆλ‹€:

$$L_{DIS} = \frac{1}{D} |h_t - z_t|_1 - \log\sigma(\cos(h_t, z_t))$$

Attention Relation KL Loss (MiniLM-v2 Style)

Self-Attention의 Q/K/V 관계λ₯Ό λ³΄μ‘΄ν•˜μ—¬ μ‹œκ°„μ  μ˜μ‘΄μ„±μ„ ν•™μŠ΅ν•©λ‹ˆλ‹€:

$$L_{KLD} = L_{KLD}^Q + L_{KLD}^K + L_{KLD}^V$$

Training Strategy

# Pseudo-code for training loop
for epoch in range(num_epochs):
    for batch in dataloader:
        # Teacher: Clip-based inference (frozen)
        with torch.no_grad():
            teacher_depth = teacher(clip)
        
        # Student: Frame-by-frame streaming
        cache = None
        for t in range(T):
            student_depth, cache = student.stream_step(frame[t], cache)
            
            # Compute losses
            loss_depth = depth_loss(student_depth, gt_depth[t])
            loss_kd = kd_loss(student_depth, teacher_depth[t])
            
            loss = loss_depth + Ξ»_kd * loss_kd
            loss.backward()

πŸ”¬ Results

Quantitative Results on ScanNet

Model Mode Abs Rel ↓ RMSE ↓ δ₁ ↑
Video-Depth-Anything Non-streaming 0.0XXX 0.XXX 0.806
StreamDepth (Ours) Streaming 0.0XXX 0.XXX 0.837

Qualitative Comparison Graph (later)


πŸš€ Quick Start

Installation

# Clone repository
git clone https://github.com/your-repo/video-stream.git
cd video-stream

# Create conda environment
conda create -n streamdepth python=3.10
conda activate streamdepth

# Install dependencies
pip install -r requirements.txt

Download Pretrained Weights

bash get_weights.sh

Inference (Streaming Mode)

# Real-time streaming inference on video
python run_streaming.py \
    --input_video assets/example_videos/sample.mp4 \
    --encoder vits \
    --output_dir outputs_streaming

Training

# Train with Knowledge Distillation
python train.py \
    --pretrained_ckpt checkpoints/video_depth_anything_vits.pth \
    --epochs 75 \
    --val_dataset_key scannet

πŸ“Š Benchmark

Supported Datasets

  • KITTI: Outdoor driving scenes
  • ScanNet: Indoor scenes
  • Sintel: Synthetic sequences
  • Bonn: RGB-D dynamic scenes
  • NYUv2: Indoor depth benchmark

Running Evaluation

# Run inference
python benchmark/infer/infer.py \
    --infer_path benchmark/output/scannet_stream \
    --json_file datasets/scannet/scannet_video_500.json \
    --datasets scannet

# Evaluate
bash benchmark/eval/eval_500.sh benchmark/output/scannet_stream benchmark/dataset_extract/dataset

πŸ“ Project Structure

video-stream/
β”œβ”€β”€ πŸ“„ train.py                    # Main training script
β”œβ”€β”€ πŸ“„ run_streaming.py            # Real-time streaming inference
β”œβ”€β”€ πŸ“„ run_eval_comparison.py      # Teacher vs Student evaluation
β”œβ”€β”€ πŸ“„ config_jh.yaml              # Training configuration
β”‚
β”œβ”€β”€ πŸ“‚ video_depth_anything/       # Model implementations
β”‚   β”œβ”€β”€ video_depth.py             # Teacher model (Non-streaming)
β”‚   β”œβ”€β”€ video_depth_stream.py      # Student model (Streaming)
β”‚   β”œβ”€β”€ dpt_temporal.py            # DPT Head with Temporal module
β”‚   β”œβ”€β”€ dinov2.py                  # DINOv2 backbone
β”‚   └── motion_module/             # Temporal attention modules
β”‚
β”œβ”€β”€ πŸ“‚ utils/
β”‚   β”œβ”€β”€ loss_MiDas.py              # Depth loss functions
β”‚   β”œβ”€β”€ loss_kd_aux.py             # KD auxiliary losses
β”‚   └── train_helper.py            # Training utilities
β”‚
β”œβ”€β”€ πŸ“‚ benchmark/                  # Evaluation pipeline
β”‚   β”œβ”€β”€ infer/                     # Inference scripts
β”‚   β”œβ”€β”€ eval/                      # Evaluation scripts
β”‚   └── dataset_extract/           # Dataset preparation
β”‚
β”œβ”€β”€ πŸ“‚ checkpoints/                # Model weights
β”œβ”€β”€ πŸ“‚ data/                       # Data loading utilities
└── πŸ“‚ outputs/                    # Training outputs

βš™οΈ Configuration

μ£Όμš” ν•™μŠ΅ μ„€μ • (config_jh.yaml):

hyper_parameter:
  learning_rate: 1.0e-4
  batch_size: 4
  clip_len: 32              # Frames per training clip
  epochs: 75
  ratio_ssi: 1.0            # Scale-Shift Invariant loss weight
  ratio_tgm: 10.0           # Temporal Gradient Matching loss weight

kd_aux:
  enabled: true             # Enable Knowledge Distillation
  lambda_kd: 0.0001         # KD loss weight

model:
  encoder: "vits"           # ViT-S (vits) or ViT-L (vitl)
  features: 64
  num_frames: 32

πŸ“š Citation

@article{streamdepth2025,
  title={StreamDepth: Real-Time Streaming Video Depth Estimation via Knowledge Distillation},
  author={Your Name},
  journal={arXiv preprint},
  year={2025}
}

πŸ™ Acknowledgements

λ³Έ ν”„λ‘œμ νŠΈλŠ” λ‹€μŒ 연ꡬ듀을 기반으둜 ν•©λ‹ˆλ‹€:


πŸ“œ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.


Made with ❀️ for Real-time Video Depth Estimation

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages