ConsDrive / utils /custom_types.py
ZenoNing's picture
Upload ConsDrive v2 source (part 2)
314ecfb verified
Raw History Blame Contribute Delete
3.43 kB
from typing import Dict, List, NamedTuple, Optional
import torch
from torch import Tensor
class DrivingOutput(NamedTuple):
time_delta_sec: Tensor # [B, F] float32
waypoints: Tensor # [B, F, 2] float32
# Auxiliary outputs (MUST be at the end):
language_tokens: Tensor # [B, max(len(tokens))]
trajectory_tokens: Tensor # [B, F, max(len(tokens))]
class TrainingOutput(NamedTuple):
loss: Tensor # [] floating
loss_averages: Dict[str, Tensor] # [] floating
loss_values: Dict[str, Tensor] # [B] floating
loss_counts: Dict[str, Tensor] # [B] int64
driving_output: Optional[DrivingOutput] = None
class ParamGroup(NamedTuple):
pattern: str
lr: float
weight_decay: float
class DrivingInput(NamedTuple):
camera_images: torch.Tensor # [B, T, N, C, H, W] uint8 [0, 255] or preprocessed patches
image_sizes: torch.Tensor # image_grid_thw / video_grid_thw for qwen encoders
camera_intrinsics: torch.Tensor # [B, N, 3, 3] float32
camera_extrinsics: torch.Tensor # [B, N, 4, 4] float32
vehicle_speed: torch.Tensor # [B, S] float32 ms
map_route: torch.Tensor # [B, 3, RH, RW] uint8 [0, 255] or [B, 2, 2] target points
target_point: torch.Tensor # [B, 2] float32
navigation_command: List[str]
prompt: Optional[List[str]] = None # free-form instruction (Action Dreaming)
objects: Optional[torch.Tensor] = None # [B, N, FEAT_DIM] object-bank tokens (dataloader.object_bank)
object_mask: Optional[torch.Tensor] = None # [B, N] bool, True for real objects
class DrivingLabel(NamedTuple):
time_delta_sec: Tensor # [B, F] 0-2 sec
waypoints: Tensor # [B, F, 2] 11 future waypoints 0.2s apart
waypoints_1d: Tensor # [B, F, 2] 11 future waypoints 0.2s apart
route_adjusted: Tensor
waypoints_org: Optional[Tensor] = None # [B, F, 2] original trajectory (dreamer)
route_adjusted_org: Optional[Tensor] = None # [B, R, 2] original route (dreamer)
future_states: Optional[Tensor] = None # [B, 4, 64, 1024] fp16 V-JEPA2 future latents
wm_valid: Optional[Tensor] = None # [B] bool, False for shift-augmented / uncached samples
consequence_risk_target: Optional[Tensor] = None # [B, 10]
consequence_risk_valid: Optional[Tensor] = None # [B, 10] bool
consequence_clearance_target: Optional[Tensor] = None # [B, 10], metres
consequence_clearance_valid: Optional[Tensor] = None # [B, 10] bool
future_obstacles: Optional[Tensor] = None # [B, 10, M, 5] xy/extent/yaw
future_obstacle_valid: Optional[Tensor] = None # [B, 10, M] bool
future_obstacle_step_valid: Optional[Tensor] = None # [B, 10] bool
safe_to_execute: Optional[Tensor] = None # [B] bool (Action Dreaming)
safe_to_execute_valid: Optional[Tensor] = None # [B] bool
is_dreamer: Optional[Tensor] = None # [B] bool
dream_safe_route: Optional[Tensor] = None # [B, 20, 2]
dream_safe_speed: Optional[Tensor] = None # [B, 10, 2]
dream_unsafe_route: Optional[Tensor] = None # [B, 20, 2]
dream_unsafe_speed: Optional[Tensor] = None # [B, 10, 2]
dream_pair_valid: Optional[Tensor] = None # [B] bool
object_relation: Optional[Tensor] = None # [B, N] int64 relation class per object token, -100 = no label
class DrivingExample(NamedTuple):
driving_input: DrivingInput
driving_label: DrivingLabel
run_id: List[str]
timestamp: Tensor # unix timestamp of ff cam