简体   繁体   中英

How to deploy an image classification model in AWS SageMaker after done training job and created end-point

I have done training a model with the build in image classification model to classify two phone models by raw images with lst file.(Ex:Iphone6splus and Iphone7plus) So the num of classes is 2, num of datasets I use is 1600 images, 800 for each class.

After that, I created the end point in console using the artifacts data from tanning job that have been done.

In order to deploy the model to test the accuracy, I need to use the juputer notebook?

import json
import numpy as np
import boto3
runtime = boto3.Session().client(service_name='sagemaker-runtime')
# set the object categories array
object_categories = ['class1','class0'}
# Load the image bytes
img = open('xxxfolder/xxx.jpg', 'rb').read()

# Call your model for predicting which object appears in this image.
response = runtime.invoke_endpoint(
EndpointName=endpoint_name, 
ContentType='application/x-image', 
Body=bytearray(img)
)
# read the prediction result and parse the json
result = response['Body'].read()
result = json.loads(result)

# which category has the highest confidence?
pred_label_id = np.argmax(result)

print( “%s (%f)” % (object_categories[pred_label_id], result[pred_label_id] ) 
)

Is this the sample code that I need to refer to get the results?

When you create and Sagemaker endpoit you already had your model deployed. After creating the endpoint we can create a Lambda Function to use your model.

Note that you can call your model from anywhere, but using an API Gateway with a Lambda function enable you to call via HTTP POST. If your idea is just to test your deployed model, It's better to use the notebook, but If you want to test in a real production scenario, I recommend you to use Lambda + API Gateway solution (adding Cognito for security validation).

In this AWS tutorial you can learn how to use AWS Lambda and API Gateway to call your model via HTTP POST.

Another Option, as Thales Minussi commented, is to invoke your endpoint directly (as long as the call is v4 signed ), which will greatly reduce costs if there are too many invocations on it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM