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.
Launch Binder
git clone https://github.com/weiji14/nz_convnet.git
cd nz_convnet
conda env create -f environment.yml
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
Folder | Example of a file inside | extension | Notes |
---|---|---|---|
data/vector | nz-building-outlines-pilot.shp | *.shp | see section Training data/Mask |
data/raster/downloads | lds-tile-2015-bk39-5000-0401-rgb-GTiff.zip | *.zip | see section Training data/Images |
data/raster | 2015_BK39_5000_0401_RGB.tif | *.tif | unzipped files from data/raster/downloads |
data/train | X_2015_BK39_5000_0401_RGB.hdf5 | *.hdf5 | binary of tif file to load into numpy array |
data/test | wellington-03m-rural-aerial-photos-2012-2013.tif | *.tif | unzipped files similar to those in data/raster |
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.
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
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
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.
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.
Region Crop Type | Region Name | LINZ Data Source |
---|---|---|
General Electorate Boundaries 2014 | Wigram | Canterbury 0.3m Rural Aerial Photos (2015-16) |
Manual Tile Selection* | Hastings 2015_BK39_5000_{XXXX}_RGB | 0401 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 |
- Manual tile selection selects tiles manually from the tiles table, e.g. here
- NZ Building Outlines (Pilot) in shapefile format.
Region Crop Type | Region Name | LINZ Data Source |
---|---|---|
NZ Topo 50 Map Sheets | BP31 - Porirua | Wellington 0.3m Rural Aerial Photos (2012-2013) |