File size: 2,864 Bytes
db613b6 | 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 | """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")
|