本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
用于 Object2Vec 推理的数据格式
下一页描述了用于从 Amazon A SageMaker I Object2Vec 模型中获取评分推断的输入请求和输出响应格式。
GPU优化:分类或回归
由于GPU内存稀缺,可以指定INFERENCE_PREFERRED_MODE
环境变量来优化是加载分类/回归还是输出:编码器嵌入推理网络。GPU如果您的大多数推理适用于分类或回归,请指定 INFERENCE_PREFERRED_MODE=classification
。下面是一个批量转换示例,用于说明如何使用 4 个针对分类/回归推理进行优化的 p3.2xlarge 实例:
transformer = o2v.transformer(instance_count=4, instance_type="ml.p2.xlarge", max_concurrent_transforms=2, max_payload=1, # 1MB strategy='MultiRecord', env={'INFERENCE_PREFERRED_MODE': 'classification'}, # only useful with GPU output_path=output_s3_path)
输入:分类或回归请求格式
Content-type:application/json
{ "instances" : [ {"in0": [6, 17, 606, 19, 53, 67, 52, 12, 5, 10, 15, 10178, 7, 33, 652, 80, 15, 69, 821, 4], "in1": [16, 21, 13, 45, 14, 9, 80, 59, 164, 4]}, {"in0": [22, 1016, 32, 13, 25, 11, 5, 64, 573, 45, 5, 80, 15, 67, 21, 7, 9, 107, 4], "in1": [22, 32, 13, 25, 1016, 573, 3252, 4]}, {"in0": [774, 14, 21, 206], "in1": [21, 366, 125]} ] }
Content-type:application/jsonlines
{"in0": [6, 17, 606, 19, 53, 67, 52, 12, 5, 10, 15, 10178, 7, 33, 652, 80, 15, 69, 821, 4], "in1": [16, 21, 13, 45, 14, 9, 80, 59, 164, 4]} {"in0": [22, 1016, 32, 13, 25, 11, 5, 64, 573, 45, 5, 80, 15, 67, 21, 7, 9, 107, 4], "in1": [22, 32, 13, 25, 1016, 573, 3252, 4]} {"in0": [774, 14, 21, 206], "in1": [21, 366, 125]}
对于分类问题,分数向量的长度对应于 num_classes
。对于回归问题,长度为 1。
输出:分类或回归响应格式
Accept:application/json
{ "predictions": [ { "scores": [ 0.6533935070037842, 0.07582679390907288, 0.2707797586917877 ] }, { "scores": [ 0.026291321963071823, 0.6577019095420837, 0.31600672006607056 ] } ] }
Accept:application/jsonlines
{"scores":[0.195667684078216,0.395351558923721,0.408980727195739]} {"scores":[0.251988261938095,0.258233487606048,0.489778339862823]} {"scores":[0.280087798833847,0.368331134319305,0.351581096649169]}
在分类和回归格式中,分数应用于单个标签。