Home

Awesome

<h1 align='center'>Label-Pixels</h1>

Label-Pixels is the tool for semantic segmentation of remote sensing imagery using Fully Convolutional Networks (FCNs). Initially, this tool developed for road extraction from high-resolution remote sensing imagery and now, this tool can be used to extract various features. This is part of my MSc research work (Automatic Road Extraction from High-Resolution Remote Sensing Imagery using Fully Convolutional Networks and Transfer Learning), worked under Mr. Ashutosh Kumar Jha (IIRS) and Dr. Claudio Persello (ITC, University of Twente).

Tested on

python 3.7.15
Keras 2.9.0 
Tensorflow 2.9.2
gdal 2.2.3
scikit-learn 1.0.2

Checkout Demo in Google Colab

:point_right: Google Colab Notebook

Installation

Clone repository

git clone https://github.com/venkanna37/Label-Pixels.git
cd Label-Pixels

Setup environment

conda env create -f environment.yml
conda activate label-pixels
cd tools

Usage

<p align="center"> <img width="900" height="370" src="/data/figures/methodology.png"> </p>

Rasterize

optionsDescription
--helpPrint usage information
--raster_dirDirectory that contains raster image/images
--vector_dirDirectory that contains vector files with the same projection as raster data. And name of the vector and raster files should be same.
--raster_formatRaster format of the image/images
--vector_formatVector format ex: shp, geojson, etc.
--output_dirOutput directory to save labels
--bufferBuffer length for line feature. Not required for polygon
--buffer_atrAttribute from the vector file, this attribute can be buffer width and it multiplies with --buffer.
--labels_atrAttribute from the vector file, pixels inside the polygon will be assigned by its attribute value.

<b>Examples:</b>

python rasterize.py --raster_dir ../data/spacenet/raster/ --raster_format tif --vector_dir ../data/spacenet/vector/ --vector_format shp --buffer 2 --output_dir ../data/spacenet/labels/ --label_atr partialDec --buffer_atr lanes

python rasterize.py --raster_dir ../data/spacenet/raster/ --vector_dir ../data/spacenet/vector_multi/ --vector_format shp --output_dir ../data/spacenet/labels/ --label_atr value

Patch Generation

optionsDescription
--image_folderFolder of input images/tiles with directory
--image_formatImage format tiff/tif/jpg/png
--label_folderFolder of label images with directory
--label_formatLabel format tiff/tif/jpg/png
--patch_sizePatch size to feed network. Default size is 256
--overlapOverlap between two patches on image/tile (units: pixels)
--output_folderOutput folder to save patches

<b> Example: </b>

python patch_gen.py --image_folder ../data/massachusetts/test/image/ --image_format tiff --label_folder ../data/massachusetts/test/roads_and_buildings/ --label_format tif --patch_size 256 --output_folder ../data/mass_patches/

CSV Paths

optionsDescription
--image_folderFolder of image patches with directory
--image_formatImage format tif (patch_gen.py save patches in tif format)
--label_folderFolder of label patches with directory
--label_formatLabel format tif (patch_gen.py save patches in tif format)
--patch_sizePatch size to feed network. Default size is 256
--output_csvcsv filename with directory

<b> Example </b>

python csv_paths.py --image_folder ../data/mass_patches/image/ --label_folder ../data/mass_patches/label/ --output_csv ../paths/data_rnb.csv

Training

optionsDescription
--modelName of the FCN model. Existing models are unet, unet_mini, segnet and resunet
--train_csvCSV file name with directory, consists of directories of image and label patches of training set.
--valid_csvCSV file name with directory, consists of directories of image and label patches of validation set.
--input_shapeInput shape of model to feed patches (patch_size patch_size channels)
--batch_sizeBatch size, depends on GPU/CPU memory
--num_classesNumber of classes in labels data
--epochsNumber of epochs
--rsRadiometric resolution of the input images to rescale (Eg: 8, 12 and etc.)
--rs_labelThe value for rescaling label images (Eg: --rs_label 255 for converting 0 & 255 values to 0 & 1
--weightsPretrained weights file for fine tuning the model

<b> Example </b>

python train.py --model unet_mini --train_csv ../paths/data_rnb.csv --valid_csv ../paths/data_rnb.csv --input_shape 256 256 3 --batch_size 4 --num_classes 3 --epochs 100

Accuracy

optionsDescription
--input_shapeInput shape of model (patch_size, patch_size, channels)
--weightsTrained model with directory
--csv_pathsCSV file name with directory, consists of directories of image and label patches of test set.
--num_classesNumber of classes in labels data

<b> Example </b>

python accuracy.py --model unet_mini --input_shape 256 256 3 --weights ../trained_models/unet_mini_256_100_23_10_22.hdf5 --csv_paths ../paths/data_rnb.csv --num_classes 3

Prediction

optionsDescription
--modelName of the FCN model. Existing models are unet, unet_mini, segnet and resunet
--input_shapeInput shape of model (patch_size, patch_size, channels)
--weightsTrained model with directory
--image_folderFolder of input images/tiles with directory
--image_formatImage format tiff/tif/jpg/png
--output_folderOutput folder to save predicted images/tiles
--num_classesNumber of classes in labels data
--rsRadiometric resolution of the input images (Eg: 8, 12 and etc.)

<b> Example: </b>

python tile_predict.py --model unet_mini --input_shape 256 256 3 --weights ../trained_models/unet_mini_256_100_07_11_22.hdf5 --image_folder ../data/massachusetts/test/image/ --image_format tiff --output_folder ../data/predictions/ --num_classes 3

Summary of the Model

optionsDescription
--modelName of FCN model. Existing models are unet, unet_mini, segnet and resunet
--input_shapeInput shape of model to feed (patch_size patch_size channels)
--num_classesNumber of classes to train

<b> Example </b>

python summary.py --model unet_mini --input_shape 256 256 3 --num_classes 3

For examples of other scripts, check Google Colab Demo Notebook

Example Outputs

<p align="center"> <img width="900" height="1300" src="/data/figures/mass_sota.png"> </p>

Benchmark datasets

  1. Massachusetts Benchmark datasets for Roads and Buildings extraction <br/> https://academictorrents.com/browse.php?search=Volodymyr +Mnih
  2. List of Benchmark datasets for semantic segmentation, object detection from remote sensing imagery https://github.com/chrieke/awesome-satellite-imagery -datasets

Any problem with code?

Please open the issue