Giter Club home page Giter Club logo

laika's Introduction

Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.

Laika

Notes and experiments with satellite image data.

Synopsis

The goal of this repo is to research potential sources of satellite image data and to implement various algorithms for satellite image segmentation.

Table of contents

Running the code

The following steps describe the end-to-end flow for the current work in progress. The implementation makes use of a utility to help build a training dataset, and a SegNet encoder/decoder network for image segmentation.

Creating a training dataset

Install some os deps:

brew install mapnik
brew install paralell

Clone and install the skynet-data project:

git clone https://github.com/developmentseed/skynet-data
cd skynet-data

The skynet-data project is a tool for sampling OSM QA tiles and associated satelite image tiles from MapBox.

The first task is to decide what classes to include in the dataset. These are specified in a JSON configuration file and follow the osm tag format. This project attempts to identify 6 types of land use and objects:

cd into classes and create a new configuration mine.json:

[{
  "name": "residential",
  "color": "#010101",
  "stroke-width": "1",
  "filter": "[landuse] = 'residential'",
  "sourceLayer": "osm"
}, {
  "name": "commercial",
  "color": "#020202",
  "stroke-width": "1",
  "filter": "[landuse] = 'commercial'",
  "sourceLayer": "osm"
}, {
  "name": "industrial",
  "color": "#030303",
  "stroke-width": "1",
  "filter": "[landuse] = 'industrial'",
  "sourceLayer": "osm"
}, {
  "name": "vegetation",
  "color": "#040404",
  "stroke-width": "1",
  "filter": "([natural] = 'wood') or 
             ([landuse] = 'forest') or 
             ([landuse] = 'tree_row') or 
             ([landuse] = 'tree') or 
             ([landuse] = 'scrub') or 
             ([landuse] = 'heath') or 
             ([landuse] = 'grassland') or 
             ([landuse] = 'orchard') or 
             ([landuse] = 'farmland') or 
             ([landuse] = 'tree') or 
             ([landuse] = 'allotments') or 
             ([surface] = 'grass') or 
             ([landuse] = 'meadow') or 
             ([landuse] = 'vineyard')",
  "sourceLayer": "osm"
},
{
  "name": "building",
  "color": "#050505",
  "stroke-width": "1",
  "filter": "[building].match('.+')",
  "sourceLayer": "osm"
},
{
  "name": "brownfield",
  "color": "#060606",
  "stroke-width": "1",
  "filter": "[landuse] = 'brownfield'",
  "sourceLayer": "osm"
}]

The skynet-data tool will use this configuration to create ground-truth labels for the specified classes. For each satelite image instance, it's pixel-by-pixel ground-truth will be encoded as an image with the same size as the satelite image. An individual class will be encoded by colour, such that a specific pixel belonging to an individual class will assume one of 7 colour values corresponding to the above configuration.

For example, a pixel belonging to the vegetation class will assume the RGB colour #040404 and a building will assume the value #050505. Note that these can be any RGB colour. For convenience, I have chosen to encode the class number in each of the 3 RGB bytes so that it can be easily retrieved later on without the need for a lookup table.

Note that it is possible for a pixel to assume an unknown class in which case, it can be considered as "background". Thus Unknown pixels have been encoded as #000000 (the 7th class).

Next, in the skynet-data parent directory, add the following to the Makefile:

QA_TILES?=united_kingdom
BBOX?='-3.3843,51.2437,-2.3923,51.848'
IMAGE_TILES?="tilejson+https://a.tiles.mapbox.com/v4/mapbox.satellite.json?access_token=$(MapboxAccessToken)"
TRAIN_SIZE?=10000
CLASSES?=classes/mine.json
ZOOM_LEVEL?=17

This will instruct the proceeding steps to download 10,000 images from within a bounding box (defined as part of the South-west here). The images will be randomly sampled within the bounding box area. Zoom level 17 corresponds to approx. 1m per pixel resolution. To specify the bounding box area, this tool is quite handy. Note that coordinates are specified in the following form:

-lon, -lat, +lon, +lat

Before following the next steps, go to MapBox and sign up for a developer key.

Having obtained your developer key from MapBox, store it in an env. variable:

export MapboxAccessToken="my_secret_token"

Then initiate the download process:

