Amazon CLI v1 示例 - 亚马逊 SageMaker AI
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

Amazon CLI v1 示例

上一节中的示例适用于 Amazon CLI v2。以下发送到端点的请求示例和来自端点的响应示例使用 Amazon CLI v1。

在以下代码示例中,请求由一条记录组成,响应是其概率值。

aws sagemaker-runtime invoke-endpoint \ --endpoint-name test-endpoint-sagemaker-xgboost-model \ --content-type text/csv \ --accept text/csv \ --body '1,2,3,4' \ /dev/stderr 1>/dev/null

在前面的代码示例中,响应输出如下。

0.6

在以下代码示例中,请求由两条记录组成,响应包括其概率,这些概率用逗号分隔。

aws sagemaker-runtime invoke-endpoint \ --endpoint-name test-endpoint-sagemaker-xgboost-model \ --content-type text/csv \ --accept text/csv \ --body $'1,2,3,4\n5,6,7,8' \ /dev/stderr 1>/dev/null

在前面的代码示例中,--body 中的 $'content' 表达式告诉命令将内容中的 '\n' 解释为换行符。响应输出如下。

0.6,0.3

在以下代码示例中,请求由两条记录组成,响应包括其概率,这些概率用换行符分隔。

aws sagemaker-runtime invoke-endpoint \ --endpoint-name test-endpoint-csv-1 \ --content-type text/csv \ --accept text/csv \ --body $'1,2,3,4\n5,6,7,8' \ /dev/stderr 1>/dev/null

在前面的代码示例中,响应输出如下。

0.6 0.3

在以下代码示例中,请求由一条记录组成,响应是来自包含三个类的多类模型的概率值。

aws sagemaker-runtime invoke-endpoint \ --endpoint-name test-endpoint-csv-1 \ --content-type text/csv \ --accept text/csv \ --body '1,2,3,4' \ /dev/stderr 1>/dev/null

在前面的代码示例中,响应输出如下。

0.1,0.6,0.3

在以下代码示例中,请求由两条记录组成,响应包括来自包含三个类的多类模型的概率值。

aws sagemaker-runtime invoke-endpoint \ --endpoint-name test-endpoint-csv-1 \ --content-type text/csv \ --accept text/csv \ --body $'1,2,3,4\n5,6,7,8' \ /dev/stderr 1>/dev/null

在前面的代码示例中,响应输出如下。

0.1,0.6,0.3 0.2,0.5,0.3

在以下代码示例中,请求由两条记录组成,响应包括预测标签和概率。

aws sagemaker-runtime invoke-endpoint \ --endpoint-name test-endpoint-csv-2 \ --content-type text/csv \ --accept text/csv \ --body $'1,2,3,4\n5,6,7,8' \ /dev/stderr 1>/dev/null

在前面的代码示例中,响应输出如下。

1,0.6 0,0.3

在以下代码示例中,请求由两条记录组成,响应包括标签标题和概率。

aws sagemaker-runtime invoke-endpoint \ --endpoint-name test-endpoint-csv-3 \ --content-type text/csv \ --accept text/csv \ --body $'1,2,3,4\n5,6,7,8' \ /dev/stderr 1>/dev/null

在前面的代码示例中,响应输出如下。

"['cat','dog','fish']","[0.1,0.6,0.3]" "['cat','dog','fish']","[0.2,0.5,0.3]"

在以下代码示例中,请求由一条记录组成,响应是其概率值。

aws sagemaker-runtime invoke-endpoint \ --endpoint-name test-endpoint-jsonlines \ --content-type application/jsonlines \ --accept application/jsonlines \ --body '{"features":["This is a good product",5]}' \ /dev/stderr 1>/dev/null

在前面的代码示例中,响应输出如下。

{"score":0.6}

在以下代码示例中,请求由两条记录组成,响应包括预测标签和概率。

aws sagemaker-runtime invoke-endpoint \ --endpoint-name test-endpoint-jsonlines-2 \ --content-type application/jsonlines \ --accept application/jsonlines \ --body $'{"features":[1,2,3,4]}\n{"features":[5,6,7,8]}' \ /dev/stderr 1>/dev/null

在前面的代码示例中,响应输出如下。

{"predicted_label":1,"probability":0.6} {"predicted_label":0,"probability":0.3}

在以下代码示例中,请求由两条记录组成,响应包括标签标题和概率。

aws sagemaker-runtime invoke-endpoint \ --endpoint-name test-endpoint-jsonlines-3 \ --content-type application/jsonlines \ --accept application/jsonlines \ --body $'{"data":{"features":[1,2,3,4]}}\n{"data":{"features":[5,6,7,8]}}' \ /dev/stderr 1>/dev/null

在前面的代码示例中,响应输出如下。

{"predicted_labels":["cat","dog","fish"],"probabilities":[0.1,0.6,0.3]} {"predicted_labels":["cat","dog","fish"],"probabilities":[0.2,0.5,0.3]}

在以下代码示例中,请求采用 CSV 格式,响应采用 JSON 行格式。

aws sagemaker-runtime invoke-endpoint \ --endpoint-name test-endpoint-csv-in-jsonlines-out \ --content-type text/csv \ --accept application/jsonlines \ --body $'1,2,3,4\n5,6,7,8' \ /dev/stderr 1>/dev/null

在前面的代码示例中,响应输出如下。

{"probability":0.6} {"probability":0.3}

在以下代码示例中,请求采用 JSON 行格式,响应采用 CSV 格式。

aws sagemaker-runtime invoke-endpoint \ --endpoint-name test-endpoint-jsonlines-in-csv-out \ --content-type application/jsonlines \ --accept text/csv \ --body $'{"features":[1,2,3,4]}\n{"features":[5,6,7,8]}' \ /dev/stderr 1>/dev/null

在前面的代码示例中,响应输出如下。

0.6 0.3

在以下代码示例中,请求采用 CSV 格式,响应采用 JSON 格式。

aws sagemaker-runtime invoke-endpoint \ --endpoint-name test-endpoint-csv-in-jsonlines-out \ --content-type text/csv \ --accept application/jsonlines \ --body $'1,2,3,4\n5,6,7,8' \ /dev/stderr 1>/dev/null

在前面的代码示例中,响应输出如下。

{"predictions":[{"label":1,"score":0.6},{"label":0,"score":0.3}]}