API Reference¶
Models¶
backseat_driver.models.scene
¶
Camera
¶
Bases: StrEnum
The six cameras on a nuScenes vehicle, front-centre first then clockwise.
Source code in backseat_driver/models/scene.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
channel
property
¶
The name nuScenes gives this camera, e.g. CAM_FRONT.
SceneDescription
¶
Bases: SceneKeyframe
A scene keyframe plus the natural-language description a VLM produced for it.
Source code in backseat_driver/models/scene.py
33 34 35 36 37 38 | |
SceneKeyframe
¶
Bases: BaseModel
A single representative image picked to stand in for a whole scene.
Source code in backseat_driver/models/scene.py
23 24 25 26 27 28 29 30 | |
backseat_driver.models.job
¶
DeadLetter
¶
Bases: BaseModel
A task that ran out of retries, kept whole so it can be inspected or re-enqueued; the job only records why.
Source code in backseat_driver/models/job.py
36 37 38 39 40 41 42 | |
Job
¶
Bases: JobReference
A request to describe every scene of the dataset, with its current progress.
Source code in backseat_driver/models/job.py
25 26 27 28 29 30 31 32 33 | |
JobDeadLetter
¶
Bases: DeadLetter
A dead letter listed across jobs, so it says which job it belongs to.
Source code in backseat_driver/models/job.py
45 46 47 48 | |
JobReference
¶
Bases: BaseModel
What ties a job's row, its queue messages and every worker log line together.
Source code in backseat_driver/models/job.py
9 10 11 12 13 | |
JobState
¶
Bases: StrEnum
Lifecycle of a job, derived from scene counts and the recorded error rather than stored.
Source code in backseat_driver/models/job.py
16 17 18 19 20 21 22 | |
backseat_driver.models.tasks
¶
CaptionTask
¶
Bases: JobReference
Queue message: caption one scene's keyframe on behalf of a job.
Source code in backseat_driver/models/tasks.py
11 12 13 14 15 | |
IngestTask
¶
Bases: JobReference
Queue message: load the dataset and fan out one CaptionTask per keyframe (scene and camera).
Source code in backseat_driver/models/tasks.py
5 6 7 8 | |
Read¶
backseat_driver.read
¶
Stage 1, read: get the scenes and their images.
SceneLoader turns a dataset into SceneKeyframes and ImageStore hands out an image's bytes. This package holds
the simple core, a loader and a store that read a dataset on local disk. read/s3/ is the layer that puts the
dataset in an S3-compatible bucket instead, for workers that share no disk.
Process¶
backseat_driver.process
¶
Stage 2, process: caption a keyframe image with a vision-language model.
The Captioner port, built from a CaptionBackend (where inference runs) plus a CaptionModel (which model and
prompt). The monolith calls it in-process; the distributed caption worker calls the same class once per queue task.
Write¶
backseat_driver.write
¶
Stage 3, write: persist the SceneDescriptions.
describe (one process) list[SceneDescription] ──▶ json_writer.write_json ──▶ output/*.json
workers (many machines) one SceneDescription ──▶ transport.job_store ──▶ SQLite / Postgres
The two are different contracts: a batch written once at the end, and results recorded one by one. The second also
carries the completion rule, since the job record says how many results to expect. It is part of the seam, so it lives
in transport/job_store/, over the database in write/job_store/. show/ reads either and is not part of this stage.
Pipeline¶
backseat_driver.pipeline
¶
The whole program in one place: read the scenes, process each image, write the descriptions.
keyframes = await loader.load_keyframes() # read (backseat_driver.read)
descriptions = [await describe_keyframe(...) ...] # process (backseat_driver.process)
write_json(descriptions, path) # write (backseat_driver.write), done by the caller
ScenePipeline runs the first two in one process; the describe command adds the third. The distributed layer
splits the same steps across queues instead of changing them: IngestWorker is the read step, CaptionWorker calls
describe_keyframe (the process step) once per task, and the job store is the write step.
The loader and captioner are abstract ports, so the pipeline is unit-testable with fakes and never imports nuscenes-devkit, transformers, or torch directly.
ScenePipeline
¶
Runs the loader → captioner pipeline over every scene in the dataset.
Source code in backseat_driver/pipeline.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
run(max_scenes=None, on_progress=None)
async
¶
Progress is reported once per batch, with the batch's first keyframe, before the batch is captioned.
Source code in backseat_driver/pipeline.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
describe_keyframe(keyframe, captioner, local_path)
async
¶
Caption the file at local_path as the keyframe's scene. Shared by the batch pipeline and the caption worker.
The file to read is separate from keyframe.image_path, which is what the description records: the image is
captioned from a local copy, but the result still names it by its dataset key.
Source code in backseat_driver/pipeline.py
29 30 31 32 33 34 35 | |
describe_keyframes(keyframes, captioner, local_paths)
async
¶
describe_keyframe for several keyframes at once, so the captioner can run them together.
Source code in backseat_driver/pipeline.py
38 39 40 41 42 43 44 45 46 47 48 | |
first_scenes(keyframes, max_scenes)
¶
The keyframes of the first max_scenes scenes, in their original order; all of them when max_scenes is None.
Counts scenes, not keyframes: a multi-camera run has several keyframes per scene. Shared by the batch pipeline and
the ingest worker, so max_scenes means the same in both.
Source code in backseat_driver/pipeline.py
63 64 65 66 67 68 69 70 71 72 | |
Transport¶
backseat_driver.transport
¶
The seam between read and process: a queue, and the two workers at its ends.
Without it (describe) the program is one function call:
read ──────────────────────────▶ process ──▶ write
With it, the same steps become tasks. IngestWorker is the read step turned into a producer and CaptionWorker is the
process and write steps run once per task:
read ──▶ IngestWorker ══ queue ══▶ CaptionWorker ──▶ write
(this package)
The queue is a JobQueue. InProcessJobQueue keeps both ends in one process on one thread (the API monolith, so
just dev needs no broker). CeleryJobQueue puts RabbitMQ between them so the ends run on different machines.
Tasks finish one at a time, so the seam also brings a JobStore (job_store/, in this package): one row per
description plus the job's expected count, which is how a job knows it is done. It is a SQLite file in the monolith and
Postgres across machines. Only crossing machines needs read/s3/, because the workers then share no disk.
Show¶
backseat_driver.show
¶
Showing the results: a separate role from describing.
Reads SceneDescriptions (from JSON files or the API's jobs), scores them and renders the model-comparison page.
Nothing here runs a model or reads the dataset.
Config¶
backseat_driver.config
¶
Settings
¶
Bases: BaseSettings
Source code in backseat_driver/config.py
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
model_name_for(backend=None, model_name=None)
¶
The model that backend (default: the configured one) runs; model_name overrides the configured one.
Source code in backseat_driver/config.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
output_path_for(backend=None, model_name=None)
¶
Default result file for a backend/model pair, so runs of different models never overwrite each other.
Source code in backseat_driver/config.py
96 97 98 99 100 101 | |
Logger¶
backseat_driver.logger
¶
HTTP API¶
backseat_driver.api.app
¶
create_app(settings, build_http=build_http_client)
¶
Build the service for settings; tests build their own with dependency_overrides instead of patching.
Source code in backseat_driver/api/app.py
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 | |