make clean
rm -f data/all_tiles.txt
make download-osm-tiles
make data/all_tiles.txt
make data/sample.txt
make data/labels/color
make data/images

You will end up with 10,000 images in data/images and 10,000 "ground truth" images in data/labels. data/sample-filtered.txt contains a list of files of which at least 1 pixel belongs to a specified class.

Image sampling

Note, that there is in a convenience tool in the skynet-data utility for quickly viewing the downloaded data. To use it, first install a local webserver, e.g., Nginx and add an alias to the preview.html file. You can then visualise the sampled tiles by following a URL of the following form:

http://localhost:8080/preview.html?accessToken=MAPBOX_KEY&prefix=data

See notebooks for a visual inspection of some of the data. The following shows some of the downloaded tiles with overlaid OSM labels:

OSM labels

The level of detail can be quite fine in places, while in others, quite sparse. This example shows a mix of industrial (yellow) and commercial (blue) land areas mixed in with buildings (red) and vegetation (green).

The model

The model implemented here is the SegNet encoder/decoder architecture. There are 2 variations of this architecure, of which the simplified version has been implemented here. See paper for details. Briefly, the architecture is suited for multi-class pixel-by-pixel segmentation and has been shown to be effective in scene understanding tasks. Given this. it may also be suited to segmentation of satelite imagery.

Side note: The architecutre has been shown to be very effective at segmenting images from car dashboard cameras, and is of immediate interest in our street -view related research.

The model, specified in model.py, consists of 2 main components. The first is an encoder which takes as input a 256x256 RGB image and compresses the image into a set of features. In fact, this component is the same as a VGG16 network without the final fully connected layer. In place of the final fully connected layer, the encoder is connected to a decoder. This decoder is a reverse image of the encoder, and acts to up-sample the features.

The final output of the model is a N*p matrix, where p = 256*256 corresponding to the original number of image pixels and N = the number of segment classes. As such, each pixel has an associated class probability vector. The predicted segment/class can be extrcacted by taking the the max of these values.

Training

First install numpy, theano, keras and opencv2 Then:

python3 train.py

train.py will use the training data created with skynet in the previous step. Note that by default, train.py expects to find this data in ../skynet-data/data. Having loaded the raw training data and associated segment labels into a numpy array, the data are stored in HDF5 format in data/training.hdf5. On subsequent runs, the data loader will first look for this HDF5 data as to reduce the startup time. Note that the data/training.hdf5 can be used by other models/frameworks/languages.

In current form, all parameters are hard-coded. These are the default parameters:

Parameter Default Note
validation 0.2 % of dataset to use as training validation subset
epochs ! 10 number of training epochs
learning_rate 0.001 learning rate
momentum 0.9 momentum

As-is, the model converges at a slow rate:

img

Training and validation errors (loss and accuracy) are stored in training_log.csv. On completion, the network weights are dumped into weights.hdf5 - Note that this may be loaded into the same model implemented in another language/framework.

Validating

Having trained the model, validate it using the testing data held back in the data-preparation stage:

python3 validate.py

validate.py expects to find the trained model weights in weights.hdf5 in the current working directory. In addition to printing out the validation results, the pixel-by-pixel class probabilities for each instance are stored in predictions.hdf5 which can be inspected to debug the model.

Running

feed_forward.py takes as input trained weights, an input image and an output directory to produce pixel-by-pixel class predictions.

python3 feed_forward.py <hdf5 weights> <img location> <output dir>

Specifically, given an input satellite image, the script outputs the number of pixels belonging to one the 8 land-use classes, such that the sum of class pixels = total number of pixels in the image. In addition, the script will output class heatmaps and class segments visualisations in to the <output dir>.

segmented

The class heatmaps (1 image per class) show the model's confidence that a pixel belongs to a particular class (buildings and vegetation shown above). Given this confidence, the maximum value from each class is used to determine the final pixel segment, shown on the right in the above image. Some more visualisations can be found in this notebook.

Further work/notes

  • The model as-is, is quite poor, trained to only 70% accuracy over the validation set).
  • The model has only been trained once: fine-tuning and hyperparameter search has not yet been completed.
  • The training data is very noisy: the segments are only partially labelled. As such, missing labels are assigned as "background".

Background research

Satellite themes of interest

