기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
참고
SageMaker AI 엔드포인트를 프로그래밍 방식으로 호출하기 전에 Amazon SageMaker Canvas에서 모델 배포를 테스트하는 것이 좋습니다. SageMaker
애플리케이션과 함께 프로덕션 환경에서 Amazon SageMaker SageMaker Canvas 모델을 사용할 수 있습니다. 다른 SageMaker AI 실시간 엔드포인트를 호출하는 것과 동일한 방식으로 프로그래밍 방식으로 엔드포인트를 호출합니다. 엔드포인트를 프로그래밍 방식으로 간접 호출하면 배포 테스트에서 언급한 것과 동일한 필드를 포함하는 응답 객체가 반환됩니다.
엔드포인트를 프로그래밍 방식으로 호출하는 방법에 대한 자세한 내용은 실시간 추론을 위한 모델 호출을 참조하세요.
다음 Python 예제는 모델 유형에 따라 엔드포인트를 호출하는 방법을 보여줍니다.
다음 예시에서는 엔드포인트에 배포한 JumpStart 파운데이션 모델을 간접 호출하는 방법을 보여줍니다.
import boto3
import pandas as pd
client = boto3.client("runtime.sagemaker")
body = pd.DataFrame(
[['feature_column1', 'feature_column2'],
['feature_column1', 'feature_column2']]
).to_csv(header=False, index=False).encode("utf-8")
response = client.invoke_endpoint(
EndpointName="endpoint_name",
ContentType="text/csv",
Body=body,
Accept="application/json"
)
다음 예시에서는 숫자 또는 범주형 예측 모델을 호출하는 방법을 보여줍니다.
import boto3
import pandas as pd
client = boto3.client("runtime.sagemaker")
body = pd.DataFrame(['feature_column1', 'feature_column2'], ['feature_column1', 'feature_column2']).to_csv(header=False, index=False).encode("utf-8")
response = client.invoke_endpoint(
EndpointName="endpoint_name",
ContentType="text/csv",
Body=body,
Accept="application/json"
)
다음 예시에서는 시계열 예측 모델을 간접 호출하는 방법을 보여줍니다. 시계열 예측 모델 간접 호출을 테스트하는 방법에 대한 전체 예는 Time-Series Forecasting with Amazon SageMaker Autopilot
import boto3
import pandas as pd
csv_path = './real-time-payload.csv'
data = pd.read_csv(csv_path)
client = boto3.client("runtime.sagemaker")
body = data.to_csv(index=False).encode("utf-8")
response = client.invoke_endpoint(
EndpointName="endpoint_name",
ContentType="text/csv",
Body=body,
Accept="application/json"
)
다음 예시에서는 이미지 예측 모델을 호출하는 방법을 보여줍니다.
import boto3
client = boto3.client("runtime.sagemaker")
with open("example_image.jpg", "rb") as file:
body = file.read()
response = client.invoke_endpoint(
EndpointName="endpoint_name",
ContentType="application/x-image",
Body=body,
Accept="application/json"
)
다음 예시에서는 텍스트 예측 모델을 호출하는 방법을 보여줍니다.
import boto3
import pandas as pd
client = boto3.client("runtime.sagemaker")
body = pd.DataFrame([["Example text 1"], ["Example text 2"]]).to_csv(header=False, index=False).encode("utf-8")
response = client.invoke_endpoint(
EndpointName="endpoint_name",
ContentType="text/csv",
Body=body,
Accept="application/json"
)