Skip to content

NINAnor/schoolmap

Repository files navigation

SchoolMap: Mapping of school yard in Norway 🏫

This repository contains the code necessary to train and run DeepLabV3 on satellite pictures. In particular, for our project we were interested in segmenting school yard in Norway.

Install the required libraries

pip install poetry
poetry install

Changing the CONFIG file

The configs folder contains a list of the config files necessary to use this repository's pipeline. The only config file you need to modify is the /configs/paths/default.yaml, which contains all the paths the pipeline is using.

How to Use

  1. Extract the Satellite Images

Use the script to download and prepare the satellite images used for training and testing. The exact source and format of the images should be configured in the config.yaml file.

poetry run python3 src/dataset/get_train_images.py
  1. Rasterize the Masks

This step converts GeoJSON or vector data into raster format, creating segmentation masks that correspond to your satellite images. These masks are required for training the model.

poetry run python3 src/dataset/rasterize_masks.py
  1. Train the Model

Once the dataset (images and masks) is ready, train the segmentation model using DeepLabV3 by running the following:

poetry run python3 src/train.py

The training script supports early stopping, model checkpoints, and tracks the loss function and evaluation metrics (IoU, Precision, Recall, DICE, Pixel accurracy).

  1. Predictions

Note: The predict script can predict on the test dataset (for which you have labels) or on the pictures without annotation. You need to change the parameter MODE from configs/predict/default.yaml to predict (if you want to predict on unnanotated pictures), or test if you want to predict on the test dataset. This difference occurs only because in the test dataset we have acces to the shapefile of the school, and we don't have to predict on the entire image.

Once the model is trained, you can use it to generate predictions for new images. The following script takes an input image and outputs the corresponding segmentation mask:

poetry run python3 src/predict.py cfg.paths.INPUT_PATH=<input_image_path>

Instead of only predicting a single image at a time, it is also possible to predict on a whole folder using the following command:

find /PATH/TO/IMAGE/FOLDER -name "*.png" | xargs -I {} poetry run python src/predict.py paths.INPUT_IMAGE={}
  1. Compute Evaluation Metrics

To evaluate the model’s performance on the test dataset, run the metrics script. This script computes common segmentation metrics, such as precision, recall, Dice coefficient, and IoU (Intersection over Union):

poetry run python3 src/metrics.py

Results

Here is an example of a segmented image:

About

Mapping of school yard in Norway

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages