

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 描述集合
<a name="describe-collection-procedure"></a>

您可以使用 [DescribeCollection](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DescribeCollection.html) 操作获取有关集合的下列信息：
+ 在集合中索引的人脸数量。
+ 与集合一起使用的模型版本。有关更多信息，请参阅 [了解模型版本控制](face-detection-model.md)。
+ 集合的 Amazon 资源名称 (ARN)。
+ 集合的创建日期和时间。

**描述集合 (SDK)**

1. 如果您尚未执行以下操作，请：

   1. 使用 `AmazonRekognitionFullAccess` 权限创建或更新用户。有关更多信息，请参阅 [步骤 1：设置 AWS 账户并创建用户](setting-up.md#setting-up-iam)。

   1. 安装并配置 AWS CLI 和 AWS SDKs。有关更多信息，请参阅 [第 2 步：设置 AWS CLI 和 AWS SDKs](setup-awscli-sdk.md)。

1. 使用以下示例调用 `DescribeCollection` 操作。

------
#### [ Java ]

   此示例描述集合。

   将值 `collectionId` 更改为所需集合的 ID。

   ```
   //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.)
   
   package com.amazonaws.samples;
   
   import com.amazonaws.services.rekognition.AmazonRekognition;
   import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder;
   import com.amazonaws.services.rekognition.model.DescribeCollectionRequest;
   import com.amazonaws.services.rekognition.model.DescribeCollectionResult;
   
   
   public class DescribeCollection {
   
      public static void main(String[] args) throws Exception {
   
         String collectionId = "CollectionID";
         
         AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
   
               
         System.out.println("Describing collection: " +
            collectionId );
            
               
           DescribeCollectionRequest request = new DescribeCollectionRequest()
                       .withCollectionId(collectionId);
              
         DescribeCollectionResult describeCollectionResult = rekognitionClient.describeCollection(request); 
         System.out.println("Collection Arn : " +
            describeCollectionResult.getCollectionARN());
         System.out.println("Face count : " +
            describeCollectionResult.getFaceCount().toString());
         System.out.println("Face model version : " +
            describeCollectionResult.getFaceModelVersion());
         System.out.println("Created : " +
            describeCollectionResult.getCreationTimestamp().toString());
   
      } 
   
   }
   ```

------
#### [ Java V2 ]

   此代码取自 AWS 文档 SDK 示例 GitHub 存储库。请在[此处](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javav2/example_code/rekognition/src/main/java/com/example/rekognition/DescribeCollection.java)查看完整示例。

   ```
   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.DescribeCollectionRequest;
   import software.amazon.awssdk.services.rekognition.model.DescribeCollectionResponse;
   import software.amazon.awssdk.services.rekognition.model.RekognitionException;
   //snippet-end:[rekognition.java2.describe_collection.import]
   
   /**
   * Before running this Java V2 code example, set up your development environment, including your credentials.
   *
   * For more information, see the following documentation topic:
   *
   * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html
   */
   public class DescribeCollection {
   
    public static void main(String[] args) {
   
        final String usage = "\n" +
            "Usage: " +
            "   <collectionName>\n\n" +
            "Where:\n" +
            "   collectionName - The name of the Amazon Rekognition collection. \n\n";
   
        if (args.length != 1) {
            System.out.println(usage);
            System.exit(1);
        }
   
        String collectionName = args[0];
        Region region = Region.US_EAST_1;
        RekognitionClient rekClient = RekognitionClient.builder()
            .region(region)
            .credentialsProvider(ProfileCredentialsProvider.create("profile-name"))
            .build();
   
        describeColl(rekClient, collectionName);
        rekClient.close();
    }
   
    // snippet-start:[rekognition.java2.describe_collection.main]
    public static void describeColl(RekognitionClient rekClient, String collectionName) {
   
        try {
            DescribeCollectionRequest describeCollectionRequest = DescribeCollectionRequest.builder()
                .collectionId(collectionName)
                .build();
   
            DescribeCollectionResponse describeCollectionResponse = rekClient.describeCollection(describeCollectionRequest);
            System.out.println("Collection Arn : " + describeCollectionResponse.collectionARN());
            System.out.println("Created : " + describeCollectionResponse.creationTimestamp().toString());
   
        } catch(RekognitionException e) {
            System.out.println(e.getMessage());
            System.exit(1);
        }
    }
    // snippet-end:[rekognition.java2.describe_collection.main]
   }
   ```

------
#### [ AWS CLI ]

   此 AWS CLI 命令显示 `describe-collection` CLI 操作的 JSON 输出。将 `collection-id` 的值更改为所需集合的 ID。将创建 Rekognition 会话的行中的`profile_name`值替换为您的开发人员资料的名称。

   ```
   aws rekognition describe-collection --collection-id collection-name --profile profile-name
   ```

------
#### [ Python ]

   此示例描述集合。

   将值 `collection_id` 更改为所需集合的 ID。将创建 Rekognition 会话的行中的`profile_name`值替换为您的开发人员资料的名称。

   ```
   # Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   # PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.)
   
   import boto3
   from botocore.exceptions import ClientError
   
   def describe_collection(collection_id):
   
       print('Attempting to describe collection ' + collection_id)
       
       session = boto3.Session(profile_name='default')
       client = session.client('rekognition')
       
       try:
       response = client.describe_collection(CollectionId=collection_id)
       print("Collection Arn: " + response['CollectionARN'])
       print("Face Count: " + str(response['FaceCount']))
       print("Face Model Version: " + response['FaceModelVersion'])
       print("Timestamp: " + str(response['CreationTimestamp']))
       
       except ClientError as e:
       if e.response['Error']['Code'] == 'ResourceNotFoundException':
       print('The collection ' + collection_id + ' was not found ')
       else:
       print('Error other than Not Found occurred: ' + e.response['Error']['Message'])
       print('Done...')
   
   def main():
       collection_id = 'collection-name'
       describe_collection(collection_id)
   
   if __name__ == "__main__":
       main()
   ```

------
#### [ .NET ]

   此示例描述集合。

   将值 `collectionId` 更改为所需集合的 ID。

   ```
   //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.)
   
   using System;
   using Amazon.Rekognition;
   using Amazon.Rekognition.Model;
   
   public class DescribeCollection
   {
       public static void Example()
       {
           AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient();
   
           String collectionId = "CollectionID";
           Console.WriteLine("Describing collection: " + collectionId);
   
           DescribeCollectionRequest describeCollectionRequest = new DescribeCollectionRequest()
           {
               CollectionId = collectionId
           };
   
           DescribeCollectionResponse describeCollectionResponse = rekognitionClient.DescribeCollection(describeCollectionRequest);
           Console.WriteLine("Collection ARN: " + describeCollectionResponse.CollectionARN);
           Console.WriteLine("Face count: " + describeCollectionResponse.FaceCount);
           Console.WriteLine("Face model version: " + describeCollectionResponse.FaceModelVersion);
           Console.WriteLine("Created: " + describeCollectionResponse.CreationTimestamp);
       }
   }
   ```

------
#### [ Node.js ]

   ```
   //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.)
   
   import { DescribeCollectionCommand } from  "@aws-sdk/client-rekognition";
   import  { RekognitionClient } from "@aws-sdk/client-rekognition";
   import {fromIni} from '@aws-sdk/credential-providers';
   
   // Set the AWS Region.
   const REGION = "region-name"; //e.g. "us-east-1"
   // Set the profile name
   const profileName = "profile-name"
   // Name the collection
   const rekogClient = new RekognitionClient({region: REGION, 
     credentials: fromIni({profile: profileName,}), 
   });
   
   // Name the collection
   const collection_name = "collection-name"
   
   const describeCollection = async (collectionName) => {
     try {
        console.log(`Attempting to describe collection named - ${collectionName}`)
        var response = await rekogClient.send(new DescribeCollectionCommand({CollectionId: collectionName}))
        console.log('Collection Arn:')
        console.log(response.CollectionARN)
        console.log('Face Count:')
        console.log(response.FaceCount)
        console.log('Face Model Version:')
        console.log(response.FaceModelVersion)
        console.log('Timestamp:')
        console.log(response.CreationTimestamp)
        return response; // For unit tests.
     } catch (err) {
       console.log("Error", err.stack);
     }
   };
   
   describeCollection(collection_name)
   ```

------

## DescribeCollection 操作请求
<a name="describe-collection-request"></a>

`DescribeCollection` 的输入是所需集合的 ID，如下面的 JSON 示例所示。

```
{
    "CollectionId": "MyCollection"
}
```

## DescribeCollection 操作响应
<a name="describe-collection-operation-response"></a>

响应包括以下内容：
+ 在集合中索引的人脸数量 `FaceCount`。
+ 与集合一起使用的人脸模型版本，`FaceModelVersion`。有关更多信息，请参阅 [了解模型版本控制](face-detection-model.md)。
+ 集合的 Amazon 资源名称 `CollectionARN`。
+ 集合的创建时间和日期 `CreationTimestamp`。`CreationTimestamp` 的值是自 Unix 纪元时间到集合创建时间的毫秒数。Unix 纪元时间是 1970 年 1 月 1 日星期四，协调世界时 (UTC) 00:00:00。有关更多信息，请参阅 [Unix 时间](https://en.wikipedia.org/wiki/Unix_time)。

```
{
    "CollectionARN": "arn:aws:rekognition:us-east-1:nnnnnnnnnnnn:collection/MyCollection",
    "CreationTimestamp": 1.533422155042E9,
    "FaceCount": 200,
    "UserCount" : 20,
    "FaceModelVersion": "1.0"
}
```