SlideShare a Scribd company logo
Squeezing Machine Learning into
Serverless for Image Recognition
Chris Shenton
CTO at V! Studios
AWS Meetup Arlington VA
2018-03-15
Shamelessly Plagiarized (or, “Inspired By a Blog Post”)
● Script builds ML
libraries -- must be on
AWS Linux AMI
● Create ZIP and upload
to Lambda
● Manual creation of S3,
roles, permissions,
triggers
But I’m way too lazy for that!
https://blog.waya.ai/deploy-deep-machine-learning-in-production-the-pythonic-way-a17105f1540e
Automate Build of ML Tools in Lambda-Compatible Docker
● lambci docker image: compatible with AWS Lambda
● Makefile:
○ Avoid time-consuming builds of things we already have
○ Output binaries/libraries to Lambda function directory
PIL
Cython
numpy
torch
torchvision
Makefile
Docker
lambci/lambda
Makefile
(compile)
lambdavision/
mounted by Docker
lambdavision.py
compiled ML libraries
and binaries
Serverless Framework: Create Lambda, S3, Triggers, etc
serverless.yml defines:
● S3 for image uploads
● Trigger to fire Lambda on S3 upload
● Permissions allowing Lambda to read S3
● Lambda with Python function, ML libs
○ pulls pre-trained imagenet model with 1000 classes
S3
Lambda
lambdavision.py
imagenet1000.py
PIL/
cython/
numpy/
torch/
torchvision/
resnet18
pre-trained
neural network
upload trigger lambda
lambdavision.py pulls
trained model from network
on cold start
Logs
score=11.207
classid=335
human=fox
squirrel,
eastern fox
squirrel,
Sciurus niger
It’s a Start, But It’s Not AWS Rekognition
score=11.207 classid=335 human=fox squirrel, eastern fox squirrel, Sciurus niger
score=9.719 classid=515 human=cowboy hat, ten-gallon hat
score=13.650 classid=481 human=cassette
● Takes 3-8 seconds to classify a submitted image
● We hope to train a model on NASA-specific “stamps”
● Sensitive data my preclude use of AWS Rekognition
● Code: https://github.com/v-studios/LambdaVision
Want MOAR??
Makefile -- the heart of the build
DSTDIR = lambdavision
VENV = /tmp/venv3
PIP = $(VENV)/bin/pip
PYTHON = $(VENV)/bin/python
SITE_PACKAGES = $(VENV)/lib/python3.6/site-packages
all: $(DSTDIR)
docker run --rm -v "${PWD}":/var/task lambci/lambda:build-python3.6 make --debug
lambda_packages
Makefile -- Inception -- run inside Docker
lambda_packages: $(VENV) $(DSTDIR)/PIL $(DSTDIR)/Cython $(DSTDIR)/cython.py $(DSTDIR)/pyximport
$(DSTDIR)/numpy-1.13.3-py3.6-linux-x86_64.egg $(DSTDIR)/torch $(DSTDIR)/torchvision
$(VENV) $(PIP) $(PYTHON):
virtualenv $(VENV)
# Yaml is needed to build but not to run
yaml: $(PIP)
$(PIP) install pyyaml
PIL: $(PIP)
$(PIP) install Pillow
cp -r $(SITE_PACKAGES)/PIL $(DSTDIR)/
Cython cython.py pyximport: $(PIP)
$(PIP) install cython
cp -r $(SITE_PACKAGES)/Cython $(DSTDIR)/
cp -r $(SITE_PACKAGES)/cython.py $(DSTDIR)/
cp -r $(SITE_PACKAGES)/pyximport $(DSTDIR)/
serverless.yml -- Define Infrastructure, Triggers, etc
service: lambdavision
provider:
runtime: python3.6
memorySize: 2048 # Billed Duration: 8200 ms
timeout: 30
iamRoleStatements:
- Effect: Allow
Resource: arn:aws:s3:::chris-lambdavision/*
Action:
- s3:GetObject
functions:
lambdavision:
handler: lambdavision.s3upload
events:
- s3:
bucket: chris-lambdavision
event: s3:ObjectCreated:*
Live Demo?

More Related Content

What's hot (20)

PDF
What you see is what you get for AWS infrastructure
Anton Babenko
 
PDF
Terraform in deployment pipeline
Anton Babenko
 
PDF
Preview of Terraform 0.12 + modules.tf - Kiev HUG meetup
Anton Babenko
 
PDF
Terraform modules and (some of) best practices
Anton Babenko
 
PDF
Phoenix for Rails Devs
Diacode
 
PDF
Gotchas using Terraform in a secure delivery pipeline
Anton Babenko
 
PDF
CouchDB: A NoSQL database
Rubyc Slides
 
PPT
Take Flight - Using Fly with the Play Framework
Asher Glynn
 
PDF
Logging, monitoring and tracing in a serveless app
Mariano Calandra
 
PPTX
2020.02.15 DelEx - CI/CD in AWS Cloud
Peter Salnikov
 
PDF
Terraform modules and some of best-practices - March 2019
Anton Babenko
 
PPTX
Infrastructure as Code: Introduction to Terraform
Alexander Popov
 
PPTX
Schedule File Transfer from SFTP to S3 with AWS Lambda
Maximilian Jackson
 
PDF
EKS에서 Opentelemetry로 코드실행 모니터링하기 - 신재현 (인덴트코퍼레이션) :: AWS Community Day Online...
AWSKRUG - AWS한국사용자모임
 
PDF
전 세계 팬들이 모일 수 있는 플랫폼 만들기 - 강진우 (beNX) :: AWS Community Day 2020
AWSKRUG - AWS한국사용자모임
 
PPTX
Webinar AWS für Unternehmen Teil 3: Disaster Recovery
AWS Germany
 
PDF
Packer + Ansible을 이용한 AMI 생성 및 AutoScaling Group 이미지 교체 이야기
창훈 정
 
PDF
Presentation kyushu-2018
masahitojp
 
PDF
Terraform @Base
Miroslaw Nagas
 
PDF
Terraform AWS modules and some best-practices - May 2019
Anton Babenko
 
What you see is what you get for AWS infrastructure
Anton Babenko
 
Terraform in deployment pipeline
Anton Babenko
 
Preview of Terraform 0.12 + modules.tf - Kiev HUG meetup
Anton Babenko
 
Terraform modules and (some of) best practices
Anton Babenko
 
Phoenix for Rails Devs
Diacode
 
Gotchas using Terraform in a secure delivery pipeline
Anton Babenko
 
CouchDB: A NoSQL database
Rubyc Slides
 
Take Flight - Using Fly with the Play Framework
Asher Glynn
 
Logging, monitoring and tracing in a serveless app
Mariano Calandra
 
2020.02.15 DelEx - CI/CD in AWS Cloud
Peter Salnikov
 
Terraform modules and some of best-practices - March 2019
Anton Babenko
 
Infrastructure as Code: Introduction to Terraform
Alexander Popov
 
Schedule File Transfer from SFTP to S3 with AWS Lambda
Maximilian Jackson
 
EKS에서 Opentelemetry로 코드실행 모니터링하기 - 신재현 (인덴트코퍼레이션) :: AWS Community Day Online...
AWSKRUG - AWS한국사용자모임
 
전 세계 팬들이 모일 수 있는 플랫폼 만들기 - 강진우 (beNX) :: AWS Community Day 2020
AWSKRUG - AWS한국사용자모임
 
Webinar AWS für Unternehmen Teil 3: Disaster Recovery
AWS Germany
 
Packer + Ansible을 이용한 AMI 생성 및 AutoScaling Group 이미지 교체 이야기
창훈 정
 
Presentation kyushu-2018
masahitojp
 
Terraform @Base
Miroslaw Nagas
 
Terraform AWS modules and some best-practices - May 2019
Anton Babenko
 

Similar to Squeezing Machine Learning into Serverless for Image Recognition - AWS Meetup Arlington VA (20)

PDF
Serverless Deep Learning
Alexey Grigorev
 
PDF
AWS Lambda를 통한 Tensorflow 및 Keras 기반 추론 모델 서비스하기 :: 이준범 :: AWS Summit Seoul 2018
Amazon Web Services Korea
 
PDF
maXbox Starter87
Max Kleiner
 
PDF
WIA 2019 - Unearth the Journey of Implementing Vision Based Deep Learning Sol...
Women in Analytics Conference
 
PDF
Deep Learning with Tensorflow and Apache MXNet on AWS (April 2019)
Julien SIMON
 
PDF
Get started with Machine Learning and Computer Vision Using AWS DeepLens (Feb...
Julien SIMON
 
PPTX
Deep Learning on Amazon Sagemaker (July 2019)
Julien SIMON
 
PDF
IRJET- Python Libraries and Packages for Deep Learning-A Survey
IRJET Journal
 
PPTX
Ai use cases
Sparsh Agarwal
 
PPTX
python_libraries_for_artificial_intelligence.pptx
salehaalsaleh602
 
PPTX
Machine Learning Toolssssssssssssss.pptx
salehaalsaleh602
 
PPTX
Demystifying-AI-Frameworks-TensorFlow-PyTorch-JAX-and-More (1).pptx
Anant Garg
 
PDF
Computer vision
Dmitry Ryabokon
 
PDF
Machine Learning for Web Developers
Riza Fahmi
 
PPTX
Serving deep learning models in a serverless platform (IC2E 2018)
alekn
 
PPTX
Spark application on ec2 cluster
Chao-Hsuan Shen
 
PPTX
Leonid Kuligin "Training ML models with Cloud"
Lviv Startup Club
 
PDF
Reproducible AI Using PyTorch and MLflow
Databricks
 
PPTX
Ml goes fruitful
Preeti Negi
 
PDF
Deep Representation: Building a Semantic Image Search Engine
C4Media
 
Serverless Deep Learning
Alexey Grigorev
 
AWS Lambda를 통한 Tensorflow 및 Keras 기반 추론 모델 서비스하기 :: 이준범 :: AWS Summit Seoul 2018
Amazon Web Services Korea
 
maXbox Starter87
Max Kleiner
 
WIA 2019 - Unearth the Journey of Implementing Vision Based Deep Learning Sol...
Women in Analytics Conference
 
Deep Learning with Tensorflow and Apache MXNet on AWS (April 2019)
Julien SIMON
 
Get started with Machine Learning and Computer Vision Using AWS DeepLens (Feb...
Julien SIMON
 
Deep Learning on Amazon Sagemaker (July 2019)
Julien SIMON
 
IRJET- Python Libraries and Packages for Deep Learning-A Survey
IRJET Journal
 
Ai use cases
Sparsh Agarwal
 
python_libraries_for_artificial_intelligence.pptx
salehaalsaleh602
 
Machine Learning Toolssssssssssssss.pptx
salehaalsaleh602
 
Demystifying-AI-Frameworks-TensorFlow-PyTorch-JAX-and-More (1).pptx
Anant Garg
 
Computer vision
Dmitry Ryabokon
 
Machine Learning for Web Developers
Riza Fahmi
 
Serving deep learning models in a serverless platform (IC2E 2018)
alekn
 
Spark application on ec2 cluster
Chao-Hsuan Shen
 
Leonid Kuligin "Training ML models with Cloud"
Lviv Startup Club
 
Reproducible AI Using PyTorch and MLflow
Databricks
 
Ml goes fruitful
Preeti Negi
 
Deep Representation: Building a Semantic Image Search Engine
C4Media
 
Ad

More from Chris Shenton (11)

PDF
Orchestrating complex workflows with aws step functions
Chris Shenton
 
PDF
Automating EVA Workflows with AWS Step Functions
Chris Shenton
 
PPTX
Creating Serverless apps for NASA in GovCloud
Chris Shenton
 
PDF
Scaffolding for Serverless: lightning talk for AWS Arlington Meetup
Chris Shenton
 
PDF
Serverless Optical Character Recognition in support of Astronaut Safety AWS M...
Chris Shenton
 
PDF
Serverless OCR for NASA EVA: AWS Meetup DC 2017-12-12
Chris Shenton
 
PDF
Deploying Serverless Cloud Optical Character Recognition in Support of NASA A...
Chris Shenton
 
PDF
Second Skin: Real-Time Retheming a Legacy Web Application with Diazo in the C...
Chris Shenton
 
PDF
PloneConf2017: serverless python for astronaut safety
Chris Shenton
 
PDF
[AWS DC Meetup] Not Your Father’s WebApp: The Cloud-Native Architecture of im...
Chris Shenton
 
PDF
Not Your Father’s Web App: The Cloud-Native Architecture of images.nasa.gov
Chris Shenton
 
Orchestrating complex workflows with aws step functions
Chris Shenton
 
Automating EVA Workflows with AWS Step Functions
Chris Shenton
 
Creating Serverless apps for NASA in GovCloud
Chris Shenton
 
Scaffolding for Serverless: lightning talk for AWS Arlington Meetup
Chris Shenton
 
Serverless Optical Character Recognition in support of Astronaut Safety AWS M...
Chris Shenton
 
Serverless OCR for NASA EVA: AWS Meetup DC 2017-12-12
Chris Shenton
 
Deploying Serverless Cloud Optical Character Recognition in Support of NASA A...
Chris Shenton
 
Second Skin: Real-Time Retheming a Legacy Web Application with Diazo in the C...
Chris Shenton
 
PloneConf2017: serverless python for astronaut safety
Chris Shenton
 
[AWS DC Meetup] Not Your Father’s WebApp: The Cloud-Native Architecture of im...
Chris Shenton
 
Not Your Father’s Web App: The Cloud-Native Architecture of images.nasa.gov
Chris Shenton
 
Ad

Recently uploaded (20)

PPTX
PM200.pptxghjgfhjghjghjghjghjghjghjghjghjghj
breadpaan921
 
PPTX
本科硕士学历佛罗里达大学毕业证(UF毕业证书)24小时在线办理
Taqyea
 
PDF
Azure_DevOps introduction for CI/CD and Agile
henrymails
 
PPT
introductio to computers by arthur janry
RamananMuthukrishnan
 
PPTX
一比一原版(LaTech毕业证)路易斯安那理工大学毕业证如何办理
Taqyea
 
PPTX
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
PPTX
internet básico presentacion es una red global
70965857
 
PDF
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
PPTX
PE introd.pptxfrgfgfdgfdgfgrtretrt44t444
nepmithibai2024
 
PPT
Computer Securityyyyyyyy - Chapter 1.ppt
SolomonSB
 
PPTX
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
PPTX
Research Design - Report on seminar in thesis writing. PPTX
arvielobos1
 
PPTX
INTEGRATION OF ICT IN LEARNING AND INCORPORATIING TECHNOLOGY
kvshardwork1235
 
PPT
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
PPTX
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
PPTX
原版西班牙莱昂大学毕业证(León毕业证书)如何办理
Taqyea
 
PPTX
Optimization_Techniques_ML_Presentation.pptx
farispalayi
 
PDF
DevOps Design for different deployment options
henrymails
 
PPTX
一比一原版(SUNY-Albany毕业证)纽约州立大学奥尔巴尼分校毕业证如何办理
Taqyea
 
PPTX
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 
PM200.pptxghjgfhjghjghjghjghjghjghjghjghjghj
breadpaan921
 
本科硕士学历佛罗里达大学毕业证(UF毕业证书)24小时在线办理
Taqyea
 
Azure_DevOps introduction for CI/CD and Agile
henrymails
 
introductio to computers by arthur janry
RamananMuthukrishnan
 
一比一原版(LaTech毕业证)路易斯安那理工大学毕业证如何办理
Taqyea
 
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
internet básico presentacion es una red global
70965857
 
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
PE introd.pptxfrgfgfdgfdgfgrtretrt44t444
nepmithibai2024
 
Computer Securityyyyyyyy - Chapter 1.ppt
SolomonSB
 
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
Research Design - Report on seminar in thesis writing. PPTX
arvielobos1
 
INTEGRATION OF ICT IN LEARNING AND INCORPORATIING TECHNOLOGY
kvshardwork1235
 
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
原版西班牙莱昂大学毕业证(León毕业证书)如何办理
Taqyea
 
Optimization_Techniques_ML_Presentation.pptx
farispalayi
 
DevOps Design for different deployment options
henrymails
 
一比一原版(SUNY-Albany毕业证)纽约州立大学奥尔巴尼分校毕业证如何办理
Taqyea
 
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 

Squeezing Machine Learning into Serverless for Image Recognition - AWS Meetup Arlington VA

  • 1. Squeezing Machine Learning into Serverless for Image Recognition Chris Shenton CTO at V! Studios AWS Meetup Arlington VA 2018-03-15
  • 2. Shamelessly Plagiarized (or, “Inspired By a Blog Post”) ● Script builds ML libraries -- must be on AWS Linux AMI ● Create ZIP and upload to Lambda ● Manual creation of S3, roles, permissions, triggers But I’m way too lazy for that! https://blog.waya.ai/deploy-deep-machine-learning-in-production-the-pythonic-way-a17105f1540e
  • 3. Automate Build of ML Tools in Lambda-Compatible Docker ● lambci docker image: compatible with AWS Lambda ● Makefile: ○ Avoid time-consuming builds of things we already have ○ Output binaries/libraries to Lambda function directory PIL Cython numpy torch torchvision Makefile Docker lambci/lambda Makefile (compile) lambdavision/ mounted by Docker lambdavision.py compiled ML libraries and binaries
  • 4. Serverless Framework: Create Lambda, S3, Triggers, etc serverless.yml defines: ● S3 for image uploads ● Trigger to fire Lambda on S3 upload ● Permissions allowing Lambda to read S3 ● Lambda with Python function, ML libs ○ pulls pre-trained imagenet model with 1000 classes S3 Lambda lambdavision.py imagenet1000.py PIL/ cython/ numpy/ torch/ torchvision/ resnet18 pre-trained neural network upload trigger lambda lambdavision.py pulls trained model from network on cold start Logs score=11.207 classid=335 human=fox squirrel, eastern fox squirrel, Sciurus niger
  • 5. It’s a Start, But It’s Not AWS Rekognition score=11.207 classid=335 human=fox squirrel, eastern fox squirrel, Sciurus niger score=9.719 classid=515 human=cowboy hat, ten-gallon hat score=13.650 classid=481 human=cassette ● Takes 3-8 seconds to classify a submitted image ● We hope to train a model on NASA-specific “stamps” ● Sensitive data my preclude use of AWS Rekognition ● Code: https://github.com/v-studios/LambdaVision
  • 7. Makefile -- the heart of the build DSTDIR = lambdavision VENV = /tmp/venv3 PIP = $(VENV)/bin/pip PYTHON = $(VENV)/bin/python SITE_PACKAGES = $(VENV)/lib/python3.6/site-packages all: $(DSTDIR) docker run --rm -v "${PWD}":/var/task lambci/lambda:build-python3.6 make --debug lambda_packages
  • 8. Makefile -- Inception -- run inside Docker lambda_packages: $(VENV) $(DSTDIR)/PIL $(DSTDIR)/Cython $(DSTDIR)/cython.py $(DSTDIR)/pyximport $(DSTDIR)/numpy-1.13.3-py3.6-linux-x86_64.egg $(DSTDIR)/torch $(DSTDIR)/torchvision $(VENV) $(PIP) $(PYTHON): virtualenv $(VENV) # Yaml is needed to build but not to run yaml: $(PIP) $(PIP) install pyyaml PIL: $(PIP) $(PIP) install Pillow cp -r $(SITE_PACKAGES)/PIL $(DSTDIR)/ Cython cython.py pyximport: $(PIP) $(PIP) install cython cp -r $(SITE_PACKAGES)/Cython $(DSTDIR)/ cp -r $(SITE_PACKAGES)/cython.py $(DSTDIR)/ cp -r $(SITE_PACKAGES)/pyximport $(DSTDIR)/
  • 9. serverless.yml -- Define Infrastructure, Triggers, etc service: lambdavision provider: runtime: python3.6 memorySize: 2048 # Billed Duration: 8200 ms timeout: 30 iamRoleStatements: - Effect: Allow Resource: arn:aws:s3:::chris-lambdavision/* Action: - s3:GetObject functions: lambdavision: handler: lambdavision.s3upload events: - s3: bucket: chris-lambdavision event: s3:ObjectCreated:*