Data Ingestion Pipeline - End-to-End Explanation
What is the end goal?
SatQuery AI is an agentic remote-sensing vision-language assistant. It takes a natural-language question plus one or more satellite images and answers - with text, bounding boxes, oriented boxes, points, or segmentation masks - all from a single autoregressive language model. It is built on Earth-OneVision (arXiv:2606.10819), a 2B-parameter model that unifies six sensor modalities and nine task categories in one framework.
The model does not have task-specific heads. Every output - a sentence, a coordinate pair, a detection list, a 24×24 segmentation mask - is produced by the same language-model head, then decoded by parsing the generated token stream.
The end state is: upload a GeoTIFF (or PNG for benchmarks), type a question, get a structured, auditable answer with spatial evidence, confidence, and a downloadable report.
The data ingestion pipeline - from raw dataset to training tensor
There are five stages between a downloaded dataset and a model that can train on it:
Stage 1: DOWNLOAD Raw dataset on disk (manual, license-gated)
│
Stage 2: CONVERT Annotation → MMRSRecord → JSONL manifest
│
Stage 3: VALIDATE Schema check + data leakage check
│
Stage 4: (OPTIONAL) GPT-assisted synthesis + two-stage QC
│
Stage 5: TRAIN Manifest + images → Dataset → Collator → DataLoader → Trainer
Stage 1 - Download (manual, by design)
Every dataset requires a manual, license-gated download. The repo does not auto-download because most datasets require account creation or click-through licenses, and this machine has limited disk space (61GB free of 927GB).
How to download:
cd backend
python tools/download_dataset.py --dataset cdvqa # prints instructions
python tools/download_dataset.py --dataset rsvqa
python tools/download_dataset.py --dataset bigearthnet
Each prints exact URLs and where to place files. data/dataset_registry.yaml records
per-dataset download URLs, license info, and expected directory structure.
Registered datasets:
| Dataset | Role in SatQuery | Download status |
|---|---|---|
| RSVQA (LR/HR) | Single-image VQA | Annotation JSON present |
| VRSBench | Captioning + grounding | Annotation ZIP present |
| CDVQA | Bi-temporal change VQA | Annotation JSON present in external/CDVQA/ |
| BigEarthNet-MM | Multisensor domain adaptation | Annotation present (images need Zenodo) |
| LEVIR-CD | Pixel-level change detection | Planned |
| SEN12MS-CR | Optical+SAR cross-modal | Planned |
Stage 2 - Convert (annotation → unified format)
Every converter maps a source dataset's native annotation format into MMRSRecord - the
MMRS-OneVision-compatible record schema.
The schema (backend/data/schema.py):
MMRSRecord:
id: str # unique sample id
task: str # one of: vqa, captioning, detection, visual_grounding,
# segmentation, change_detection, visual_prompting,
# classification, relation_reasoning
subtask: str # fine-grained variant (e.g. "temporal_vqa", "change_captioning")
modality: str # optical | sar | infrared | multispectral | temporal | video | fusion
conversation: list[Turn] # [{"role":"user","content":"..."}, {"role":"assistant","content":"..."}]
images: list[str] # paths to image files (relative to images_root)
image: str | None # single image path (legacy)
spatial_annotations: list # raw ground-truth boxes/points/masks (pre-SLIS)
metadata: dict # provenance, quality flags, etc.
Running a converter:
cd backend
python tools/convert_dataset.py --dataset cdvqa --split train
# Output: backend/data/manifests/cdvqa/train.jsonl (one JSONL line per MMRSRecord)
What each converter does:
| Converter | Input | Output | Notes |
|---|---|---|---|
rsvqa.py | RSVQA JSON questions/answers | MMRSRecord (task=vqa, modality=optical) | Single image per record |
vrsbench.py | VRSBench annotation JSON | MMRSRecord (captioning/grounding/vqa) | Flexible per subtask |
cdvqa.py | CDVQA before/after Q&A JSON | MMRSRecord (task=vqa, modality=temporal) | Two images, [im1/, im2/] layout |
bigearthnet.py | BigEarthNet-S1/S2 patch annotations | MMRSRecord (multispectral/sar classification) | Multi-band TIFF input |
SLIS serialization (coordinate tokens, R-RLE) is baked in at conversion time, not at
training time. The assistant-turn text already contains serialized <hbox_2d>[<112>, <345>, ...]
or <seg>target*4, others*20; ...</seg>. This means the same record can be re-serialized under
different vocabulary configurations without re-running the converter.
Stage 3 - Validate (schema + leakage)
Two checks, run before training:
Schema validation (tools/validate_dataset.py):
python tools/validate_dataset.py --manifest data/manifests/cdvqa/train.jsonl --intended-use train
Validates every JSONL line against RECORD_JSON_SCHEMA (valid task enum, required fields,
conversation length ≥ 2, at least one image source).
Data leakage prevention (backend/data/leakage/):
The paper (Sec. IV-E) mandates: "Test splits of downstream evaluation benchmarks are excluded
from all stages of MMRS-OneVision data collection, conversion, and synthesis."
data/leakage/benchmark_exclusions.yaml lists forbidden split-name patterns per benchmark.
validate_dataset.py --intended-use train cross-references every record's id against these
exclusions and fails the build (non-zero exit) if any leak is found.
Stage 4 - (Optional) GPT-assisted synthesis
Earth-OneVision's MMRS-OneVision corpus uses GPT-4o to synthesize additional QA pairs from images + factual anchors (Sec. IV-C). This repo implements the full pipeline but does not exercise it (no OpenAI API key was used).
Pipeline (backend/data/synthesis/):
Factual anchor (image caption / object list)
│
▼
Prompt templates (prompts/image_captioning.txt, change_captioning.txt)
│
▼
OpenAI backend (GPT-4o) or MockBackend (for tests)
│
▼
SHA-256 cache (avoids re-generating identical prompts)
│
▼
Rule-based QC (rejects if output contains coordinate tokens or diverges from anchors)
│
▼
Semantic QC (InternVL3-72B review, or LocalHFReviewer, or MockReviewer)
│
▼
Validated MMRSRecord → manifest
Stage 5 - Train (manifest → tensors → loss → checkpoint)
This is the actual training loop, documented fully in docs/ml/PIPELINE.md. Here is the
data-ingestion side:
A. Build a combined manifest:
cat data/manifests/rsvqa/train.jsonl data/manifests/vrsbench/train.jsonl > combined.jsonl
B. MMRSDataset loads it:
backend/data/dataset.py:MMRSDataset.__getitem__(idx):
- Reads one JSONL line →
MMRSRecord - Resolves image paths under
images_root - Loads images via
rasterio(GeoTIFF) orPIL(PNG/JPEG) - Passes through the appropriate modality processor:
- optical → passthrough (RGB)
- sar / infrared → percentile-normalized pseudo-RGB (2–98th percentile, min-max to [0,255])
- multispectral → multiple pseudo-RGB band-group views (true-color, false-veg, SWIR)
- temporal → per-frame processing, concatenated
- fusion → per-sensor processing, concatenated
Output: {"images": [PIL.Image, ...], "conversation": [...], "id": "...", ...}
C. MMRSCollator tokenizes and masks:
backend/data/collator.py:MMRSCollator.__call__(samples):
- Renders
<image>*K + conversation to a single string - Tokenizes with offset mapping (max 5400 tokens)
- Builds
response_mask: True only at assistant-turn token positions labels = input_ids.clone(), set to-100at every non-response position- Pads the batch to max length
Output: {"input_ids": [B, T], "labels": [B, T], "images_per_sample": [[PIL.Image, ...], ...]}
D. DataLoader feeds the Trainer:
The Trainer (backend/training/trainer.py) calls model.forward(input_ids, images_per_sample, labels):
- SigLIP-2 encodes each image → final feature F_N + 3 intermediate features
- ACSA cross-attends into intermediates → enhanced F̃_N
- Projector: 2×2 merge + MLP → [N/4, D_llm] visual tokens
_splice_one_sample(): replaces each<image>placeholder with its full visual-token block; sets visual-token label slots to-100- DeepStack stages intermediate features for hook injection into Qwen3 layers [0,1,2]
- Qwen3 forward with labels → shift-by-one → cross_entropy(ignore_index=-100)
- Only response-token predictions contribute to the loss
The loss is divided by gradient_accumulation_steps, accumulated over 4 datapoints, then one
AdamW step. Checkpoints are saved every 2000 steps and at the end of each epoch.
Complete file map
backend/
├── tools/
│ ├── download_dataset.py # prints download instructions per dataset
│ ├── convert_dataset.py # runs per-dataset converter → JSONL manifest
│ ├── validate_dataset.py # schema + leakage validation
│ └── converter_registry.py # name → converter class map
├── data/
│ ├── schema.py # MMRSRecord, RECORD_JSON_SCHEMA, TASK_CATEGORIES
│ ├── dataset.py # MMRSDataset (manifest → PIL images + conversation)
│ ├── collator.py # MMRSCollator (tokenize + response-only label masking)
│ ├── converters/
│ │ ├── base.py # abstract DatasetConverter interface
│ │ ├── rsvqa.py # RSVQA → MMRSRecord
│ │ ├── cdvqa.py # CDVQA (bi-temporal) → MMRSRecord
│ │ ├── vrsbench.py # VRSBench → MMRSRecord
│ │ └── bigearthnet.py # BigEarthNet → MMRSRecord
│ ├── processors/
│ │ ├── modality.py # per-modality input reorganization (no learned encoders)
│ │ └── visual_prompting.py # renders annotations onto companion image
│ ├── synthesis/
│ │ ├── openai_backend.py # GPT-4o synthesis backend
│ │ ├── batch_generator.py # orchestrates prompt → generate → QC
│ │ ├── validators.py # rule-based + semantic QC
│ │ ├── cache.py # SHA-256 generation cache
│ │ └── prompts/ # per-task prompt templates for synthesis
│ ├── leakage/
│ │ ├── benchmark_exclusions.yaml # forbidden test-split patterns
│ │ └── validator.py # cross-references manifests against exclusions
│ └── manifests/ # output: per-dataset JSONL files
│ ├── rsvqa/train.jsonl
│ ├── vrsbench/train.jsonl
│ ├── cdvqa/train.jsonl
│ └── bigearthnet/train.jsonl
├── configs/
│ ├── base.yaml # architecture + precision + optimizer defaults
│ ├── stage1.yaml # PCMA Stage 1 (viewpoint gap)
│ ├── stage2.yaml # PCMA Stage 2 (physics gap + replay)
│ ├── baseline_train.yaml # what was actually run (stage 0, Qwen3-0.6B)
│ ├── nvidia.yaml # NVIDIA A40 training overrides
│ └── deepspeed_zero2.json # CUDA multi-GPU config
└── training/
├── train.py # CLI entry point (merges configs, builds model, runs)
├── trainer.py # Training loop (grad accum, checkpointing)
├── loss.py # Response-only masked cross-entropy
├── distributed.py # Device detection (CUDA/CPU)
└── checkpointing.py # Save/load with metadata
How it all connects - ASCII summary
┌─────────────────────────────────────────┐
│ RAW DATASETS (manual download) │
│ RSVQA / VRSBench / CDVQA / BigEarthNet │
└───────────────────┬─────────────────────┘
│
python tools/convert_dataset.py
│
▼
┌─────────────────────────────────────────┐
│ JSONL MANIFESTS (MMRSRecord format) │
│ data/manifests/{rsvqa,vrsbench,cdvqa}/ │
└───────────────────┬─────────────────────┘
│
python tools/validate_dataset.py
(schema + leakage check)
│
▼
┌─────────────────────────────────────────┐
│ VALIDATED TRAINING MANIFESTS │
└───────────────────┬─────────────────────┘
│
cat *.jsonl > combined.jsonl
│
▼
┌─────────────────────────────────────────┐
│ MMRSDataset (manifest → images) │
│ modality processors → RGB PIL images │
└───────────────────┬─────────────────────┘
│
DataLoader(batch_size, collate_fn)
│
▼
┌─────────────────────────────────────────┐
│ MMRSCollator (tokenize + mask) │
│ response-only labels, pad to max_len │
└───────────────────┬─────────────────────┘
│
Trainer.train()
│
▼
┌─────────────────────────────────────────┐
│ CHECKPOINT (model.pt + metadata) │
│ checkpoints/stage{1,2}/final/ │
└───────────────────┬─────────────────────┘
│
inference/pipeline.py
│
▼
┌─────────────────────────────────────────┐
│ STRUCTURED OUTPUT (text + boxes + masks)│
│ DecodedOutput / API JSON report │
└─────────────────────────────────────────┘