Amazon Rekognition Custom Labels 작업을 직접 호출합니다. - Rekognition

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

Amazon Rekognition Custom Labels 작업을 직접 호출합니다.

다음 코드를 실행하여 Amazon Rekognition Custom Labels API를 직접 호출할 수 있는지 확인합니다. 코드에는 현재 AWS 지역의 AWS 계정 내 프로젝트가 나열됩니다. 이전에 프로젝트를 생성하지 않은 경우 응답은 비어 있지만 DescribeProjects 작업을 직접 호출할 수 있다는 확인은 표시됩니다.

일반적으로 예제 함수를 직접 호출하려면 AWS SDK Rekognition 클라이언트와 기타 필수 파라미터가 필요합니다. AWS SDK 클라이언트는 기본 함수에서 선언됩니다.

코드가 실패할 경우 사용하는 사용자에게 올바른 권한이 있는지 확인하세요. 또한 Amazon Rekognition 사용자 지정 레이블을 모든 AWS 지역에서 사용할 수 있는 것은 아니므로 사용 중인 지역도 확인하십시오. AWS

Amazon Rekognition Custom Labels 작업을 직접 호출하려면
  1. 아직 설치하지 않았다면 및 SDK를 설치하고 구성하십시오 AWS CLI . AWS 자세한 정보는 4단계: 및 SDK 설정 AWS CLIAWS을 참조하세요.

  2. 다음 예제 코드를 사용하여 프로젝트를 확인하십시오.

    CLI

    describe-projects 명령어를 사용하여 계정에 있는 프로젝트를 나열합니다.

    aws rekognition describe-projects \ --profile custom-labels-access
    Python
    # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 """ This example shows how to describe your Amazon Rekognition Custom Labels projects. If you haven't previously created a project in the current AWS Region, the response is an empty list, but does confirm that you can call an Amazon Rekognition Custom Labels operation. """ from botocore.exceptions import ClientError import boto3 def describe_projects(rekognition_client): """ Lists information about the projects that are in in your AWS account and in the current AWS Region. : param rekognition_client: A Boto3 Rekognition client. """ try: response = rekognition_client.describe_projects() for project in response["ProjectDescriptions"]: print("Status: " + project["Status"]) print("ARN: " + project["ProjectArn"]) print() print("Done!") except ClientError as err: print(f"Couldn't describe projects. \n{err}") raise def main(): """ Entrypoint for script. """ session = boto3.Session(profile_name='custom-labels-access') rekognition_client = session.client("rekognition") describe_projects(rekognition_client) if __name__ == "__main__": main()
    Java V2
    /* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ package com.example.rekognition; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; 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.DatasetMetadata; import software.amazon.awssdk.services.rekognition.model.DescribeProjectsRequest; import software.amazon.awssdk.services.rekognition.model.DescribeProjectsResponse; import software.amazon.awssdk.services.rekognition.model.ProjectDescription; import software.amazon.awssdk.services.rekognition.model.RekognitionException; public class Hello { public static final Logger logger = Logger.getLogger(Hello.class.getName()); public static void describeMyProjects(RekognitionClient rekClient) { DescribeProjectsRequest descProjects = null; // If a single project name is supplied, build projectNames argument List<String> projectNames = new ArrayList<String>(); descProjects = DescribeProjectsRequest.builder().build(); // Display useful information for each project. DescribeProjectsResponse resp = rekClient.describeProjects(descProjects); for (ProjectDescription projectDescription : resp.projectDescriptions()) { System.out.println("ARN: " + projectDescription.projectArn()); System.out.println("Status: " + projectDescription.statusAsString()); if (projectDescription.hasDatasets()) { for (DatasetMetadata datasetDescription : projectDescription.datasets()) { System.out.println("\tdataset Type: " + datasetDescription.datasetTypeAsString()); System.out.println("\tdataset ARN: " + datasetDescription.datasetArn()); System.out.println("\tdataset Status: " + datasetDescription.statusAsString()); } } System.out.println(); } } public static void main(String[] args) { try { // Get the Rekognition client RekognitionClient rekClient = RekognitionClient.builder() .credentialsProvider(ProfileCredentialsProvider.create("custom-labels-access")) .region(Region.US_WEST_2) .build(); // Describe projects describeMyProjects(rekClient); rekClient.close(); } catch (RekognitionException rekError) { logger.log(Level.SEVERE, "Rekognition client error: {0}", rekError.getMessage()); System.exit(1); } } }