KITTI-C2L-Dataset / code /src /kitti_c2l /sequence_mapping.py
mcocheteux's picture
Release KITTI-C2L v1.0.0: documented self-contained benchmark, loader and baselines
db613b6 verified
Raw History Blame Contribute Delete
2.86 kB
"""KITTI Odometry sequence <-> raw drive lookup, backed by configs/sequence_mapping.yaml.
See that file's header comment for provenance. Sequence 03's raw drive is not
publicly available anywhere (confirmed 404 on KITTI's official mirror, a
long-standing unresolved community-wide gap) -- its `SequenceInfo.available`
is False, and `AVAILABLE_SEQUENCES` / `kitti-c2l generate` exclude it.
"""
from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path
import yaml
DEFAULT_CONFIG_PATH = Path(__file__).with_name("sequence_mapping.yaml")
if not DEFAULT_CONFIG_PATH.exists(): # source checkout; wheel contains the packaged copy
DEFAULT_CONFIG_PATH = Path(__file__).resolve().parents[2] / "configs" / "sequence_mapping.yaml"
@dataclass(frozen=True)
class SequenceInfo:
sequence: str # "00".."10"
date: str # e.g. "2011_09_30"
drive: str # e.g. "0016"
start: int # 0-based raw-frame index where the sequence begins
end: int # 0-based raw-frame index (inclusive) where the sequence ends
frame_count: int
split: str # "train" | "test"
available: bool = (
True # False for sequence 03 -- raw drive not publicly available, see module docstring
)
def raw_frame_index(self, sequence_frame_index: int) -> int:
"""Maps a 0-based frame index within this odometry sequence to the raw drive's frame index."""
if not 0 <= sequence_frame_index < self.frame_count:
raise IndexError(
f"frame {sequence_frame_index} out of range for sequence {self.sequence} "
f"(frame_count={self.frame_count})"
)
return self.start + sequence_frame_index
@property
def drive_name(self) -> str:
return f"{self.date}_drive_{self.drive}_sync"
def load_sequence_mapping(config_path: str | Path | None = None) -> dict[str, SequenceInfo]:
path = Path(config_path) if config_path is not None else DEFAULT_CONFIG_PATH
raw = yaml.safe_load(path.read_text())
mapping: dict[str, SequenceInfo] = {}
for seq_id, fields in raw["sequences"].items():
mapping[seq_id] = SequenceInfo(
sequence=seq_id,
date=fields["date"],
drive=fields["drive"],
start=fields["start"],
end=fields["end"],
frame_count=fields["frame_count"],
split=fields["split"],
available=fields["available"],
)
return mapping
TRAIN_SEQUENCES: tuple[str, ...] = ("00", "01", "02", "03", "04", "05", "06", "07", "08")
TEST_SEQUENCES: tuple[str, ...] = ("09", "10")
ALL_SEQUENCES: tuple[str, ...] = TRAIN_SEQUENCES + TEST_SEQUENCES
# All sequences except 03 (see module docstring) -- what `kitti-c2l generate` uses by default.
AVAILABLE_SEQUENCES: tuple[str, ...] = tuple(seq for seq in ALL_SEQUENCES if seq != "03")