jiangyurong609/d4rt-pytorch

pytorch implementation of "Efficiently Reconstructing Dynamic Scenes One 🎯 D4RT at a Time"

74

stars

3

commits

Python

primary language

Jun 15, 2026

updated

Browse cluster: Visual Point Tracking and Optical Flow β†’

README

D4RT: Dynamic 4D Reconstruction Transformer

PyTorch implementation of D4RT, a feedforward transformer for 4D scene reconstruction from video.

Features

  • Unified query interface: Single model handles depth estimation, point tracking, and 3D reconstruction
  • Query format: (u, v, t_src, t_tgt, t_cam) - pixel coordinates and temporal indices
  • Efficient attention: FlashAttention support via PyTorch 2.0+
  • Pretrained backbones: Optional timm ViT initialization

Installation

# Clone repository
git clone https://github.com/jiangyurong609/d4rt-pytorch.git
cd d4rt

# Install dependencies
pip install -r requirements.txt

# Optional: Install pytorch3d for optimized Umeyama alignment
pip install pytorch3d

Requirements

  • Python >= 3.9
  • PyTorch >= 2.0.0
  • timm >= 0.9.0

Quick Start

import torch
from models import D4RT

# Initialize model
model = D4RT(
    encoder_variant='base',
    img_size=256,
    temporal_size=24,
    decoder_depth=8
)

# Input video: (B, T, H, W, C)
video = torch.randn(1, 24, 256, 256, 3)

# Query points
coords = torch.rand(1, 100, 2)  # (u, v) in [0, 1]
t_src = torch.zeros(1, 100, dtype=torch.long)
t_tgt = torch.ones(1, 100, dtype=torch.long) * 10
t_cam = torch.zeros(1, 100, dtype=torch.long)

# Forward pass
outputs = model(video, coords, t_src, t_tgt, t_cam)

# Outputs: pos_3d, pos_2d, visibility, displacement, normal, confidence
print(outputs['pos_3d'].shape)  # (1, 100, 3)

Data

See DATA.md for dataset download instructions.

Recommended for training: PointOdyssey (~170GB with full ground truth)

# Quick start with sample set (3.1GB)
pip install huggingface_hub
huggingface-cli download aharley/pointodyssey sample.tar.gz --repo-type dataset --local-dir ./data/pointodyssey

Training

# Train on PointOdyssey
python train.py \
    --config configs/d4rt_base.yaml \
    --data.train_root ./data/pointodyssey \
    --data.train_split train

# Distributed training
torchrun --nproc_per_node=4 train.py \
    --config configs/d4rt_base.yaml

Evaluation

# Evaluate depth estimation
python evaluate.py \
    --config configs/d4rt_base.yaml \
    --checkpoint checkpoints/d4rt_base.pth \
    --task depth \
    --data_root ./data/sintel

# Evaluate point tracking
python evaluate.py \
    --task tracking \
    --data_root ./data/pointodyssey

Model Architecture

D4RT
β”œβ”€β”€ Encoder (ViT-based)
β”‚   β”œβ”€β”€ 3D Patch Embedding (t=2, h=8, w=8)
β”‚   β”œβ”€β”€ Positional Embedding (spatial + temporal)
β”‚   └── Transformer Blocks (interleaved local/global attention)
β”‚
└── Decoder (Cross-attention)
    β”œβ”€β”€ Query Embedding
    β”‚   β”œβ”€β”€ Fourier (u, v coordinates)
    β”‚   β”œβ”€β”€ Timestep (t_src, t_tgt, t_cam)
    β”‚   └── Patch (local RGB context)
    β”œβ”€β”€ Cross-Attention Blocks
    └── Output Heads (3D pos, 2D pos, visibility, etc.)

Query Types

TaskQueryOutput
Depth(u, v, t, t, t)3D position in camera frame
Tracking(u, v, t_src, t_tgt, t_src)2D position at t_tgt
3D Tracking(u, v, t_src, t_tgt, t_cam)3D position at t_tgt in t_cam frame
Point CloudGrid queries at all framesDense 3D reconstruction

Project Structure

d4rt/
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ d4rt.py          # Main model
β”‚   β”œβ”€β”€ encoder.py       # ViT encoder with timm support
β”‚   β”œβ”€β”€ decoder.py       # Cross-attention decoder
β”‚   └── embeddings.py    # Fourier, timestep, patch embeddings
β”œβ”€β”€ losses/
β”‚   └── losses.py        # Multi-task loss functions
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ dataset.py       # Base dataset and query sampler
β”‚   └── video_dataset.py # Dataset implementations
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ camera.py        # Umeyama alignment, pose estimation
β”‚   β”œβ”€β”€ metrics.py       # Evaluation metrics
β”‚   └── visualization.py # Visualization utilities
β”œβ”€β”€ configs/
β”‚   β”œβ”€β”€ d4rt_base.yaml
β”‚   └── d4rt_large.yaml
β”œβ”€β”€ train.py
β”œβ”€β”€ evaluate.py
β”œβ”€β”€ inference.py
β”œβ”€β”€ DATA.md              # Dataset guide
└── requirements.txt

Citation

@article{d4rt2024,
  title={D4RT: Dynamic 4D Reconstruction Transformer},
  author={...},
  journal={...},
  year={2024}
}

License

MIT License

Contributors

jiangyurong609/d4rt-pytorch