In general, satellite image processing themes can be categorised into two main themes:

Earth Observation (EO)

The field of Earth observation is concerned with monitoring the status of the planet with various sensors, which includes, but is not limited to, the use of satellite data for monitoring large areas of the earth's surface at regular, frequent intervals.

EO is a broad area, which may cover water management, forestry, agriculture, urban fabric and land-use/cover in general.

A good example of EO is the use of the normalised difference vegetation index (NDVI) for monitoring nationwide vegetation levels.

This sub-field does not depend on very high resolution data since it is mainly concerned with quantifying some aspect of very large areas of land.

Object detection

In contrast to EO, the field of object detection from satellite data is principally concerned with the localisation of specific objects as opposed to general land-use cover.

A good example of Object detection from satellite data is counting cars in carparks from which various indicators can be derived, depending on the context. For example, it would be possible to derive some form of consumer/retail indicator by periodically counting cars in super market car parks.

This sub-field will depend on very high resolution data depending on the application.

Computer vision themes of interest

In addition to the two main satellite image processing themes of interest (EO and object detection), there are four more general image processing sub-fields which may be applicable to a problem domain. From "easiest" to most difficult:

  1. Classification. At the lowest level, the task is to identify which objects are present in a scene. If there are many objects, the output may be an ordered list sorted by amount or likelyhood of the object being present in the scene. The classification may also extend beyond objects to abstract concepts such as aesthetic value.

  2. Detection. The next level involves localisation of the entities/concepts in the scene. Typically this will include a bounding-box around identified objects, and/or object centroids.

  3. Segmentation. This level extends classification and detection to include pixel-by-pixel class labeling. Each pixel in the scene must be labeled with a particular class, such that the entire scene can be described. Segmentation is particularly appropriate for land-use cover. In addition, segmentaiton may be extended to provide a form of augmented bounding-box: pixels outside of the bounding box area can be negatively weighted, pixels on the border +1 and pixels inside the region [0, 1] inversely proportionate to the distance form the bounding box perimeter.

  4. Instance segmentation. Perhaps the most challenging theme: In addition to pixel-by-pixel segmentation, provide a segmented object hierarchy, such that objects/areas belonging to the same class may be individually segmented. E.g., segments for cars and car models. Commercial area, office within a commercial area, roof-top belonging to a shop etc.

The initial version of this project focuses on option 3: image segmentation in the domain of both Earth Observation and object detection.

Data sources

There are three types of data of interest for this project.

  1. Raw image data. There are numerous sources for satellite image data, ranging from lower resolution (open) data most suited for EO applications, through to high resolution (mostly propitiatory) data-sets.

  2. Pre-labeled image data. For training an image classificiation, object detection or image segmentation supervised learning model, it is necessary to obtain ample training instances along with associated ground truth labels. In the domain of general image classification, there exist plenty of datasets which are mainly used to benchmark various algorithms.

  3. Image labels. It will later be required to create training datasets with arbitrary labeled instances. For this reason, a source of ground-truth and/or a set of tools to facilitate image labeling and manual image segmentation will be necessary.

Raw image data

This project (to date) focuses specifically on open data. The 2 main data sources for EO grade images come from the Sentinel-2 and Landsat-8 satellites. Both satellites host a payload of multi-spectrum imaging equipment.

Sentinel 2 (ESA)

The Sentinel-2 satellite is capable of sensing the following wavelengths:

Band Wavelength (μm) Resolution (m)
01 – Coastal aerosol 0.443 60
02 – Blue 0.490 10
03 – Green 0.560 10
04 – Red 0.665 10
05 – Vegetation Red Edge 0.705 20
06 – Vegetation Red Edge 0.740 20
07 – Vegetation Red Edge 0.783 20
08 – NIR 0.842 10
8A – Narrow NIR 0.865 20
09 – Water vapour 0.945 60
10 – SWIR – Cirrus 1.375 60
11 – SWIR 1.610 20
12 – SWIR 2.190 20

"Sentinel 2"

The visible spectrum captured by Sentinel-2 is the highest (open) data resolution available: 10 metres per pixel. Observations are frequent: Every 5 days for the same viewing angle.

Landsat-8 (NASA)

