This repo contains the full geolocalization pipeline for the CS503 Visual Intelligence project - Flow Matching for Probabilistic Image Geolocalization in Switzerland. It is organized into the following parts:
deterministic-baseline/— deterministic baselines used to benchmark and generate conditioning signals for the probabilistic model- Main pipeline (
src/,scripts/,config/,tests/) — flow-based probabilistic geolocalization model conditioned on frozen StreetCLIP embeddings, with optional caption conditioning
The rest of this README focuses on the main probabilistic method based on flow matching.
- build a deterministic Switzerland-only OSV5M subset
- cache frozen image embeddings
- optionally cache frozen text embeddings from precomputed captions
- train a selected flow model on either 3D sphere coordinates or a local Switzerland-centered 2D map
- sample many final locations per image
- summarize them with a mode, medoid, and heatmap
- evaluate and log everything in W&B
The geolocalization head is selected from the YAML config. The current baseline is simple_plonk_rfm_s2; the PLONK-compatible spherical baseline is plonk_rfm_s2; the local Switzerland-only Euclidean variant is plonk_local_fm_r2.
src/visual_geolocation/: importable package with datasets, models, training, evaluation, inference, geospatial utilities, and W&B helpersscripts/: local CLI wrappers and analysis utilitiesscripts/slurm/: cluster launch scriptsconfig/experiments/: YAML experiment configs
Local:
python scripts/run_experiment.py --config config/experiments/simple_plonk_rfm_s2_image_only.yamlCluster:
sbatch scripts/slurm/run_experiment_slurm.sh config/experiments/simple_plonk_rfm_s2_image_only.yamlThat is the main workflow. The other scripts are internal stage utilities used by the launcher.
To run the PLONK-compatible CH image-only baseline:
sbatch scripts/slurm/run_experiment_slurm.sh config/experiments/plonk_rfm_s2_image_only.yamlTo run the local Euclidean PLONK-style CH variant:
sbatch scripts/slurm/run_experiment_slurm.sh config/experiments/plonk_local_fm_r2_image_only.yamlIf you ever want to generate captions ahead of time without training, there is also a helper:
python scripts/generate_captions.py --config config/experiments/caption_experiments/image_text_structured_full.yamlThat helper is optional. Newcomers should still start with scripts/run_experiment.py.
On the cluster, the dedicated caption-generation job is:
sbatch scripts/slurm/run_caption_generation_slurm.sh config/experiments/caption_experiments/image_text_structured_full.yamlFor faster offline caption generation, there is also a sharded multi-GPU version:
sbatch scripts/slurm/run_caption_generation_multi_gpu_slurm.sh config/experiments/caption_experiments/image_text_structured_full.yamlFor fast prompt and model benchmarking on a handful of samples, there is also a dedicated caption-comparison utility:
python scripts/compare_caption_generation.py --config config/experiments/caption_experiments/image_text_free.yaml --samples-per-split 3On the cluster:
sbatch scripts/slurm/run_caption_compare_slurm.sh config/experiments/caption_experiments/image_text_free.yaml --samples-per-split 3By default it compares a few val and test samples across multiple VLMs and prompt styles, including:
- compact cue-fragment prompting
- closed-vocabulary structured JSON extraction
- targeted VQA, where several short questions are asked and concatenated
It writes both a raw JSON dump and a Markdown report under the run directory so you can inspect outputs side by side quickly.
There are two different inputs to keep in mind:
- the image dataset subset
- the optional caption file for multimodal experiments
You can either download the prepared CH subset from Hugging Face, or let the launcher build it from OSV5M.
Fast path:
DEST=/scratch/izar/$USER/visual_geolocation_cfm_poc/data/osv5m_ch_subset
hf download mkartofel/osv5m-ch-subset \
--repo-type dataset \
--local-dir "$DEST"
tar -C "$DEST" -xf "$DEST/images_train.tar"
tar -C "$DEST" -xf "$DEST/images_val.tar"
tar -C "$DEST" -xf "$DEST/images_test.tar"
tar -C "$DEST" -xf "$DEST/images_original_osv5m_test.tar"After this, scripts/run_experiment.py will detect the matching local subset and reuse
it.
If the subset is not there, the launcher will automatically:
- download from
osv5m/osv5m-wdsas needed - filter to OSV5M samples whose country code is
CH - hold out matching samples from the original OSV5M
testsource split asoriginal_osv5m_test - create a deterministic random
80/10/10train/val/test split from the remaining source samples using the experiment seed - save it under your scratch data directory
So for image-only experiments, this is enough:
python scripts/run_experiment.py --config config/experiments/simple_plonk_rfm_s2_image_only.yamlOn the first run, it will create:
train.jsonval.jsontest.jsonoriginal_osv5m_test.json- local image files under
images/train,images/val,images/test, andimages/original_osv5m_test
If those artifacts already exist and match the config, the launcher reuses them.
For multimodal experiments, the launcher can generate captions automatically from the local subset before preprocessing.
Default behavior:
- if
conditioning.kinduses text and no caption file exists yet,scripts/run_experiment.pygenerates one - the generated file is stored at:
/scratch/izar/$USER/visual_geolocation_cfm_poc/data/osv5m_ch_subset/captions/generated_captions.jsonl- later runs reuse that file by default
The generated caption file also gets a side metadata file storing the caption-generation signature. If you change the caption model or prompts, the launcher will invalidate the old generated captions and rebuild them instead of silently reusing stale ones.
The launcher still supports loading an existing caption file from disk if you want full control:
paths:
caption_file: /path/to/captions.jsonl
caption_generation:
enabled: falseWhat the repo supports after that:
- matching captions to samples by image filename stem
- encoding those captions with the frozen StreetCLIP text encoder
- caching the resulting text embeddings
Supported caption file formats:
jsonlparquet
Expected fields include:
image_idsplit- one or more caption columns such as:
caption_freecaption_structured_fullcaption_structured_climatecaption_structured_languagecaption_structured_vegetationcaption_structured_driving_sidecaption_corrupted_climatecaption_shuffled
The image_id must match the local sample image filename stem used in the subset.
Example:
{"image_id":"000123","split":"train","caption_structured_full":"rural road, dry climate, right-hand traffic"}The built-in generator currently produces:
caption_freecaption_structured_fullcaption_structured_climatecaption_structured_languagecaption_structured_vegetationcaption_structured_driving_sidecaption_corrupted_climatecaption_shuffled
The current default caption generator is an instruction-following vision-language model, not a plain captioning model. That matters for the structured ablations, because those fields need image-grounded attribute descriptions rather than prompt echoes.
For speed, the generator only produces the caption family needed by the current experiment by default. For example, a structured_full run generates the structured captions and derived corruption controls, but does not also generate free-form captions unless caption_generation.generate_free_caption: true.
The structured generator is designed around observable, conservative attributes with a closed vocabulary, such as scene type, terrain, vegetation, road markings, visible script, road signs, and infrastructure. It intentionally avoids hidden or weakly grounded attributes like inferred country or climate zone.
Each experiment is defined by one YAML file.
Main sections:
experimentpathscaption_generationdataconditioningencoderstraininferenceevaluationanalysiswandb
Conditioning kinds:
image_onlytext_onlyimage_text_concatimage_text_sum
Text modes:
nonefreestructured_fullstructured_climatestructured_languagestructured_vegetationstructured_driving_sidecorrupted_climateshuffled
Example multimodal preset:
experiment:
name: image_text_structured_full
family: simple_plonk_rfm_s2
seed: 42
model:
name: simple_plonk_rfm_s2
conditioning:
kind: image_text_concat
text_mode: structured_full
wandb:
group: multimodal-text-ablation-v1
tags: [simple-plonk-rfm-s2, image-text, structured-full]For image_only, keep:
conditioning:
kind: image_only
text_mode: noneFor multimodal runs, make sure both are true:
conditioning.kinduses a text-enabled mode- either
caption_generation.enabled: trueorpaths.caption_filepoints to a real caption file
By default everything goes under:
/scratch/izar/$USER/visual_geolocation_cfm_pocFor one experiment, the main run directory is:
/scratch/izar/$USER/visual_geolocation_cfm_poc/runs/<experiment_name>_seed<seed>Important outputs:
resolved_config.yamlcheckpoint_best.ptcheckpoint_last.ptmetrics.jsontrain_summary.jsonevaluation/visualizations/comparisons/when enabled
Visualizations include the existing full-Earth maps plus Switzerland-zoomed companions
(*_switzerland_*.png) for regional inspection. Spherical models predict on the full
Earth sphere; plonk_local_fm_r2 predicts inside a fixed Switzerland-centered 2D box and
converts samples back to lat/lon for the same metrics.
The launcher owns W&B. One experiment run creates one W&B run.
Logged namespaces:
dataset/*preprocess/*sanity/*train/*eval/<split>/*compare/*viz/*
The run also saves:
- resolved config
- manifests
- best checkpoint
- evaluation reports
- per-example JSONL
- comparison summaries when enabled
- qualitative images
- reproducibility bundle
If you are not logged in, set in the config:
wandb:
enabled: true
mode: offlineTo compare a multimodal experiment against an image-only reference, set:
analysis:
compare_enabled: true
compare_reference_eval: /path/to/reference/test_per_example.jsonlThe launcher will write comparison outputs into the experiment run directory and log summary deltas to W&B.
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install -e .