This project is a deep learning-based tool for automatically vectorizing floor plan images. It takes a raster image (PNG, JPG) of a floor plan as input and outputs a structured JSON file containing the coordinates of walls and openings (doors/windows).
The main goal of this project is to provide a fast and accurate way to convert raster images of floor plans into structured vector data. This data can be used in various applications, such as interior design software, real estate management systems, and architectural analysis tools.
- Clone the repository:
git clone https://github.com/pimenoffd/floor-plan-vectorizer.git cd floor-plan-vectorizer - Create and activate a virtual environment:
python -m venv .venv source .venv/bin/activate - Install dependencies:
pip install -r requirements.txt
- Place your images in the
inputdirectory. - Configure your settings in the
config.yamlfile. - Run the main script:
python main.py
- The results will be saved in the
outputfolder. For each input image, a.jsonfile with structured data and adebug_...image with the predicted polygons drawn on it will be created.
The project uses a config.yaml file for configuration.
model.weights_path: Path to the trained model weights file (.pth).vectorizer.confidence_threshold: Confidence threshold for binarizing segmentation masks (a value between 0 and 1).- Other parameters for paths, training, and logging are also available in
config.yaml.
To train the model on your own dataset, follow these steps:
-
Prepare your dataset. The project includes a script for processing the CubiCasa5k dataset.
- Place the raw CubiCasa5k dataset in the
data/source/cubicasa5kdirectory (or update thecubicasa_processor.cubicasa_rootpath inconfig.yaml). - Run the preparation script:
python -m core.data_processing.prepare_cubicasa
- The processed dataset will be saved in the directory specified by
cubicasa_processor.output_dirinconfig.yaml.
- Place the raw CubiCasa5k dataset in the
-
Configure training parameters. Open
config.yamland adjust the parameters in thetrainingsection as needed (e.g.,batch_size,learning_rate,num_epochs). -
Run the training script.
python -m core.model_definitions.train
The best model weights will be saved in the directory specified by
training.weights_dirinconfig.yaml.
The core/data_processing directory contains scripts to help prepare datasets for training.
coco_to_mask.py: A versatile script to convert any dataset from COCO annotation format to segmentation masks. This is useful if you want to use a custom dataset that is annotated in COCO format. It handles splitting the data intotrain,valid, andtestsets and maps annotation categories to the class IDs used by the model.check_alignment.py: A debugging tool to visually inspect the alignment between images and their generated masks. It takes a sample of images from the training set, overlays the masks with color-coding, and saves them to thedebug_alignmentdirectory. This is crucial for verifying that the data preparation was successful before starting a lengthy training process.
The project includes a suite of automated tests to ensure the correctness of the vectorization process.
- Run the tests:
pytest
- Test Coverage:
- Unit Tests: These tests cover individual functions in isolation, such as the polygon conversion logic in the
Vectorizer. - Integration Tests: These tests cover the end-to-end vectorization pipeline, from loading a test image to comparing the final JSON output with an expected result. They use a mocked model to ensure deterministic and fast execution.
- Unit Tests: These tests cover individual functions in isolation, such as the polygon conversion logic in the
The project has the following structure:
├── core/
│ ├── data_processing/ # Data processing scripts
│ ├── model_definitions/ # Model definition and training script
│ ├── utils/ # Helper utilities (e.g., vectorizer, device manager)
│ └── custom_exceptions.py # Custom exceptions
├── data/ # Data for training
├── input/ # Input images
├── output/ #
├── tests/ # Automated tests
├── tools/ # Developer tools
├── weights/ # Saved model weights
├── main.py # Main script to run the vectorization
├── config.yaml # Configuration file
├── requirements.txt # Dependencies
└── README.md # This file