Code Monkey home page Code Monkey logo

keras-semantic-segmentation's Introduction

keras-semantic-segmentation

This repo contains code for doing semantic segmentation using Keras/Tensorflow, with a focus on aerial imagery. Here's a sample segmentation using a U-Net model we trained on RGBIR+D data from the ISPRS Potsdam 2D dataset.

Example segmentation

Usage

Requirements

  • Vagrant 1.8+
  • VirtualBox 4.3+
  • Pip 8.1+

Scripts

Name Description
cipublish Publish docker image to ECR
clean Remove build outputs inside virtual machine
infra Execute Terraform subcommands
lint Run flake8 on source code
run Run container locally or remotely
setup Bring up the virtual machine and install dependent software on it
update Install dependent software inside virtual machine
upload_code Upload code to EC2 instance for rapid debugging

Initial Setup

From within the project root, execute the following commands.

$ ./scripts/setup
$ vagrant ssh

You will be prompted to enter the OpenTreeID AWS credentials, along with a default region. These credentials will be used to authenticate calls to the AWS API when using the AWS CLI and Terraform.

Running locally on CPUs

To run an experiment locally, invoke

vagrant ssh
vagrant@otid:/vagrant$ ./scripts/update --cpu
vagrant@otid:/vagrant$ ./scripts/run --cpu
root@230fb62d8ecd:/opt/src# python -m model_training.run experiments/2_28_17/conv_logistic_test.json setup train eval

⚠️️ See model_training/README.md for more information on preparing data and running experiments.

Running remotely on AWS EC2 GPUs

Support for Amazon EC2 GPU instances is provided through a combination of the AWS CLI and Terraform. The AWS CLI is used to produce a local AWS profile with valid credentials, and Terraform is used to bring up the appropriate EC2 instances using spot pricing.

Spot Fleet

Once an AWS profile exists, use the infra script to interact with Amazon EC2 Spot Fleet API, which will request the lowest priced P2 GPU instance across all availability zones. The following command will start 1 instance and print their public DNS names. More than 1 instance can be specified if needed.

vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ./scripts/infra start 1

Afterwards, navigate to the spot request section of the EC2 console to monitor the request's progress. Once fulfilled, a running instance will visible in the instances section.

After initializing, the instance should have nvidia-docker, the GPU-enabled Docker image for this repo, and this repo and the datasets in the home directory.

Running Models On A GPU Instance

After starting an instance, ssh into it with

ssh-add ~/.aws/open-tree-id.pem
ssh ubuntu@<public dns>

Then you can train a model with

cd keras-semantic-segmentation
./scripts/run --gpu
root@230fb62d8ecd:/opt/src# python -m model_training.run experiments/2_28_17/conv_logistic_test.json setup train eval

When running on EC2, the results will be saved to the otid-data S3 bucket after each epoch and the evaluation. If a run is terminated for any reason and you would like to resume it, simply run the above command with the same options file, and it should pick up where it left off.

⚠️️ When done with all the instances, you should shut them down with

./scripts/infra destroy

Publishing the Docker container to ECR

To enable fast bootup, we publish the latest Docker image to ECR and then download it when initializing the EC2 instance. To build and publish the container, run ./scripts/cipublish.

keras-semantic-segmentation's People

Contributors

lewfish avatar

Watchers

dvr avatar  avatar

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.