pytorch implementation of "Efficiently Reconstructing Dynamic Scenes One 🎯 D4RT at a Time"

74

stars

3

commits

Python

primary language

Jun 15, 2026

updated

Browse cluster: Visual Point Tracking and Optical Flow β†’

README

D4RT: Dynamic 4D Reconstruction Transformer

PyTorch implementation of D4RT, a feedforward transformer for 4D scene reconstruction from video.

Features

  • Unified query interface: Single model handles depth estimation, point tracking, and 3D reconstruction
  • Query format: (u, v, t_src, t_tgt, t_cam) - pixel coordinates and temporal indices
  • Efficient attention: FlashAttention support via PyTorch 2.0+
  • Pretrained backbones: Optional timm ViT initialization

Installation

# Clone repository
git clone https://github.com/jiangyurong609/d4rt-pytorch.git
cd d4rt

# Install dependencies
pip install -r requirements.txt

# Optional: Install pytorch3d for optimized Umeyama alignment
pip install pytorch3d

Requirements

  • Python >= 3.9
  • PyTorch >= 2.0.0
  • timm >= 0.9.0

Quick Start

import torch
from models import D4RT

# Initialize model
model = D4RT(
    encoder_variant='base',
    img_size=256,
    temporal_size=24,
    decoder_depth=8
)

# Input video: (B, T, H, W, C)
video = torch.randn(1, 24, 256, 256, 3)

# Query points
coords = torch.rand(1, 100, 2)  # (u, v) in [0, 1]
t_src = torch.zeros(1, 100, dtype=torch.long)
t_tgt = torch.ones(1, 100, dtype=torch.long) * 10
t_cam = torch.zeros(1, 100, dtype=torch.long)

# Forward pass
outputs = model(video, coords, t_src, t_tgt, t_cam)

# Outputs: pos_3d, pos_2d, visibility, displacement, normal, confidence
print(outputs['pos_3d'].shape)  # (1, 100, 3)

Data

See DATA.md for dataset download instructions.

Recommended for training: PointOdyssey (~170GB with full ground truth)

# Quick start with sample set (3.1GB)
pip install huggingface_hub
huggingface-cli download aharley/pointodyssey sample.tar.gz --repo-type dataset --local-dir ./data/pointodyssey

Training

# Train on PointOdyssey
python train.py \
    --config configs/d4rt_base.yaml \
    --data.train_root ./data/pointodyssey \
    --data.train_split train

# Distributed training
torchrun --nproc_per_node=4 train.py \
    --config configs/d4rt_base.yaml

Evaluation

# Evaluate depth estimation
python evaluate.py \
    --config configs/d4rt_base.yaml \
    --checkpoint checkpoints/d4rt_base.pth \
    --task depth \
    --data_root ./data/sintel

# Evaluate point tracking
python evaluate.py \
    --task tracking \
    --data_root ./data/pointodyssey

Model Architecture

D4RT
β”œβ”€β”€ Encoder (ViT-based)
β”‚   β”œβ”€β”€ 3D Patch Embedding (t=2, h=8, w=8)
β”‚   β”œβ”€β”€ Positional Embedding (spatial + temporal)
β”‚   └── Transformer Blocks (interleaved local/global attention)
β”‚
└── Decoder (Cross-attention)
    β”œβ”€β”€ Query Embedding
    β”‚   β”œβ”€β”€ Fourier (u, v coordinates)
    β”‚   β”œβ”€β”€ Timestep (t_src, t_tgt, t_cam)
    β”‚   └── Patch (local RGB context)
    β”œβ”€β”€ Cross-Attention Blocks
    └── Output Heads (3D pos, 2D pos, visibility, etc.)

Query Types

TaskQueryOutput
Depth(u, v, t, t, t)3D position in camera frame
Tracking(u, v, t_src, t_tgt, t_src)2D position at t_tgt
3D Tracking(u, v, t_src, t_tgt, t_cam)3D position at t_tgt in t_cam frame
Point CloudGrid queries at all framesDense 3D reconstruction

Project Structure

d4rt/
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ d4rt.py          # Main model
β”‚   β”œβ”€β”€ encoder.py       # ViT encoder with timm support
β”‚   β”œβ”€β”€ decoder.py       # Cross-attention decoder
β”‚   └── embeddings.py    # Fourier, timestep, patch embeddings
β”œβ”€β”€ losses/
β”‚   └── losses.py        # Multi-task loss functions
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ dataset.py       # Base dataset and query sampler
β”‚   └── video_dataset.py # Dataset implementations
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ camera.py        # Umeyama alignment, pose estimation
β”‚   β”œβ”€β”€ metrics.py       # Evaluation metrics
β”‚   └── visualization.py # Visualization utilities
β”œβ”€β”€ configs/
β”‚   β”œβ”€β”€ d4rt_base.yaml
β”‚   └── d4rt_large.yaml
β”œβ”€β”€ train.py
β”œβ”€β”€ evaluate.py
β”œβ”€β”€ inference.py
β”œβ”€β”€ DATA.md              # Dataset guide
└── requirements.txt

Citation

@article{d4rt2024,
  title={D4RT: Dynamic 4D Reconstruction Transformer},
  author={...},
  journal={...},
  year={2024}
}

License

MIT License

Contributors

Languages

Python

87.4%

Shell

12.6%