Predicting Employee Churn: A Data-Driven Approach Project Presentation
Deploying computer vision model as api using aws lambda and api gateway
1. 1 | 5 0
Deploying Computer
Vision Model as an API
using
AWS Lambda & API
Gateway
2. 2 | 5 0
Topic
Deploying Computer Vision Model as an
API using AWS Lambda & API Gateway
2 | 5 0
Speaker
SHIRISH GUPTA
HEAD – DATA SCIENCE & PARTNERSHIPS AT
LOAN2GROW
3. 3 | 5 0
“Awesome. You have created a great machine learning algorithm. Am impressed by the
accuracy and love the technique. How can we implement it in our system?” Is this
something you have heard multiple times during a client or business meeting but never been able to
truthfully answer it? Worry not, this is probably faced by 90% (to be conservative) of fellow data
scientists. And AWS has many solutions for it. One of them being —
“AWS lambda function integrated with Amazon API gateway”
4. 4 | 5 04 | 5 0
• What are AWS Lambda & Amazon API ?
• Overview of our approach
• Hands-On Training
• Login to AWS Lambda
• Understand & create a lambda_function
• Download & define layers(aka dependencies)
• Configure Amazon API gateway
• Deploy the API and test it using Postman or
Curl
Agenda for Today
5. 5 | 5 0
AWS Lambda
AWS Lambda is an event-driven, serverless computing
platform provided by Amazon as a part of Amazon Web
Services. It is a computing service that runs code in response
to events and automatically manages the computing
resources required by that code. The concept
of serverless computing refers to the idea that you don’t
need to maintain your own servers to run these functions.
Which means you can just upload your codes (Python,
Node.js, Go, .NET, Java, Ruby) and Lambda will manage other
things like runtime, scaling, load balancing, etc.
Amazon API
Amazon API Gateway is a fully managed service that makes it
easy for developers to create, publish, maintain, monitor, and
secure APIs at any scale. APIs act as the front door for
applications to access data, business logic, or functionality
from your backend services. Using API Gateway, we can
create RESTful APIs and WebSocket APIs that enable real-
time two-way communication applications. API Gateway
supports containerized and serverless workloads, as well as
web applications.
6. 6 | 5 0
Overview of our approa
• Write a simple OCR code using OpenCV +
Tesseract algorithm in Python language
• Configure the algorithm in AWS Lambda
• Deploy it as an API on Amazon API gateway
6 | 5 0
OCR or Optical character recognition or optical character reader is the electronic
or mechanical conversion of images of typed, handwritten or printed text into
machine-encoded text, whether from a scanned document, a photo of a
document, a scene-photo or from subtitle text superimposed on an image.
7. 7 | 5 0
OCR or Optical
Character
RecognitionThe electronic or mechanical conversion of images of typed, handwritten
or printed text into machine-encoded text, whether from a scanned
document, a photo of a document, a scene-photo or from subtitle text
superimposed on an image.
8. 8 | 5 0
Important Notes
• The workshop will require you to upload few python
libraries as zip files. You can download them from the
following link
• https://implayers.s3.amazonaws.com/Pillow.zip
• https://implayers.s3.amazonaws.com/tesseract-
layer.zip
• https://implayers.s3.amazonaws.com/pytesseract%3D
%3D0.3.3.zip
• Python codes & sample photos to test
https://drive.google.com/drive/folders/1jVXiI1QzOwaqW
ggY-kDGE4WTtsd2mbX5?usp=sharing
• Please refer to the following blog for other queries
https://towardsdatascience.com/aws-lambda-amazon-
api-gateway-not-as-daunting-as-they-sound-part-1-
d77b92f53626
Pre-requisites
• Python development experience
• Basics on Computer Vision and OCR
• Activated AWS account (You might need to enter your
credit card details to activate the account. Don’t worry
you won’t be charged for the same)
10. 1 0 | 5 0
Lambda_Function
The code (here: python) that runs on AWS Lambda is uploaded
as a Lambda function
• Event represents the event or trigger that caused the
invocation of the lambda. It’s like the input to the function.
eg: Lambda function can be triggered by an upload to S3 or
by passing some input/data via API Gateway.
• Context Provides information about the invocation,
and execution environment of your lambda. Can be used to
check the memory allocation or to retrieve the number of
milliseconds left before the execution times out. It’s like
extra or meta info provided by AWS to understand
function’s runtime.
Layers
• Although we have created the lambda function, it won’t execute
or run right away. The reason is that we haven’t downloaded or
installed the necessary libraries(dependencies) required for the
code to run.
• Like in a normal environment, we need to pip or conda install the
libraries, we will need to do the same thing for AWS lambda. We
do that by adding layers to our AWS lambda
• A ZIP archive that contains libraries, a custom runtime, or other
dependencies. With layers, you can use libraries in your function
without needing to include them in your deployment package