Amazon Rekognition Custom Labels 모델 중지 - Rekognition

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

Amazon Rekognition Custom Labels 모델 중지

콘솔을 사용하거나 버전 작업을 사용하여 Amazon Rekognition 사용자 지정 레이블 모델 실행을 중단할 수 있습니다. StopProject

Amazon Rekognition Custom Labels 모델 중지(콘솔)

다음 절차를 사용하여 콘솔에서 Amazon Rekognition Custom Labels 모델의 실행을 중지합니다. 콘솔에서 직접 모델을 중지하거나 콘솔에서 제공하는 AWS SDK 코드를 사용할 수 있습니다.

모델을 중지하려면(콘솔)
  1. https://console.aws.amazon.com/rekognition/에서 Amazon Rekognition 콘솔을 엽니다.

  2. 사용자 지정 레이블 사용을 선택합니다.

  3. Get started를 선택합니다.

  4. 왼쪽 탐색 창에서 프로젝트를 선택합니다.

  5. 프로젝트 리소스 페이지에서 중지하려는 훈련된 모델이 포함된 프로젝트를 선택합니다.

  6. 모델 항목에서 중지하려는 모델을 선택합니다.

  7. 모델 사용 탭을 선택합니다.

  8. Stop model using the console
    1. 모델 시작 또는 중지 항목에서 중지를 선택합니다.

    2. 모델 중지 대화 상자에서 중지를 입력하여 모델 중지를 확인합니다.

    3. 중지를 선택하여 모델을 중지합니다.

    Stop model using the AWS SDK

    모델 사용 항목에서 다음을 수행하세요.

    1. API 코드를 선택합니다.

    2. AWS CLI 또는 Python을 선택합니다.

    3. 모델 중지에서 예제 코드를 복사합니다.

    4. 예제 코드를 사용하여 모델을 중지하세요. 자세한 정보는 Amazon Rekognition Custom Labels 모델 중지(SDK)을 참조하세요.

  9. 페이지 상단에서 프로젝트 이름을 선택하면 프로젝트 개요 페이지로 돌아갑니다.

  10. 모델 항목에서 모델의 상태를 확인합니다. 모델 상태가 중지로 표시되면 모델이 중지된 것입니다.

Amazon Rekognition Custom Labels 모델 중지(SDK)

StopProject버전 API를 호출하고 ProjectVersionArn 입력 파라미터에 모델의 Amazon 리소스 이름 (ARN) 을 전달하여 모델을 중지합니다.

모델을 중지하는 데 시간이 걸릴 수 있습니다. 현재 상태를 확인하려면 DescribeProjectVersions를 사용하세요.