The Landsat-8 satellite is limited to 30m resolution accross all wavelengths with the exception of it's panchromatic sensor, which is capable of capturing 15m per pixel data. The revisit frequency for landsat is 16 days.

Band Wavelength (μm) Resolution (m)
01 - Coastal / Aerosol 0.433 – 0.453 30
02 - Blue 0.450 – 0.515 30
03 - Green 0.525 – 0.600 30
04 - Red 0.630 – 0.680 30
05 - Near Infrared 0.845 – 0.885 30
06 - Short Wavelength Infrared 1.560 – 1.660 30
07 - Short Wavelength Infrared 2.100 – 2.300 30
08 - Panchromatic 0.500 – 0.680 15
09 - Cirrus 1.360 – 1.390 30

"Landsat 8"

Links

Papers

Other

Pre-labeled image data

There are numerous sources of pre-labeled image data available. Recently, there have been a number of satellite image related competitions hosted on Kaggle and TopCoder. This data may be useful to augment an existing dataset, to pre-train models or to train a model for later use in an ensemble.

Object and land-use labels

There exist a number of land-use and land-cover datasets. The main issue is dataset age: If the objective is to identify construction sites or urban sprawl then a dataset > 1 year is next to useless, unless it can be matched to imagery from the same time period which would then only be useful for the creation of a training dataset.

The most promising source (imo) is the OpenStreetMap project since it is updated constantly and contains an extensive hierarchy of relational objects. There is also the possibility to contribute back to the OMS project should manual labeling be necessary.

Modeling

The proof of concept in this project makes use of concepts from deep learning. A review of the current state of the art, covering papers, articles, competitive data science platform results and open source projects indicates that the most recent advances have been in the area of image segmentation - most likely fueled by research trends in autonomous driving..

From the image segmentation domain, the top performing, most recent developments tend to be some form of encoder/decoder neural network in which the outputs of a standard CNN topology (E.g., VGG16) are upsampled to form class probability matrices with the same dimensions as the original input image.

The following papers and resources provide a good overview of the field.

Modeling Papers

Satelite specific

2017
2016
2015
2014
2013

Modeling specific

2017
2016
2015

Model implementations

There exist a number of implementations of recent satelite image procesing techniques. The following Github respositories are a good research starting point:

  1. random forests Java :)

  2. Multi-scale context aggregation by dilated convolutions (Tensorflow)

  3. Instance-aware semantic segmentation via multi- task network cascades (Caffe)

  4. Fully Convolutional Network (FCN) + Gradient Boosting Decision Tree (GBDT) (Keras)

  5. FCN (Keras)

Image segmentation model implementations

General

SegNet

Segnet architecture

Keras implementations:

(note these are all the basic version from the approach described in the paper.

U-Net

Keras implementations:

DeepLab

Note, there seems to be no Keras implementation. Tensorflow implementations:

Dilated Convolutions

PSPNet (Pyramid Scene Parsing Network)

Bleeding edge. More details here

Comeptitive data science

Lots of interesting reading and projects.

DSTL - Kaggle

  1. U-Net

  2. not known

  3. Another U-Net

  4. modified U-Net

  5. pixel-wise logistic regression model

Understaning Amazon from space - Kaggle

  1. 11 convolutional neural networks - This is pretty nice, details winners' end-to-end architecture.

Current competitions

Tools/utilities

  • SpaceNetChallenge utlitiles - Github - Packages intended to assist in the preprocessing of SpaceNet satellite imagery data corpus to a format that is consumable by machine learning algorithms.

  • Sentinelsat - Github - Utility to search and download Copernicus Sentinel satellite images.

Visualisations/existing tools

Projects using Sentinel data

Blogs

Other

laika's People

Contributors

chrisns avatar ioannistsalamanis avatar phil8192 avatar stevenh-wg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laika's Issues

skynet data

Hi,

Is the skynet data available? could you share it?
I check up all folders but not find it.

Thansk in advance, JL

Implement signed distance transform

When classifying an object or area, there are actually 3 labels: inside, edge, outside. With segmentation, just having an object mask (1 = pixel in object, 0 = pixel does not contain object) will cause issues: will be hard to differentiate adjacent objects + lots of info is lost (e.g., building size). This method labels a pixel as +ve if inside object (higher the further away from boundary), 0 if boundary and -ve if outside. This can be visualised with ease, and makes the decision surface "smoother". It retains distance information and can even be converted into standard masks by taking sign(pixel).

Class rebalancing

  • Weight training instance labels according to ratio of class types: Loss function should not be guided by dominant class.
  • Keras has functionality for this.

Unexpected token error when trying to build using npm

SyntaxError: Unexpected token

at Object.parse (native)
at Object.<anonymous> (/workspace/skynet-data/label-counts:11:20)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)
at startup (node.js:136:18)
at node.js:966:3

