【发布时间】:2019-08-04 15:23:05
【问题描述】:
我已经使用内置图像分类模型训练了一个模型,通过带有 lst 文件的原始图像对两个手机模型进行分类。(例如:Iphone6splus 和 Iphone7plus) 所以类数是 2,我使用的数据集数是 1600 张图像,每个类 800 个。
之后,我使用来自已完成的制革工作的工件数据在控制台中创建了终点。
为了部署模型测试准确率,我需要使用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] )
)
这是获取结果需要参考的示例代码吗?
【问题讨论】:
-
在 SageMaker 中创建端点时,您实际上是在部署模型,您可以开始使用端点名称调用它。你到底在问什么?
-
我想确认使用笔记本是否是测试模型结果的方式。
-
您可以按照您的描述从笔记本中执行此操作,但您可以从其他任何位置执行此操作。您可以创建一个网页,您可以上传图像并查看结果,创建一个发送一批图像并检查其类的自动化服务等。所有这些都使用 sagemaker-realtime 的任何 SDK。
标签: amazon-web-services aws-sdk amazon-sagemaker