Giter VIP home page Giter VIP logo

spacenet_building_detection's Introduction

SpaceNet Building Detection

This repository privides some python scripts and jupyter notebooks to train and evaluate convolutional neural networks which extract buildings from SpaceNet satellite images.

Dependency

Usage

0. Clone this repo

$ PROJ_DIR=~/spacenet_building_detection  # assuming you clone this repo to your home directory

$ git clone --recursive https://github.com/motokimura/spacenet_building_detection.git $PROJ_DIR

1. Download SpaceNet dataset

Download satellite images and ground-truth building footprints (of SpaceNet AOI-1 Rio). Assuming you already configured AWS CLI to download the data from AWS S3.

$ cd $PROJ_DIR/data

# Download processed 200mx200m tiles of AOI 1 (3.4 GB) with associated building footprints
$ aws s3api get-object --bucket spacenet-dataset --key AOI_1_Rio/processedData/processedBuildingLabels.tar.gz --request-payer requester processedBuildingLabels.tar.gz

$ tar -xvf processedBuildingLabels.tar.gz
$ cd processedBuildingLabels
$ tar -xvf 3band.tar.gz

$ cd vectordata 
$ tar -xvf geojson.tar.gz

# Download the Source Imagery Mosaic (3-band = 2.3 GB and 8-band = 6.5 GB)
$ cd $PROJ_DIR/data
$ aws s3api get-object --bucket spacenet-dataset --key AOI_1_Rio/srcData/rasterData/3-Band.tar.gz --request-payer requester 3-Band.tar.gz
$ tar -xvf 3-Band.tar.gz

You can find more details here.

2. Build Docker image

Build docker image to setup the environment to preprocess SpaceNet dataset and train/evaluate convolutional neural networks.

$ cd $PROJ_DIR/docker
$ bash build.sh

I strongly reccomend you to use docker because you may have some troubles to install some geo-spatial data processing libraries. In case you don't want to use docker, you have to install additional dependencies described in Dockerfile.

3. Preprocess SpaceNet dataset

Convert SpaceNet ground-truth building footprints from GeoJSON into building mask images.

Run docker container by following:

$ cd $PROJ_DIR/docker
$ bash run.sh

Now you should be inside the docker container you ran. Convert SpaceNet dataset by following:

$(docker) cd /workspace/src/features
$(docker) python build_labels.py ../../data/processedBuildingLabels/3band ../../data/processedBuildingLabels/vectordata/geojson ../../data/buildingMaskImages

Now you will find many pairs of satellite images and building mask images in $PROJ_DIR/data/processedBuildingLabels/3band and $PROJ_DIR/data/buildingMaskImages respectively like below:

4. Train U-Net

Train U-Net, a convolutional neural network originaly developed for medical image segmentation.

Train U-Net with SpaceNet dataset by following:

$(docker) cd /workspace/src/models
$(docker) python train_model.py ../../data/dataSplit ../../data/processedBuildingLabels/3band ../../data/buildingMaskImages

You can check training status and validation accuracy from TensorBoard:

# Open another terminal window outside the container and type:
$ cd $PROJ_DIR/docker
$ bash exec.sh

# Now you should be inside the container already running. Start TensorBoard by following:
$(docker) tensorboard --logdir /workspace/models

Then, open http://localhost:6006 from your browser.

5. Evaluate U-Net

Evaluate U-Net with jupyter notebook.

Launch jupyter notebook by flollowing:

$(docker) cd /workspace/notebooks
$(docker) jupyter notebook

Then, open http://localhost:8888 from your browser.

Default password is passw0rd as defined in Dockerfile.

Note that you may need to modify the path to pre-trained model defined in the notebooks below.

5.1 Quantitative evaluation

Open this notebook.

5.2 Qualitative evaluation on test tile-images

Open this notebook to see segmentation results on tile images in test-plit.

Output examples:

5.3 Qualitative evaluation on mosaic images

Open this notebook to see segmentation results on source mosaic images.

Output examples:

License

MIT License

spacenet_building_detection's People

Contributors

jacobwhall avatar motokimura 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

spacenet_building_detection's Issues

Error cupy.cuda.memory.OutOfMemoryError: out of memory to allocate

When trying to execute

python train_model.py ../../data/dataSplit ../../data/processedBuildingLabels/3band ../../data/buildingMaskImages

I receive the following error:

/opt/conda/envs/py3.6/lib/python3.6/site-packages/cupy/core/fusion.py:659: FutureWarning: cupy.core.fusion is experimental. The interface can change in the future.
  util.experimental('cupy.core.fusion')
GPU: 0
# Minibatch-size: 16
# Crop-size: 400
# epoch: 50

