Skip to content
This repository was archived by the owner on Jan 21, 2023. It is now read-only.
/ nst-tele-bot Public archive

AWS-based solution of Neural Style Transfer

License

Notifications You must be signed in to change notification settings

s0rl0v/nst-tele-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description

AWS-based solution of Neural Style Transfer app.

Made with Angular Made with Bootstrap

How it works

NST is quite heavy on computation resources, thus GPU enabled instances of EC2 - P series - is used. Since running such instance on permanent basis is quite a luxury even in production, cost-effective AWS batchis selected to run style transfer on demand.

AWS Labda based python-telegram-bot function

This function uploads received images to s3 bucket and handles s3 events on new images in s3 bucket - depending on the name of an image (content/generated) it invokes AWS batch (content) or sends generated image (generated).

AWS Batch - Tensorflow docker image based on AWS DL Container images

Custom image runs the bootstrap script entrypoint.py which downloads tensorflow implementation of NST, fetches style and content images from s3 bucket, runs interference, uploads generated image and terminates container

S3

CloudFormation template creates a temporary bucket with the stack which is used to store intermediate images and trigger notification event to drive Lambda function.

How to build and deploy

Prerequisites

  • AWS account
  • awscli
  • sam

Steps

  1. Clone this repo and cd to it;
  2. Build docker image and push it to ECR:
cd docker
docker build -t nst:latest .
  1. Replace JobDefinition/Properties/ContainerProperties/Image in cloudformation/template.yaml with built image;
  2. Paste your values into variables:
export BUCKET_NAME=name
export TELEGRAM_BOT_API_KEY=key
  1. Build lambda package:
# sam build --use-container -t cloudformation\template.yaml -s .
  1. Upload the package to s3:
# sam package --s3-bucket $BUCKET_NAME --output-template-file package.yaml
  1. Deploy the stack to AWS:
# aws cloudformation deploy --template-file package.yaml --stack-name nst --capabilities CAPABILITY_IAM --force-upload --parameter-overrides "ApiKey=TELEGRAM_BOT_API_KEY" "BucketName=$BUCKET_NAME"
  1. Download VGG19 model to $BUCKET_NAME S3 bucket along with style.jpg image - this image style will be used in image processing;
  2. Post an image to telegram bot and wait until app will process it.

Reference

deeplearning.ai for implementation of NST model.

The Neural Style Transfer algorithm was due to Gatys et al. (2015). Harish Narayanan and Github user "log0" also have highly readable write-ups from which we drew inspiration. The pre-trained network used in this implementation is a VGG network, which is due to Simonyan and Zisserman (2015). Pre-trained weights were from the work of the MathConvNet team.

About

AWS-based solution of Neural Style Transfer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published