Skip to content

Repository files navigation

Floor Plan Document Intelligence

The original code and documentation are available under the MIT License. Results and example figures containing CubiCasa5K floor plans retain the source dataset's CC BY-NC 4.0 terms; the MIT licence does not replace those terms.

This independent portfolio project turns raster architectural floor plans into machine-readable building information. Phases 0--6 establish a verified CubiCasa5K ingestion path, a reproducible dataset audit, a classical baseline, a learned five-class segmentation model, and a local OCR prototype.

This independent portfolio project was inspired by a public Upwork requirement for software that converts architectural floor-plan images into structured geometry. It was not commissioned by, developed for, or endorsed by the original client.

Current pipeline

CubiCasa image + SVG annotation
              |
              v
Verified 5-class mask (background / room / wall / door / window)
              |
              v
Dataset audit + alignment contact sheets
              |
              v
Classical morphology baseline -> held-out reference metrics
              |
              v
SegFormer-B0 -> five-class masks, overlays and held-out metrics
              |
              v
Tesseract 5 -> text tokens, boxes and coarse entity labels
              |
              v
Approximate polygons + conservative spatial links + review-aware JSON
              |
              v
Held-out structure checks + robustness evidence + local review demo

Dataset and licensing

CubiCasa5K contains 5,000 floor plans with dense SVG polygon annotations. The dataset is licensed separately under CC BY-NC 4.0; its archive and derivatives are not committed here. The repository's code is MIT licensed. Dataset provenance: Zenodo record 2613548, DOI 10.5281/zenodo.2613548.

The task mapping is narrow and documented in data/category_mapping.yaml. It follows the selectors used by CubiCasa5K's official House parser, excludes outdoor spaces and railings, and uses explicit window > door > wall > room > background overlap precedence.

Reproduce

Python 3.11 or 3.12 is required. Every Python command below runs inside the local virtual environment.

uv venv --python 3.12 .venv
uv pip install --python .venv\Scripts\python.exe -e ".[dev,demo]"
.\.venv\Scripts\python.exe scripts\download_dataset.py
.\.venv\Scripts\python.exe scripts\install_tesseract.py

# Development: do not inspect test.
.\.venv\Scripts\python.exe scripts\audit_dataset.py --splits train val
.\.venv\Scripts\python.exe scripts\tune_baseline.py --max-samples 100
.\.venv\Scripts\python.exe scripts\evaluate_baseline.py --split val

# Only after configs/baseline.yaml is frozen.
.\.venv\Scripts\python.exe scripts\audit_dataset.py --splits test --allow-test
.\.venv\Scripts\python.exe scripts\evaluate_baseline.py --split test --allow-test
.\.venv\Scripts\python.exe -m pytest

# Frozen end-to-end Phase 5 evidence (the first 24 official test entries).
.\.venv\Scripts\python.exe scripts\evaluate_pipeline.py `
  --checkpoint results\segmentation\phase2_dev\checkpoints\best.pt `
  --allow-test --max-samples 24
.\.venv\Scripts\python.exe scripts\evaluate_robustness.py `
  --checkpoint results\segmentation\phase2_dev\checkpoints\best.pt
.\.venv\Scripts\python.exe scripts\analyse_errors.py `
  --checkpoint results\segmentation\phase2_dev\checkpoints\best.pt

