Home

Awesome

Convolutional Neural Network (ConvNet) trained on open data from Land Information New Zealand (LINZ). Specifically, we train the ConvNet on aerial photography to detect building outlines.

Getting started

Quickstart

Launch Binder

Binder

Installation

git clone https://github.com/weiji14/nz_convnet.git
cd nz_convnet
conda env create -f environment.yml

Running the jupyter notebook

source activate nz_convnet
python -m ipykernel install --user  #to install conda env properly
jupyter kernelspec list --json      #see if kernel is installed
jupyter notebook

Where the data goes

FolderExample of a file insideextensionNotes
data/vectornz-building-outlines-pilot.shp*.shpsee section Training data/Mask
data/raster/downloadslds-tile-2015-bk39-5000-0401-rgb-GTiff.zip*.zipsee section Training data/Images
data/raster2015_BK39_5000_0401_RGB.tif*.tifunzipped files from data/raster/downloads
data/trainX_2015_BK39_5000_0401_RGB.hdf5*.hdf5binary of tif file to load into numpy array
data/testwellington-03m-rural-aerial-photos-2012-2013.tif*.tifunzipped files similar to those in data/raster

Prediction

In near realtime!

source activate nz_convnet
python predict.py

#You can also set 2 integer parameters:
#  1st argument - output pixel size e.g. 256, 512, 1024 (default: 256)
#  2nd argument - prediction threshold e.g from least accurate 0% accept anything to 100% won't output much (default: 50)
python predict.py 512 50 

Live testing on imagery of Karori, Wellington.

livesample1

To a raster geotiff (which you can vectorize to a polygon)

Once you clone the repository, open the jupyter notebook and follow the instructions to run 'Part 5 - Save Results'. You will need to have some geotiffs inside the data/test folder, and you may need to tweak the (img_height, img_width) parameter.

There might need to be some fiddling on your part to get this parameter right, so that the input RGB image will be tiled perfectly. The algorithm will create a prediction on each tile, and join in back together, so if it is not tiled perfectly due to the user setting, it will raise an error.

Below is a visualization in QGIS 3.0 of a sample test image and the predicted raster mask output

qgissample1

Mask was styled using singleband pseudocolor, linear interpolation, with the OrRd color ramp in equal-interval mode. Opacity set to 0% for values 0, 0.25 and 0.5, and 50% for values 0.75 and 1.0. GIF was recorded using Peek

More output examples

Sample outputs on cross validation dataset plotted with matplotlib inside the jupyter notebook environment. Left is input RGB image, Middle is ConvNet model output, Right is the Mask.

sample1 sample2 sample3

Data sources used to train the keras model

Using freely available data from LINZ Data Service. As there is a 3.5GB limit, we resort to using region crops using the 'Set a crop' tool on the top right. Not ideal but it ensures a little bit of reproducibility.

Training data

Images

Region Crop TypeRegion NameLINZ Data Source
General Electorate Boundaries 2014WigramCanterbury 0.3m Rural Aerial Photos (2015-16)
Manual Tile Selection*Hastings 2015_BK39_5000_{XXXX}_RGB0401 0402 0403 0404 0405 0501 0502 0503 0504 0505 0601 0602 0603 0604 0605
Manual Tile Selection*Tuakau bb32_{XXXX}4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039

Mask

Test data

Region Crop TypeRegion NameLINZ Data Source
NZ Topo 50 Map SheetsBP31 - PoriruaWellington 0.3m Rural Aerial Photos (2012-2013)