2

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?

WHGG
  • 33
  • 4
  • 1
    When you create an endpoint in SageMaker you are actually deploying the model and you can start calling it using the endpoint name. What exactly are you asking? – Guy Aug 05 '19 at 06:04
  • I want to confirm that whether using the notebook is the way to test the results from the model. – WHGG Aug 06 '19 at 14:26
  • You can do that from the notebook as you described, but you can do it from anywhere else. You can create a web page that you can upload an image and see the results, create an automated service that is sending a batch of images and checking their classes, etc. All are using any of the SDK of sagemaker-realtime. – Guy Aug 07 '19 at 08:40

1 Answers1

4

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.

bcosta12
  • 2,364
  • 16
  • 28
  • 1
    Sagemaker endpoints are also available to be invoked directly as long as the call is v4 signed, which will greatly reduce costs if there are too many invocations on it. – Thales Minussi Aug 05 '19 at 12:41
  • 1
    @ThalesMinussi Can I edit my answer with this information? – bcosta12 Aug 05 '19 at 13:00
  • Thanks sir, I just want to test the deployed model in model, but I'm not familiar with the coding at that interface, where should I refer if I wanna learn it. – WHGG Aug 06 '19 at 14:28
  • https://aws.amazon.com/getting-started/tutorials/build-train-deploy-machine-learning-model-sagemaker/ – bcosta12 Aug 06 '19 at 14:29
  • AWS Blog, AWS Docs and AWS youtube channel... And try these demos https://github.com/kendoo-solutions/amazon-sagemaker-workshop – bcosta12 Aug 06 '19 at 14:31
  • Thank you for all the information. Very appreciate about it. – WHGG Aug 08 '19 at 09:06