This repo contains source code and supporting files for the Serverless AI workshop.
It included the following folders:
/SAM/digit_classifier
- a serverless application for classifying handwritten digits using a machine learning model in PyTorch/SAM/clip_crop
- a serverless application for searching and cropping objects in a image using YoloV5 and OpenAI CLIP/Sagemaker/serverless_inference.ipynb
- jupyter notebook to deploy Huggingface sentiment classifier as Sagemaker serverless endpoint
- AWS account - Create AWS account
- AWS CLI - Install the AWS CLI
- SAM CLI - Install the SAM CLI
- Docker - Install Docker community edition
SAM is Serverless Application Model to deploy serverless applications in AWS
In this workshop, we will deploy two applications. One is a simple mnist digit classifier and second one is little advanced that use Open AI CLIP and YoloV5 to search and crop objects in a image.
- Download SAM https://github.com/aws/aws-sam-cli/releases/latest/download/AWS_SAM_CLI_64_PY3.msi
- Install SAM
- Verify installation - Open cmd terminal and run
sam —version
For more details : https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install-windows.html
-
git clone --recursive https://github.com/bismillahkani/AWS-Serverless-AI.git
-
Create IAM user with following permissions,
- IAMFullAccess
- AWSLambda_FullAccess
- AmazonAPIGatewayAdministrator
- AWSCloudFormationFullAccess
- AmazonEC2ContainerRegistryFullAccess
- AmazonS3FullAccess
- CloudWatchLogsFullAccess
- AmazonEventBridgeFullAccess
-
IAM User access key - Create access keys
-
open terminal and run
aws configure
. Enter Access key and Secret key. -
cd ~/SAM/digit_classifier
-
open terminal and run
sam build
-
run
sam deploy —guided
and follow the instructions as shown in terminal -
Once deployed, copy the API url from Outputs and test it in POSTMAN`
-
For clip_crop application, change directory
cd ~/SAM/clip_crop
-
Download the model weights for CLIP model from https://openaipublic.azureedge.net/clip/models/40d365715913c9da98579312b702a82c18be219cc2a73407c4526f58eba950af/ViT-B-32.pt and copy the weights to
/SAM/clip_crop/app/weights
-
run
sam build
andsam deploy --guided
-
Once deployed, copy the API url of clip_crop from Outputs and update the
/SAM/clip_crop/app/testapi.py
-
Run
testapi.py
- Create a notebook instance in Sagemaker
- Upload the serverless_inference.ipynb notebook
- Run cell, deploy serverless endpoint and do inference
https://sam-bkvgvd906y7.streamlit.app/
I have not investigated the free tier usage for this workshop. Hence cannot guarantee that you will not be charged. You can refer the below AWS pricing details,
Lambda pricing - https://aws.amazon.com/lambda/pricing/
Sagemaker pricing - https://aws.amazon.com/sagemaker/pricing/
ECR pricing - https://aws.amazon.com/ecr/pricing/
API gateway pricing - https://aws.amazon.com/api-gateway/pricing/
Don’t forget to delete all the resources you created for this workshop. Otherwise you will be charged.