undefined:23
"filter": "([natural] = 'wood') or

I am guessing it is something to do with my mine.json file. Can you please help me with this.

Try to find pre-labelled Sentinel 2 image data (Earth observation)

We will likely make use of Sentinel 2 data for non-object detection/EO. It would be nice to find some pre-labelled data as to get something up and running asap. Labels may include general land-use: Industrial, urban fabric, agricultural etc.

Failing this, would have to look into creating the labels from external source (e.g., Open street map land use polygons) - Which we will need to do anyway, but at this stage we are looking to implement an end-to-end proof of concept.

Evaluate skynet-data

evaluate this - it builds a training set by combining openstreetmap features from OSM QA tiles with satellite image tiles from mapbox.

  • uses osm.
  • since it is tile based, will be easy to manipulate (will be able to directly render any results on map)

Choose model to implement first

Choose a pixel-wise segmentation approach for initial implementation. From the current state of the art:

  • SegNet (Probably most straight forward) (2014 - Old).
  • U-Net (Another encoder-decoder. 2nd place in DSTL.)
  • DeepLab (V3 of this is current bleeding edge in benchmark tests. Complicated)
  • Dilated Convolutions
  • PSPNet (Pyramid Scene Parsing Network) Bleeding edge. Also current leader in street scene parsing. 2-birds 1-.....

See reference implementations (Keras and/or TensorFlow) in references.md as starting point.

Error when checking model target

C02STFEGGTFM:laika stubp$ python3 ./train.py 
Using Theano backend.
Loaded model.
Model compiled.
Loading training data from HDF5.
Loaded data.
Traceback (most recent call last):
  File "./train.py", line 22, in <module>
    hist = m.fit(images, labels, batch_size=14, epochs=100, verbose=1)
  File "/usr/local/lib/python3.6/site-packages/keras/models.py", line 853, in fit
    initial_epoch=initial_epoch)
  File "/usr/local/lib/python3.6/site-packages/keras/engine/training.py", line 1406, in fit
    batch_size=batch_size)
  File "/usr/local/lib/python3.6/site-packages/keras/engine/training.py", line 1300, in _standardize_user_data
    exception_prefix='model target')
  File "/usr/local/lib/python3.6/site-packages/keras/engine/training.py", line 133, in _standardize_input_data
    str(array.shape))
ValueError: Error when checking model target: expected activation_5 to have shape (None, 65536, 12) but got array with shape (3669, 65536, 7)

no pre-trained weights provided

Hello!
Please, can I ask you for the pre-trained weights? You use them in one of the examples but I cannot find the file with weights anywhere in the project. Thank you!

Google satellite image API pre-processing

Some existing work has made use of satellite imagery obtained from Google static map image API. One combines such imagery with the Urban Atlas land-use data. Another project combines open street map data with google sat. image data for detecting zebra-crossings.

Implement a module that takes as input a single image tile obtained from the google API and combines it with object and/or land-use labels from another source. The output should be a set of masks for each label.

Should this be feasible, additional tasks will entail large scale pre-processing (e.g., defining area of interest and processing in batches etc.)

Skywalker

Project has over-run taken 1 month instead of 2 weeks

Next Steps

  • Coach other people to use the pipeline

Notes

  • Pipeline is ready and documentation is close to completion
  • Been offered construction data from Barbour to validate identification of brown field sites

Model parameter versioning

  • Currently learned model weights are stored in a HDF5 file.
  • The network topology and weights should be stored in such as way that makes model comparison and later model aggregation easy.
  1. Store network topology as JSON on Github.
  2. Store network meta data + learning parameters as JSON on Github.
  3. Store learned model weights on Github using Git LFS. The weights should be in HDF5 format.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.