0% found this document useful (0 votes)
289 views3 pages

Steps To Create and Deploy Our YOLO Model On AWS Sagemaker

1. Deploy the trained YOLO model to an Amazon SageMaker endpoint to serve predictions. 2. Create an AWS Lambda function with permissions to access the SageMaker endpoint. The function will receive images, send them to SageMaker for inference, and return the results. 3. Create an API Gateway to integrate the Lambda function and deploy it, generating a public URL to share with API users.

Uploaded by

Anupam Poddar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
289 views3 pages

Steps To Create and Deploy Our YOLO Model On AWS Sagemaker

1. Deploy the trained YOLO model to an Amazon SageMaker endpoint to serve predictions. 2. Create an AWS Lambda function with permissions to access the SageMaker endpoint. The function will receive images, send them to SageMaker for inference, and return the results. 3. Create an API Gateway to integrate the Lambda function and deploy it, generating a public URL to share with API users.

Uploaded by

Anupam Poddar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Steps to create and Deploy our YOLO model:

1. deploy the YOLO model on Amazon SageMaker:


● Deploy the model as an endpoint: Create an Amazon SageMaker endpoint to host the
trained model, which will serve as the backend for the API.

2. Create an AWS Lambda function:


● Create a new Lambda function in the AWS Management Console or using the AWS CLI.
● Choose the Python 3.8/9 runtime and create a new execution role with permissions to
access the SageMaker endpoint and the API Gateway service.
● Add the boto3 library to the function dependencies, which allows you to call SageMaker
APIs from the Lambda function.
● Write the function code that will receive the image from the API caller, send it to the
SageMaker endpoint for inference, and return the inference results to the caller, if in case
we receive id of the image we will write it to S3, we do the following:

steps to read from and write to an S3 bucket in AWS Lambda:

1.Create an S3 client

2.Read from an S3 bucket with the help of id

3.Write to an S3 bucket:

Here is an example:

Lambda function code that receives the image as a base64-encoded string, decodes it, and

sends it to the SageMaker endpoint for inference:

import base64
import boto3

import json

# Initialize the SageMaker runtime client

sm_client = boto3.client('runtime.sagemaker')

def lambda_handler(event, context):

# Get the image data from the API Gateway event

body = json.loads(event['body'])

image_data = base64.b64decode(body['image'])

# Call the SageMaker endpoint to perform inference on the image

response = sm_client.invoke_endpoint(

EndpointName='<endpoint-name>',

ContentType='application/x-image',

Body=image_data

# Parse the inference results and return them to the API caller
results = json.loads(response['Body'].read().decode())

return {

'statusCode': 200,

'body': json.dumps(results)

3. Create an API Gateway:

● Create a new REST API in the API Gateway service.


● Add a new resource and method to the API, which will map to the Lambda function you
just created.
● Configure the integration between the API Gateway and the Lambda function, specifying
the Lambda function name and version, the content type of the request and response,
and any other required settings.
● Deploy the API to a new or existing deployment stage, which will generate a public API
endpoint URL that can be shared with the API users.

4. Test the API:


● We can leverage Postman or cURL request to send a POST request to the API endpoint
URL with an image file or a base64-encoded image in the request body.
● Check the API response for the object detection/Masking results returned by the YOLO
our model.

You might also like