Giter VIP home page Giter VIP logo

neural-net-rest-api-aws's Introduction

Overview

Image classification using a REST API and PyTorch/NumPy/PIL libraries. Includes AWS deployment utilizing CloudFormation, API Gateway, Lambda, and S3.

Contributors

Required Libs and Environment

  • Python 3.6
  • PyTorch
  • NumPy
  • PIL

AWS Services

  • API Gateway
  • Lambda
  • S3
  • CloudFormation
  • CloudWatch
  • IAM

AWS Deployment with CloudFormation

Inside the "AWS Deployment" folder you'll find the CloudFormation template, Lambda Function source code, custom Lambda Layers (NumPy, PIL), and the required S3 bucket contents.
  1. Upload the files in Bucket Contents to your S3 bucket. This includes the Lambda function code and some pre-trained FCNN and CNN models. These models were lightly trained with a batch size = 32 and epochs = 100, feel free to generate more robust models using the local run method described at the bottom of the page.

  2. Create a new stack in CloudFormation and upload template.json.

  3. Specify a new IAM username, your bucket name, and Lambda Layer ARNs for PyTorch, NumPy, and PIL.

    PyTorch was a public layer that I found and NumPy / PIL are custom ones I compiled myself. I provided the zips in the Lambda Layers directory so you can upload them yourselves if needed.

  4. Once the deployment is finished you can try it out by issuing a POST request to your new API Gateway endpoint titled "Get_Scene API".

    I recommend using Postman with the configuration described below. Include the mode - either "FCNN" (Fully Connected Neural Network) or "CNN" (Convolutional Neural Network), the source model bucket name, and the sample image as a Base64 encoded string.

POST Message Body

    {
      "mode": String,
      "imageBase64": String,
      "bucketName": String
    }

POST Authorization

	Provide the Access Key and Secret Key associated to the username you specified in step 3.

Running Locally

Train Network and Classify Test Samples

The src directory contains main.py which is used for training and testing FCNN/CNN models.

python main.py <train_dir> <test_dir> <mode>

The mode can be either "FCNN" (Fully Connected Neural Network) or "CNN" (Convolutional Neural Network). The test and train directories must contain a subdirectory for each class. See the example dataset by extracting dataset.zip (split across dataset.zip.001 and dataset.zip.002).

After the run is complete, the model will be evaluated and metrics displayed to the end user. A file will be generated in the same directory as main.py titled either "model_FCNN" or "model_CNN" depending on the type launched. This model can be used locally by setting "LOAD_MODEL" to true in main.py. The models can also be uploaded into your S3 bucket for the AWS deployment described above.

neural-net-rest-api-aws's People

Contributors

andrewaltimit avatar

Watchers

 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.