Skip to content

This is an implementation of the paper Only a Matter of Style: Age Transformation Using a Style-Based Regression Model by Y. Alauf et al. The model inference is performed via a serverless implementation on AWS Lambda.

PatrickStaehli/age_transformator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Age Transformator: Deploy a Serverless Machine Learning App on AWS Lambda

This is an implementation of the paper Only a Matter of Style: Age Transformation Using a Style-Based Regression Model by Y. Alauf et al. The model inference is performed via a serverless implementation on AWS Lambda.

App architecture

After training and testing a machine learning model, the next step is to deploy it to make it available to the world. One way to do this is to use a serverless architecture (e.g using Lambda functions), where you don't have to provision servers yourself.

The architecture of the app is as follows:

The left side shows the front-end interface that is based on a Bootstrap template and hosted on a Linux system (Linode) using uWSGI and Nginx. The right side visualized the back-end, which consists of an API Gateway that communicates with the front-end via HTTP request, and the Lambda function that performs the age transformation.

Backend - Deployment of the Age Transformator

The Age Transformation Model

The model that was used in this project was developed and published by Y. Alaluf et al.. I used the pre-trained model from the original implementation. Furthermore, the code borrows heavily from the original implementation as well as from pixel2style2pixel.

Using Amazon ECR with the AWS CLI

The following steps show how to push a container image to a private Amazon ECR repository for the first time using the Docker CLI and the AWS CLI. I developed and deployed this app from my personal computer through Windows Subsystem for Linux.

Prerequisites

You need to have an AWS account. As a new user, you will get a free tier offer that is available for 12 months following your AWS sign-up date. Although the free tier includes 400,000 seconds of computing time per month for AWS Lambda, which is more than enough for testing purposes, the free tier usage limit for the Amazon EC2 Container Registry (ECR) is only 500BM-month. Since the pre-trained model is larger (about 5GB), this will generate costs of about 0.75$ per month.

Follow these steps to sign up for AWS and to install the CLI locally.

  • Sign up for AWS and create an IAM user. This official documentation will walk you through the necessary steps.
  • Install the AWS Command Line Interface (CLI). Official Documentation.
  • Create an Acces key for CLI via AWS console -> Security credentials. Then, run the AWS configuration command and enter the credentials
$ aws configure
AWS Access Key ID [None]: < Access Key ID >
AWS Secret Access Key [None]: < Secret Access Key >
Default region name [None]: eu-central-1
Default output format [None]: json

Authenticate to your default registry

In order to push and pull images with Amazon ECR, authentication of the Docker CLI to the default registry is needed:

aws ecr get-login-password --region <REGION> | docker login --username AWS --password-stdin <AWS_ACCOUNT_ID>.dkr.ecr.<REGION>.amazonaws.com

Replace < REGION > with your region (e.g eu-central-1) and < AWS_ACCOUNT_ID > with your IAM's account id (format is 123456789101).

Note: If you experience the error Error saving credentials: error storing credentials - err: exit status 1, you may have to delete "credsStore": "osxkeychain" in the ~/.docker/config.json file.

Create a Repository

aws ecr create-repository \
    --repository-name age-transformator \
    --image-scanning-configuration scanOnPush=true \
    --region eu-central-1

Download the pre-trained models

mkdir pretrained_models
pip install gdown
gdown "https://drive.google.com/u/0/uc?id=1XyumF6_fdAxFmxpFcmPf-q84LU_22EMC&export=download" -O pretrained_models/sam_ffhq_aging.pt
wget "https://github.com/italojs/facial-landmarks-recognition/raw/master/shape_predictor_68_face_landmarks.dat"

Create a Docker image

To create the Docker image, execute the following command inside the Backend folder

docker build -t age-transformator .

Tag and push the docker image

docker tag age-transformator:latest  <AWS_ACCOUNT_ID>.dkr.ecr.<REGION>.amazonaws.com/age-transformator:latest

docker push <AWS_ACCOUNT_ID>.dkr.ecr.<REGION>.amazonaws.com/age-transformator:latest

Credits

This code borrows heavily from the original implementation

About

This is an implementation of the paper Only a Matter of Style: Age Transformation Using a Style-Based Regression Model by Y. Alauf et al. The model inference is performed via a serverless implementation on AWS Lambda.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published