# PNG/JPG or selected PDF-page inference, then the optional local viewer.
.\.venv\Scripts\python.exe scripts\predict.py --input path\to\plan.pdf --page 1 `
  --output results\prediction
.\.venv\Scripts\python.exe -m streamlit run app\app.py

The downloader obtains the archive through the Zenodo API, checks the repository-provided checksum, validates archive paths, and extracts locally. The official train.txt, val.txt, and test.txt split membership is preserved. The Tesseract installer is placed under .venv\Tesseract-OCR; no system-wide OCR installation is required. The frozen inference checkpoint is committed under results/segmentation/phase2_dev/checkpoints/best.pt, with a SHA-256 manifest, so a fresh clone can run inference without retraining first.

Documentation map

Results

The complete train/validation audit parsed all 4,600 files without corruption or annotation failure. Visual checks cover simple, dense, highest/lowest-resolution, opening-heavy and unusual-aspect plans.

Split Plans Rooms Walls Doors Windows Parse failures
Train 4,200 45,002 110,624 42,004 36,985 0
Validation 400 4,189 10,188 3,853 3,395 0
Test 400 4,351 10,711 4,088 3,629 0

Class imbalance is substantial. Training pixel frequencies are 54.55% background, 37.81% room, 5.76% wall, 0.59% door and 1.29% window.

Aligned CubiCasa source polygons, collapsed mask and overlay

The baseline configuration was selected on the first 100 official validation plans, frozen in commit 054408d, and then evaluated once on all 400 held-out test plans. Door/window scores are zero by design.

Class IoU Dice Precision Recall
Background 0.698 0.822 0.850 0.796
Room 0.613 0.760 0.791 0.732
Wall 0.251 0.401 0.286 0.670
Door 0.000 0.000 n/a 0.000
Window 0.000 0.000 n/a 0.000

Held-out five-class mIoU is 0.312; mean foreground IoU is 0.216. Median baseline CPU inference time is 0.028 seconds per plan (annotation parsing and image I/O excluded). Machine-readable outputs live under results/dataset_audit/ and results/baseline/; locally generated contact sheets make alignment and baseline behaviour visually inspectable.

Classical baseline prediction on a held-out test plan

Phase 2: learned segmentation

SegFormer-B0 is initialized from the public ADE20K checkpoint, its classifier is reinitialized for the project's five labels, and it is fine-tuned with weighted cross-entropy plus Dice loss. A deterministic 1,200-plan subset of official training data and all 400 validation plans were used for model selection. The epoch-18 checkpoint was frozen in commit 6a3cb1d before evaluating the 400 official test plans.

Class IoU Dice Precision Recall
Background 0.922 0.959 0.991 0.930
Room 0.828 0.906 0.925 0.888
Wall 0.532 0.694 0.586 0.852
Door 0.195 0.327 0.202 0.845
Window 0.409 0.580 0.431 0.887

Held-out five-class mIoU is 0.577 and foreground mIoU is 0.491; inference has a 2.13 ms median GPU forward-pass time per cached plan (image I/O and mask rendering excluded). Door recall is high but precision remains low, so opening geometry needs further work before it can support CAD-grade output.

SegFormer prediction on a held-out test plan

Phase 3: OCR prototype

The OCR workflow uses a reproducible, held-out synthetic benchmark with room labels, drawing codes and dimensions, then applies the selected method to real CubiCasa validation plans for qualitative inspection. Raw 2x upscaling was chosen on the 80-sample validation split (75.0% exact match, 21.4% CER), ahead of adaptive thresholding. With that choice frozen, it scored 78.8% exact match, 16.2% CER, 23.8% WER, 64.7% numeric-token accuracy and 90.7% room-label accuracy on the separate 80-sample synthetic test split.

Real-plan detections are visual examples only: their source annotations do not provide text transcriptions, so they are not presented as an OCR accuracy claim. The prototype reports Tesseract word boxes and coarse labels (ROOM_LABEL, DIMENSION_LIKE, DRAWING_CODE, or OTHER).

Qualitative OCR word boxes on a real validation plan

Phase 4: structured geometry

scripts/predict.py turns a PNG/JPG floor plan or selected PDF page into a pixel-coordinate JSON document and overlay. It extracts simplified room, wall, door and window polygons, preserves opening confidence, classifies OCR tokens, links text to a room only when its centre is contained or conservatively nearby, and creates a room graph only for doors close to two room boundaries. Unresolved doors, unassigned text and low-confidence openings are explicit review warnings. Raster inputs honour EXIF orientation metadata, while PDF inputs require a positive rasterisation DPI and an explicit 1-indexed page number.

The command below was run once on held-out test plan high_quality_architectural/1191: it produced 10 room regions, 18 doors, 19 windows, 198 OCR word entities, six conservative room-graph edges and 93 review warnings. These are raw pipeline outputs—not ground-truth geometry metrics—and the high warning count is expected given the weak door precision (0.202) and full-page OCR clutter.

.\.venv\Scripts\python.exe scripts\predict.py `
  --input data\cubicasa5k\high_quality_architectural\1191\F1_scaled.png `
  --output results\phase4\test_1191

Structured output: segmentation polygons, OCR and entity identifiers

The resulting structured_output.json uses original-image pixel coordinates and deliberately represents walls as approximate polygons, not CAD/BIM objects or physical measurements.

Phase 5: end-to-end evidence and local demo

The frozen pipeline was run on the first 24 entries of the official held-out test split, a deterministic evaluation subset selected before any Phase 5 inspection. It is a structure/count check, not instance matching: CubiCasa SVG polygons provide room, door, and window counts, but do not provide trustworthy OCR or connectivity labels. The resulting mean absolute count errors were 3.25 rooms, 4.17 doors, and 4.42 windows per plan. Of 997 detected room/opening components attempted by the vectoriser, 996 formed valid polygons (99.90%). End-to-end mean runtime was 4.45 seconds per plan on the RTX 5070 Ti, including image load, segmentation, whole-page OCR, geometry, links, and JSON assembly.

Fixed-rule held-out result: source, target segmentation, prediction, and structured overlay

Robustness uses fixed mild brightness, contrast, blur, Gaussian-noise, JPEG, 3-degree rotation, and down/up-sampling transformations on 12 held-out plans and 24 held-out synthetic OCR crops. Segmentation foreground mIoU stayed within 0.405--0.414 across these transformations. OCR was more sensitive: the small sample's exact-match score ranged from 54.2% for rotation to 75.0% for contrast, and noise had the worst CER (108.7%). These results are diagnostic only; the synthetic subset is not a replacement for real-plan transcription ground truth. The complete machine-readable reports are under results/phase5/robustness/ and results/phase5/structured_evaluation/.

Error-analysis examples are selected by fixed extrema across the same first 24 held-out entries, rather than chosen manually. They include strong/weak segmentation, missed/false openings, high/unassigned text links, and resolved/unresolved doorway links. The particularly weak opening precision and full-page OCR clutter remain visible in the saved examples.

The optional Streamlit viewer accepts PNG, JPG, or a selected PDF page and shows the original, segmentation, OCR/geometry overlay, warnings, connectivity edges, expandable JSON, and a JSON download button. It is a local inspection tool, not a deployment claim.

Phase 6: calibrated review, optional OCR comparison, and geometry refinement

Phase 6 adds dependency-free confidence calibration utilities, conservative high / medium / low_review bands in structured geometry, polygon validity metadata, and PCA-based approximate wall centerlines. The published checkpoint is now tracked in Git and verified by:

python scripts/verify_checkpoint.py

An optional PaddleOCR 3 adapter is available for environments with a compatible PaddlePaddle runtime:

uv pip install --python .venv\Scripts\python.exe -e ".[paddle]"
python scripts/compare_ocr.py --input path\to\plan.png

The adapter is intentionally optional; the current environment records it as optional_not_installed in results/phase6/report.json instead of claiming an unrun benchmark. Phase 6 release checks and the checkpoint checksum are implemented in scripts/evaluate_phase6.py.

Limitations

  • CubiCasa5K plans are not representative of UK planning documents; no UK-wide generalisation or production-readiness claim is made.
  • The OCR score is from synthetic technical text. CubiCasa SVGs have geometry, not transcription ground truth, so real-plan OCR is qualitative only.
  • Pixel-coordinate polygons are approximate inspection geometry, not CAD/BIM, physical scale, or recovered dimensions. Curves and thin openings simplify poorly.
  • High door recall comes with low precision, creating false openings, review warnings, and unreliable connectivity on difficult plans.
  • The pipeline does not estimate property risk, value, or nationwide coverage.

See the methodology, data instructions, and the public job reference for detail.

Releases

Packages

Contributors

Languages