

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 엔드포인트 호출
<a name="canvas-deploy-model-invoke"></a>

**참고**  
프로그래밍 방식으로 [SageMaker AI 엔드포인트를 간접 호출하기 전에 Amazon SageMaker Canvas에서 모델 배포를 테스트](canvas-deploy-model-test.md)하는 것이 좋습니다.

프로덕션 환경에서 애플리케이션과 함께 SageMaker AI 엔드포인트에 배포한 Amazon SageMaker Canvas 모델을 사용할 수 있습니다. 다른 [SageMaker AI 실시간 엔드포인트](https://docs.aws.amazon.com/sagemaker/latest/dg/realtime-endpoints.html)를 간접 호출하는 것과 동일한 방식으로 프로그래밍 방식으로 엔드포인트를 간접 호출합니다. 엔드포인트를 프로그래밍 방식으로 간접 호출하면 [배포 테스트](canvas-deploy-model-test.md)에서 언급한 것과 동일한 필드를 포함하는 응답 객체가 반환됩니다.

엔드포인트를 프로그래밍 방식으로 호출하는 방법에 대한 자세한 내용은 [실시간 추론을 위한 모델 호출](realtime-endpoints-test-endpoints.md)을 참조하세요.

다음 Python 예제는 모델 유형에 따라 엔드포인트를 호출하는 방법을 보여줍니다.

## JumpStart 파운데이션 모델
<a name="canvas-invoke-js-example"></a>

다음 예시에서는 엔드포인트에 배포한 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"
)
```

## 숫자 및 범주형 예측 모델
<a name="canvas-invoke-tabular-example"></a>

다음 예시에서는 숫자 또는 범주형 예측 모델을 호출하는 방법을 보여줍니다.

```
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"
)
```

## 시계열 예측 모델
<a name="canvas-invoke-forecast-example"></a>

다음 예시에서는 시계열 예측 모델을 간접 호출하는 방법을 보여줍니다. 시계열 예측 모델 간접 호출을 테스트하는 방법에 대한 전체 예는 [Time-Series Forecasting with Amazon SageMaker Autopilot](https://github.com/aws/amazon-sagemaker-examples/blob/eef13dae197a6e588a8bc111aba3244f99ee0fbb/autopilot/autopilot_time_series.ipynb)을 참조하세요.

```
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"
)
```

## 이미지 예측 모델
<a name="canvas-invoke-cv-example"></a>

다음 예시에서는 이미지 예측 모델을 호출하는 방법을 보여줍니다.

```
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"
    )
```

## 텍스트 예측 모델
<a name="canvas-invoke-nlp-example"></a>

다음 예시에서는 텍스트 예측 모델을 호출하는 방법을 보여줍니다.

```
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"
)
```