Exception in main training loop: out of memory to allocate 163840000 bytes (total 1673061376 bytes)
Traceback (most recent call last):
  File "/opt/conda/envs/py3.6/lib/python3.6/site-packages/chainer/training/trainer.py", line 304, in run
    update()
  File "/opt/conda/envs/py3.6/lib/python3.6/site-packages/chainer/training/updaters/standard_updater.py", line 149, in update
    self.update_core()
  File "/opt/conda/envs/py3.6/lib/python3.6/site-packages/chainer/training/updaters/standard_updater.py", line 160, in update_core
    optimizer.update(loss_func, *in_arrays)
  File "/opt/conda/envs/py3.6/lib/python3.6/site-packages/chainer/optimizer.py", line 593, in update
    loss = lossfun(*args, **kwds)
  File "/workspace/src/models/unet.py", line 95, in __call__
    h = self.forward(x)
  File "/workspace/src/models/unet.py", line 61, in forward
    e2 = F.relu(self.bnc2(self.c2(e1)))
  File "/opt/conda/envs/py3.6/lib/python3.6/site-packages/chainer/functions/activation/relu.py", line 141, in relu
    y, = ReLU().apply((x,))
  File "/opt/conda/envs/py3.6/lib/python3.6/site-packages/chainer/function_node.py", line 257, in apply
    outputs = self.forward(in_data)
  File "/opt/conda/envs/py3.6/lib/python3.6/site-packages/chainer/function_node.py", line 364, in forward
    return self.forward_gpu(inputs)
  File "/opt/conda/envs/py3.6/lib/python3.6/site-packages/chainer/functions/activation/relu.py", line 39, in forward_gpu
    y = cuda.cupy.maximum(x[0], 0)
  File "/opt/conda/envs/py3.6/lib/python3.6/site-packages/cupy/core/fusion.py", line 701, in __call__
    return self._cupy_op(*args, **kwargs)
  File "cupy/core/elementwise.pxi", line 804, in cupy.core.core.ufunc.__call__
  File "cupy/core/elementwise.pxi", line 381, in cupy.core.core._get_out_args
  File "cupy/core/core.pyx", line 95, in cupy.core.core.ndarray.__init__
  File "cupy/cuda/memory.pyx", line 439, in cupy.cuda.memory.alloc
  File "cupy/cuda/memory.pyx", line 916, in cupy.cuda.memory.MemoryPool.malloc
  File "cupy/cuda/memory.pyx", line 937, in cupy.cuda.memory.MemoryPool.malloc
  File "cupy/cuda/memory.pyx", line 694, in cupy.cuda.memory.SingleDeviceMemoryPool.malloc
  File "cupy/cuda/memory.pyx", line 749, in cupy.cuda.memory.SingleDeviceMemoryPool._malloc
Will finalize trainer extensions and updater before reraising the exception.
Traceback (most recent call last):
  File "cupy/cuda/memory.pyx", line 731, in cupy.cuda.memory.SingleDeviceMemoryPool._malloc
  File "cupy/cuda/memory.pyx", line 664, in cupy.cuda.memory.SingleDeviceMemoryPool._alloc
  File "cupy/cuda/memory.pyx", line 394, in cupy.cuda.memory._malloc
  File "cupy/cuda/memory.pyx", line 395, in cupy.cuda.memory._malloc
  File "cupy/cuda/memory.pyx", line 67, in cupy.cuda.memory.Memory.__init__
  File "cupy/cuda/runtime.pyx", line 214, in cupy.cuda.runtime.malloc
  File "cupy/cuda/runtime.pyx", line 137, in cupy.cuda.runtime.check_status
cupy.cuda.runtime.CUDARuntimeError: cudaErrorMemoryAllocation: out of memory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "cupy/cuda/memory.pyx", line 737, in cupy.cuda.memory.SingleDeviceMemoryPool._malloc
  File "cupy/cuda/memory.pyx", line 664, in cupy.cuda.memory.SingleDeviceMemoryPool._alloc
  File "cupy/cuda/memory.pyx", line 394, in cupy.cuda.memory._malloc
  File "cupy/cuda/memory.pyx", line 395, in cupy.cuda.memory._malloc
  File "cupy/cuda/memory.pyx", line 67, in cupy.cuda.memory.Memory.__init__
  File "cupy/cuda/runtime.pyx", line 214, in cupy.cuda.runtime.malloc
  File "cupy/cuda/runtime.pyx", line 137, in cupy.cuda.runtime.check_status
