기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
Amazon Lookout for Vision 모델 시작하기
Amazon Lookout for Vision 모델을 사용하여 이상 현상을 탐지하려면 먼저 모델을 시작해야 합니다. StartModel API를 호출하고 다음을 전달하여 모델을 시작합니다.
ProjectName — 시작하려는 모델이 포함된 프로젝트 이름입니다.
ModelVersion — 시작하려는 모델의 버전입니다.
MinInferenceUnits — 추론 단위의 최소 수입니다. 자세한 내용은 추론 단위 섹션을 참조하세요.
(선택 사항) MaxInferenceUnits — Amazon Lookout for Vision에서 모델을 자동으로 확장하는 데 사용할 수 있는 최대 추론 단위 수입니다. 자세한 내용은 추론 단위 자동 규모 조정 섹션을 참조하세요.
Amazon Lookout for Vision에서는 모델을 시작하고 중지하는 데 사용할 수 있는 예제 코드를 제공합니다.
모델 시작 (콘솔)
Amazon Lookout for Vision 콘솔은 모델을 시작하는 데 사용할 수 있는 AWS CLI명령을 제공합니다. 모델이 시작되면 이미지의 이상 탐지를 시작할 수 있습니다. 자세한 내용은 이미지에서 이상 탐지 섹션을 참조하세요.
모델을 시작하려면 (콘솔)
-
아직 하지 않았다면 AWS CLI 및 AWS SDK를 설치하고 구성하세요. 자세한 내용은 4단계: AWS CLI 및 AWS SDK 설정 섹션을 참조하세요.
https://console.aws.amazon.com/lookoutvision/에서 Amazon Lookout for Vision 콘솔을 엽니다.
Get started를 선택합니다.
왼쪽 탐색 창에서 프로젝트를 선택합니다.
프로젝트 리소스 페이지에서 시작하려는 학습된 모델이 포함된 프로젝트를 선택합니다.
모델 항목에서 시작할 모델을 선택합니다.
모델의 세부 정보 페이지에서 모델 사용을 선택한 다음 클라우드에 API 통합을 선택합니다.
AWS CLI 명령에서 start-model
을 호출하는 AWS CLI 명령을 복사합니다.
명령 프롬프트에서 이전 단계에서 복사한 start-model
명령을 입력합니다. lookoutvision
프로필을 사용하여 자격 증명을 가져오려면 --profile lookoutvision-access
매개 변수를 추가하십시오.
콘솔의 왼쪽 탐색 창에서 모델을 선택합니다.
상태 열에서 모델의 현재 상태를 확인합니다. 상태가 호스팅인 경우 모델을 사용하여 이미지의 이상을 감지할 수 있습니다. 자세한 내용은 이미지에서 이상 탐지 섹션을 참조하세요.
Amazon Lookout for Vision 모델 (SDK) 시작하기
StartModel 작업을 호출하여 모델을 시작합니다.
모델을 시작하는 데 시간이 걸릴 수 있습니다. DescribeModel을 호출하여 현재 상태를 확인할 수 있습니다. 자세한 내용은 모델 보기 섹션을 참조하세요.
모델 (SDK) 을 시작하려면
-
아직 하지 않았다면 AWS CLI 및 AWS SDK를 설치하고 구성하세요. 자세한 내용은 4단계: AWS CLI 및 AWS SDK 설정 섹션을 참조하세요.
다음 예제 코드를 사용하여 모델을 시작합니다.
- CLI
-
다음 값을 변경합니다.
project-name
은 시작하려는 모델이 포함된 프로젝트 이름으로 이동합니다.
model-version
은 시작하려는 모델의 버전으로 이동합니다.
--min-inference-units
은 사용하려는 추론 단위 수입니다.
(선택 사항) --max-inference-units
은 Amazon Lookout for Vision에서 모델을 자동으로 스케일링하는 데 사용할 수 있는 최대 추론 단위 수까지 늘립니다.
aws lookoutvision start-model --project-name "project name
"\
--model-version model version
\
--min-inference-units minimum number of units
\
--max-inference-units max number of units
\
--profile lookoutvision-access
- Python
-
이 코드는 AWS 문서 SDK 예제 GitHub 리포지토리에서 가져왔습니다. 전체 예제는 여기에서 확인하세요.
@staticmethod
def start_model(
lookoutvision_client, project_name, model_version, min_inference_units, max_inference_units = None):
"""
Starts the hosting of a Lookout for Vision model.
:param lookoutvision_client: A Boto3 Lookout for Vision client.
:param project_name: The name of the project that contains the version of the
model that you want to start hosting.
:param model_version: The version of the model that you want to start hosting.
:param min_inference_units: The number of inference units to use for hosting.
:param max_inference_units: (Optional) The maximum number of inference units that
Lookout for Vision can use to automatically scale the model.
"""
try:
logger.info(
"Starting model version %s for project %s", model_version, project_name)
if max_inference_units is None:
lookoutvision_client.start_model(
ProjectName = project_name,
ModelVersion = model_version,
MinInferenceUnits = min_inference_units)
else:
lookoutvision_client.start_model(
ProjectName = project_name,
ModelVersion = model_version,
MinInferenceUnits = min_inference_units,
MaxInferenceUnits = max_inference_units)
print("Starting hosting...")
status = ""
finished = False
# Wait until hosted or failed.
while finished is False:
model_description = lookoutvision_client.describe_model(
ProjectName=project_name, ModelVersion=model_version)
status = model_description["ModelDescription"]["Status"]
if status == "STARTING_HOSTING":
logger.info("Host starting in progress...")
time.sleep(10)
continue
if status == "HOSTED":
logger.info("Model is hosted and ready for use.")
finished = True
continue
logger.info("Model hosting failed and the model can't be used.")
finished = True
if status != "HOSTED":
logger.error("Error hosting model: %s", status)
raise Exception(f"Error hosting model: {status}")
except ClientError:
logger.exception("Couldn't host model.")
raise
- Java V2
-
이 코드는 AWS 문서 SDK 예제 GitHub 리포지토리에서 가져왔습니다. 전체 예제는 여기에서 확인하세요.
/**
* Starts hosting an Amazon Lookout for Vision model. Returns when the model has
* started or if hosting fails. You are charged for the amount of time that a
* model is hosted. To stop hosting a model, use the StopModel operation.
*
* @param lfvClient An Amazon Lookout for Vision client.
* @param projectName The name of the project that contains the model that you
* want to host.
* @modelVersion The version of the model that you want to host.
* @minInferenceUnits The number of inference units to use for hosting.
* @maxInferenceUnits The maximum number of inference units that Lookout for
* Vision can use for automatically scaling the model. If the
* value is null, automatic scaling doesn't happen.
* @return ModelDescription The description of the model, which includes the
* model hosting status.
*/
public static ModelDescription startModel(LookoutVisionClient lfvClient, String projectName, String modelVersion,
Integer minInferenceUnits, Integer maxInferenceUnits) throws LookoutVisionException, InterruptedException {
logger.log(Level.INFO, "Starting Model version {0} for project {1}.",
new Object[] { modelVersion, projectName });
StartModelRequest startModelRequest = null;
if (maxInferenceUnits == null) {
startModelRequest = StartModelRequest.builder().projectName(projectName).modelVersion(modelVersion)
.minInferenceUnits(minInferenceUnits).build();
} else {
startModelRequest = StartModelRequest.builder().projectName(projectName).modelVersion(modelVersion)
.minInferenceUnits(minInferenceUnits).maxInferenceUnits(maxInferenceUnits).build();
}
// Start hosting the model.
lfvClient.startModel(startModelRequest);
DescribeModelRequest describeModelRequest = DescribeModelRequest.builder().projectName(projectName)
.modelVersion(modelVersion).build();
ModelDescription modelDescription = null;
boolean finished = false;
// Wait until model is hosted or failure occurs.
do {
modelDescription = lfvClient.describeModel(describeModelRequest).modelDescription();
switch (modelDescription.status()) {
case HOSTED:
logger.log(Level.INFO, "Model version {0} for project {1} is running.",
new Object[] { modelVersion, projectName });
finished = true;
break;
case STARTING_HOSTING:
logger.log(Level.INFO, "Model version {0} for project {1} is starting.",
new Object[] { modelVersion, projectName });
TimeUnit.SECONDS.sleep(60);
break;
case HOSTING_FAILED:
logger.log(Level.SEVERE, "Hosting failed for model version {0} for project {1}.",
new Object[] { modelVersion, projectName });
finished = true;
break;
default:
logger.log(Level.SEVERE, "Unexpected error when hosting model version {0} for project {1}: {2}.",
new Object[] { projectName, modelVersion, modelDescription.status() });
finished = true;
break;
}
} while (!finished);
logger.log(Level.INFO, "Finished starting model version {0} for project {1} status: {2}",
new Object[] { modelVersion, projectName, modelDescription.statusMessage() });
return modelDescription;
}
코드 출력이 Model is hosted and ready for use
인 경우 모델을 사용하여 이미지의 이상을 감지할 수 있습니다. 자세한 내용은 이미지에서 이상 탐지 섹션을 참조하세요.