gabrielchao / terrainclassifier

Deep learning-based semantic segmentation terrain classifier for aerial orthophotos. Built using Keras-Tensorflow and with several open-source CNN repositories.
10 stars 4 forks source link

Terrain Classifier

Example predictions

A semantic segmenation classifier for RGB aerial orthophotos. Given overhead, birds-eye-view images of terrain, terrainclassifier classifies each pixel of the image by type of terrain. The output is an image of the same resolution as the original, but with each pixel colour-coded to indicate its terrain class.

terrainclassifier is able to identify the following types of terrain:

terrainclassifier is built to be trained with the ISPRS Potsdam Dataset.

This package was made as part of a project to explore the field of deep learning. For a more thorough explanation of this package, as well as the basic deep learning principles behind it, please view the project report in PDF format.

What's Inside

This package consists of preprocessing and training utilities bundled with three Keras CNN (convolutional neural network) models.

The architectures implemented in the models are:

These models were implemented with code from open source repositories (see Acknowledgements).

Built with

Usage

The Keras models must be trained before they can be used for prediction. Pre-trained weights are not provided. The training dataset can be downloaded via the ISPRS website.

Training:

If training with the Potsdam dataset, ensure that the dataset has been placed correctly in the datasets/Potsdam folder. Command line usage with arguments is currently disabled. To enable it, follow the instructions in the comments in train.py. Instead, train.py can be conveniently used by modifying the code using the convenience training functions train_fcn(), train_pspnet(), and train_mobilenetv2().

Run the train.py script with Python in the command line like so:

python train.py

The help documentation is as follows:

usage: train.py [-h] [--model_name {fcn,pspnet,mobilenetv2}]
                [--model_file MODEL_FILE] [--save_path SAVE_PATH]
                [--batch_size BATCH_SIZE] [--steps_per_epoch STEPS_PER_EPOCH]
                [--epochs EPOCHS] [--validation_steps VALIDATION_STEPS]

optional arguments:
  -h, --help            show this help message and exit
  --model_name {fcn,pspnet,mobilenetv2}
                        Model to train
  --model_file MODEL_FILE
                        Model file as h5 format. If not specified, new model
                        will be created
  --save_path SAVE_PATH
                        Path to save trained model file. If not specified,
                        will save in default path
  --batch_size BATCH_SIZE
                        Number of patches in each training and validation
                        batch
  --steps_per_epoch STEPS_PER_EPOCH
                        Number of training batches in each epoch
  --epochs EPOCHS       Number of epochs
  --validation_steps VALIDATION_STEPS
                        Number of batches for validation after each epoch

Prediction:

Run the predict_tile.py script with Python in the command line like so:

python predict_tile.py

The help documentation is as follows:

usage: predict_tile.py [-h] [--model_name {fcn,pspnet,mobilenetv2}]
                       [--model_file {artifacts/model_FCN.h5,artifacts/model_PSPNet.h5,artifacts/model_MobileNetv2.h5}]
                       [--tile_file TILE_FILE] [--batch_size BATCH_SIZE]
                       [--save_name SAVE_NAME]

optional arguments:
  -h, --help            show this help message and exit
  --model_name {fcn,pspnet,mobilenetv2}
                        Model to use
  --model_file {artifacts/model_FCN.h5,artifacts/model_PSPNet.h5,artifacts/model_MobileNetv2.h5}
                        Model file as h5 format. If not specified, uses
                        default file for given model name
  --tile_file TILE_FILE
                        Tile file as tif format
  --batch_size BATCH_SIZE
                        Number of patches in each batch
  --save_name SAVE_NAME
                        Filename to save predicted image

Acknowledgments

terrainclassifier uses Keras models derived from the following sources: