LayoutSAM sample pipeline
April 19, 2026 ยท View on GitHub
Fast reproduction (recommended)
If your goal is to reproduce the released numbers in bench/sample_scripts/README.md, use the packaged references first.
cd bench/sample_scripts/layoutsam
# unpack the released pack beside this script
tar -xzf layoutsam_reference_pack.tar.gz
# run with default arguments
python run_sample_bench_from_pack.py
This uses default ./layoutsam_reference_pack and writes outputs under bench/output/layoutsam/.
Then run evaluation (MiniCPM-V QA + CLIP / PickScore) in one script:
python layoutsam_eval.py
Runs MiniCPM-V QA first, then CLIP/Pick on the same --sampled-bench JSON. Override paths with --generate-path / --sampled-bench. Model and dataset IDs are constants at the top of layoutsam_eval.py.
Full pipeline (rebuild references from scratch)
cd bench/sample_scripts/layoutsam
python run_layoutsam.py --help
Run order:
gen-segmentsvalid-bboxfilter-benchmarksample-bench
Configuration
Defaults live in layoutsam_config.py (USER CONFIG block):
DATA_DIR: benchmark JSON + generated intermediate files.FLUX_MODEL_PATH: model path/id forgen-segments.FLUX_TURBO_LORA_PATH: optional turbo LoRA for fast segment generation.GROUNDING_DINO_MODEL: model path/id forvalid-bbox.GENERATION_REPO: project root containingsrc/.KONTEXT_MODEL_PATH,ADAPTER_PATH: model paths forsample-bench.
You can override config fields via CLI flags (for example --data-dir, --kontext-model-path, --adapter-path).
Key files
run_sample_bench_from_pack.py: direct reproduction from unpacked pack.run_layoutsam.py: full CLI pipeline.pipeline/reference.py: segment generation, bbox validation, benchmark filtering.pipeline/sample_bench.py: full-scene sampling.layoutsam_eval.py: MiniCPM-V region QA and CLIP/PickScore metrics on generated images.