cupy.cuda.runtime.CUDARuntimeError: cudaErrorMemoryAllocation: out of memory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "cupy/cuda/memory.pyx", line 743, in cupy.cuda.memory.SingleDeviceMemoryPool._malloc
  File "cupy/cuda/memory.pyx", line 664, in cupy.cuda.memory.SingleDeviceMemoryPool._alloc
  File "cupy/cuda/memory.pyx", line 394, in cupy.cuda.memory._malloc
  File "cupy/cuda/memory.pyx", line 395, in cupy.cuda.memory._malloc
  File "cupy/cuda/memory.pyx", line 67, in cupy.cuda.memory.Memory.__init__
  File "cupy/cuda/runtime.pyx", line 214, in cupy.cuda.runtime.malloc
  File "cupy/cuda/runtime.pyx", line 137, in cupy.cuda.runtime.check_status
cupy.cuda.runtime.CUDARuntimeError: cudaErrorMemoryAllocation: out of memory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "train_model.py", line 152, in <module>
    train_model()
  File "train_model.py", line 148, in train_model
    trainer.run()
  File "/opt/conda/envs/py3.6/lib/python3.6/site-packages/chainer/training/trainer.py", line 318, in run
    six.reraise(*sys.exc_info())
  File "/opt/conda/envs/py3.6/lib/python3.6/site-packages/six.py", line 693, in reraise
    raise value
  File "/opt/conda/envs/py3.6/lib/python3.6/site-packages/chainer/training/trainer.py", line 304, in run
    update()
  File "/opt/conda/envs/py3.6/lib/python3.6/site-packages/chainer/training/updaters/standard_updater.py", line 149, in update
    self.update_core()
  File "/opt/conda/envs/py3.6/lib/python3.6/site-packages/chainer/training/updaters/standard_updater.py", line 160, in update_core
    optimizer.update(loss_func, *in_arrays)
  File "/opt/conda/envs/py3.6/lib/python3.6/site-packages/chainer/optimizer.py", line 593, in update
    loss = lossfun(*args, **kwds)
  File "/workspace/src/models/unet.py", line 95, in __call__
    h = self.forward(x)
  File "/workspace/src/models/unet.py", line 61, in forward
    e2 = F.relu(self.bnc2(self.c2(e1)))
  File "/opt/conda/envs/py3.6/lib/python3.6/site-packages/chainer/functions/activation/relu.py", line 141, in relu
    y, = ReLU().apply((x,))
  File "/opt/conda/envs/py3.6/lib/python3.6/site-packages/chainer/function_node.py", line 257, in apply
    outputs = self.forward(in_data)
  File "/opt/conda/envs/py3.6/lib/python3.6/site-packages/chainer/function_node.py", line 364, in forward
    return self.forward_gpu(inputs)
  File "/opt/conda/envs/py3.6/lib/python3.6/site-packages/chainer/functions/activation/relu.py", line 39, in forward_gpu
    y = cuda.cupy.maximum(x[0], 0)
  File "/opt/conda/envs/py3.6/lib/python3.6/site-packages/cupy/core/fusion.py", line 701, in __call__
    return self._cupy_op(*args, **kwargs)
  File "cupy/core/elementwise.pxi", line 804, in cupy.core.core.ufunc.__call__
  File "cupy/core/elementwise.pxi", line 381, in cupy.core.core._get_out_args
  File "cupy/core/core.pyx", line 95, in cupy.core.core.ndarray.__init__
  File "cupy/cuda/memory.pyx", line 439, in cupy.cuda.memory.alloc
  File "cupy/cuda/memory.pyx", line 916, in cupy.cuda.memory.MemoryPool.malloc
  File "cupy/cuda/memory.pyx", line 937, in cupy.cuda.memory.MemoryPool.malloc
  File "cupy/cuda/memory.pyx", line 694, in cupy.cuda.memory.SingleDeviceMemoryPool.malloc
  File "cupy/cuda/memory.pyx", line 749, in cupy.cuda.memory.SingleDeviceMemoryPool._malloc
cupy.cuda.memory.OutOfMemoryError: out of memory to allocate 163840000 bytes (total 1673061376 bytes)

cupy.cuda.compiler.CompileException: nvrtc: error: invalid value for --gpu-architecture (-arch)

Dockerfile build - miniconda issue

The Dockerfile's miniconda curl returns an empty repo and fails because the current line doesn't have the 'allow redirect' tag. You may want to update the conda RUN command to include the -L tag.

From:
RUN curl -o ~/miniconda.sh

To:
RUN curl -L -o ~/miniconda.sh

Solution credit found here

aws dataset key changed

aws s3api get-object --bucket spacenet-dataset --key AOI_1_Rio/processedData/processedBuildingLabels.tar.gz --request-payer requester processedBuildingLabels.tar.gz

has become

aws s3api get-object --bucket spacenet-dataset --key AOIs/AOI_1_Rio/processedData/processedBuildingLabels.tar.gz --request-payer requester processedBuildingLabels.tar.gz

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.