本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
上一節的範例適用於 AWS CLI v2。下列來自端點的請求和回應範例使用 AWS CLI 第 1 版。
在下列程式碼範例中,請求包含單一記錄,而回應就是其機率值。
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}]}