모델을 중지하려면(SDK)
  1. 아직 설치하지 않았다면 및 AWS SDK를 설치하고 구성하십시오. AWS CLI 자세한 정보는 4단계: 및 SDK 설정 AWS CLIAWS을 참조하세요.

  2. 다음 예제 코드를 사용하여 모델 실행을 중지합니다.

    CLI

    project-version-arn의 값을 중지하려는 모델 버전의 ARN으로 변경합니다.

    aws rekognition stop-project-version --project-version-arn "model arn" \ --profile custom-labels-access
    Python

    다음 예제는 이미 실행 중인 모델을 중지합니다.

    다음 명령줄 파라미터를 제공하세요.

    • project_arn: 중지하려는 모델이 포함된 프로젝트의 ARN

    • model_arn: 중지하려는 모델의 ARN

    # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 """ Purpose Shows how to stop a running Amazon Lookout for Vision model. """ import argparse import logging import time import boto3 from botocore.exceptions import ClientError logger = logging.getLogger(__name__) def get_model_status(rek_client, project_arn, model_arn): """ Gets the current status of an Amazon Rekognition Custom Labels model :param rek_client: The Amazon Rekognition Custom Labels Boto3 client. :param project_name: The name of the project that you want to use. :param model_arn: The name of the model that you want the status for. """ logger.info ("Getting status for %s.", model_arn) # Extract the model version from the model arn. version_name=(model_arn.split("version/",1)[1]).rpartition('/')[0] # Get the model status. models=rek_client.describe_project_versions(ProjectArn=project_arn, VersionNames=[version_name]) for model in models['ProjectVersionDescriptions']: logger.info("Status: %s",model['StatusMessage']) return model["Status"] # No model found. logger.exception("Model %s not found.", model_arn) raise Exception("Model %s not found.", model_arn) def stop_model(rek_client, project_arn, model_arn): """ Stops a running Amazon Rekognition Custom Labels Model. :param rek_client: The Amazon Rekognition Custom Labels Boto3 client. :param project_arn: The ARN of the project that you want to stop running. :param model_arn: The ARN of the model (ProjectVersion) that you want to stop running. """ logger.info("Stopping model: %s", model_arn) try: # Stop the model. response=rek_client.stop_project_version(ProjectVersionArn=model_arn) logger.info("Status: %s", response['Status']) # stops when hosting has stopped or failure. status = "" finished = False while finished is False: status=get_model_status(rek_client, project_arn, model_arn) if status == "STOPPING": logger.info("Model stopping in progress...") time.sleep(10) continue if status == "STOPPED": logger.info("Model is not running.") finished = True continue error_message = f"Error stopping model. Unexepected state: {status}" logger.exception(error_message) raise Exception(error_message) logger.info("finished. Status %s", status) return status except ClientError as err: logger.exception("Couldn't stop model - %s: %s", model_arn,err.response['Error']['Message']) raise def add_arguments(parser): """ Adds command line arguments to the parser. :param parser: The command line parser. """ parser.add_argument( "project_arn", help="The ARN of the project that contains the model that you want to stop." ) parser.add_argument( "model_arn", help="The ARN of the model that you want to stop." ) def main(): logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s") try: # Get command line arguments. parser = argparse.ArgumentParser(usage=argparse.SUPPRESS) add_arguments(parser) args = parser.parse_args() # Stop the model. session = boto3.Session(profile_name='custom-labels-access') rekognition_client = session.client("rekognition") status=stop_model(rekognition_client, args.project_arn, args.model_arn) print(f"Finished stopping model: {args.model_arn}") print(f"Status: {status}") except ClientError as err: logger.exception("Problem stopping model:%s",err) print(f"Failed to stop model: {err}") except Exception as err: logger.exception("Problem stopping model:%s", err) print(f"Failed to stop model: {err}") if __name__ == "__main__": main()
    Java V2

    다음 명령줄 파라미터를 제공하세요.

    • project_arn: 중지하려는 모델이 포함된 프로젝트의 ARN

    • model_arn: 중지하려는 모델의 ARN

    /* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ package com.example.rekognition; import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.rekognition.RekognitionClient; import software.amazon.awssdk.services.rekognition.model.DescribeProjectVersionsRequest; import software.amazon.awssdk.services.rekognition.model.DescribeProjectVersionsResponse; import software.amazon.awssdk.services.rekognition.model.ProjectVersionDescription; import software.amazon.awssdk.services.rekognition.model.ProjectVersionStatus; import software.amazon.awssdk.services.rekognition.model.RekognitionException; import software.amazon.awssdk.services.rekognition.model.StopProjectVersionRequest; import software.amazon.awssdk.services.rekognition.model.StopProjectVersionResponse; import java.util.logging.Level; import java.util.logging.Logger; public class StopModel { public static final Logger logger = Logger.getLogger(StopModel.class.getName()); public static int findForwardSlash(String modelArn, int n) { int start = modelArn.indexOf('/'); while (start >= 0 && n > 1) { start = modelArn.indexOf('/', start + 1); n -= 1; } return start; } public static void stopMyModel(RekognitionClient rekClient, String projectArn, String modelArn) throws Exception, RekognitionException { try { logger.log(Level.INFO, "Stopping {0}", modelArn); StopProjectVersionRequest stopProjectVersionRequest = StopProjectVersionRequest.builder() .projectVersionArn(modelArn).build(); StopProjectVersionResponse response = rekClient.stopProjectVersion(stopProjectVersionRequest); logger.log(Level.INFO, "Status: {0}", response.statusAsString()); // Get the model version int start = findForwardSlash(modelArn, 3) + 1; int end = findForwardSlash(modelArn, 4); String versionName = modelArn.substring(start, end); // wait until model stops DescribeProjectVersionsRequest describeProjectVersionsRequest = DescribeProjectVersionsRequest.builder() .projectArn(projectArn).versionNames(versionName).build(); boolean stopped = false; // Wait until create finishes do { DescribeProjectVersionsResponse describeProjectVersionsResponse = rekClient .describeProjectVersions(describeProjectVersionsRequest); for (ProjectVersionDescription projectVersionDescription : describeProjectVersionsResponse .projectVersionDescriptions()) { ProjectVersionStatus status = projectVersionDescription.status(); logger.log(Level.INFO, "stopping model: {0} ", modelArn); switch (status) { case STOPPED: logger.log(Level.INFO, "Model stopped"); stopped = true; break; case STOPPING: Thread.sleep(5000); break; case FAILED: String error = "Model stopping failed: " + projectVersionDescription.statusAsString() + " " + projectVersionDescription.statusMessage() + " " + modelArn; logger.log(Level.SEVERE, error); throw new Exception(error); default: String unexpectedError = "Unexpected stopping state: " + projectVersionDescription.statusAsString() + " " + projectVersionDescription.statusMessage() + " " + modelArn; logger.log(Level.SEVERE, unexpectedError); throw new Exception(unexpectedError); } } } while (stopped == false); } catch (RekognitionException e) { logger.log(Level.SEVERE, "Could not stop model: {0}", e.getMessage()); throw e; } } public static void main(String[] args) { String modelArn = null; String projectArn = null; final String USAGE = "\n" + "Usage: " + "<project_name> <version_name>\n\n" + "Where:\n" + " project_arn - The ARN of the project that contains the model that you want to stop. \n\n" + " model_arn - The ARN of the model version that you want to stop.\n\n"; if (args.length != 2) { System.out.println(USAGE); System.exit(1); } projectArn = args[0]; modelArn = args[1]; try { // Get the Rekognition client. RekognitionClient rekClient = RekognitionClient.builder() .credentialsProvider(ProfileCredentialsProvider.create("custom-labels-access")) .region(Region.US_WEST_2) .build(); // Stop model stopMyModel(rekClient, projectArn, modelArn); System.out.println(String.format("Model stopped: %s", modelArn)); rekClient.close(); } catch (RekognitionException rekError) { logger.log(Level.SEVERE, "Rekognition client error: {0}", rekError.getMessage()); System.exit(1); } catch (Exception rekError) { logger.log(Level.SEVERE, "Error: {0}", rekError.getMessage()); System.exit(1); } } }