

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

# 取消用户人脸关联
<a name="disassociate-faces"></a>

您可以使用该[DisassociateFaces](https://docs.aws.amazon.com/rekognition/latest/APIReference/API_DisassociateFaces.html)操作来移除用户 ID 和面容 ID 之间的关联。

**取消关联人脸 (SDK)**

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

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

   1. 安装和配置 AWS CLI 和 AWS SDK。有关更多信息，请参阅 [第 2 步：设置 AWS CLI and AWS 软件开发工具包](setup-awscli-sdk.md)。

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

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

   此 Java 示例删除了 FaceID 和用户 ID 与 `DisassociateFaces` 操作之间的关联。

   ```
   import java.util.Arrays;
   import java.util.List;
   
   import com.amazonaws.services.rekognition.AmazonRekognition;
   import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder;
   import com.amazonaws.services.rekognition.model.DisassociateFacesRequest;
   import com.amazonaws.services.rekognition.model.DisassociateFacesResult;
   
   
   public class DisassociateFaces {
   
       public static void main(String[] args) throws Exception {
   
   
           AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
   
           /* Replace the below configurations to allow you successfully run the example
   
              @collectionId: The collection where user and faces are stored
              @userId: The user which faces will get disassociated from
              @faceIds: The list of face IDs that will get disassociated from the given user
            */
   
           String collectionId = "MyCollection";
           String userId = "demoUser";
           String faceId1 = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
           String faceId2 = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
           List<String> faceIds = Arrays.asList(faceid1,faceid2);
   
           System.out.println("Disassociating faces from existing user: " +
                   userId);
   
           DisassociateFacesRequest request = new DisassociateFacesRequest()
                   .withCollectionId(collectionId)
                   .withUserId(userId)
                   .withFaceIds(faceIds)
   
           DisassociateFacesResult result = rekognitionClient.disassociateFaces(request);
   
           System.out.println("Successful face disassociations: " + result.getDisassociatedFaces().size());
           System.out.println("Unsuccessful face disassociations: " + result.getUnsuccessfulFaceDisassociations().size());
       }
   
   }
   ```

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

   此 AWS CLI 命令会移除 FaceID 和用户 ID 与`DisassociateFaces`操作之间的关联。

   ```
   aws rekognition disassociate-faces --face-ids {{list-of-face-ids}}
   --user-id {{user-id}} --collection-id {{collection-name}} --region {{region-name}}
   ```

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

   以下示例删除了 FaceID 和用户 ID 与 `DisassociateFaces` 操作之间的关联。

   ```
   from botocore.exceptions import ClientError
   import boto3
   import logging
   
   logger = logging.getLogger(__name__)
   session = boto3.Session(profile_name='profile-name')
   client = session.client('rekognition')
   
   def disassociate_faces(collection_id, user_id, face_ids):
       """
       Disassociate stored faces within collection to the given user
   
       :param collection_id: The ID of the collection where user and faces are stored.
       :param user_id: The ID of the user that we want to disassociate faces from
       :param face_ids: The list of face IDs to be disassociated from the given user
   
       :return: response of AssociateFaces API
       """
       logger.info(f'Disssociating faces from user: {user_id}, {face_ids}')
       try:
           response = client.disassociate_faces(
               CollectionId=collection_id,
               UserId=user_id,
               FaceIds=face_ids
           )
           print(f'- disassociated {len(response["DisassociatedFaces"])} faces')
       except ClientError:
           logger.exception("Failed to disassociate faces from the given user")
           raise
       else:
           print(response)
           return response
   
   def main():
       face_ids = ["faceId1", "faceId2"]
       collection_id = "collection-id"
       user_id = "user-id"
       disassociate_faces(collection_id, user_id, face_ids)
   
   if __name__ == "__main__":
       main()
   ```

------

## DisassociateFaces 操作响应
<a name="disassociate-faces-response"></a>

`DisassociateFaces` 的响应包括 `UserStatus`（即解除关联请求的状态）以及要取消关联的 `FaceIds` 的列表。还会返回一个 `UnsuccessfulFaceDisassociations` 列表。向提交请求后 DisassociateFaces，操作可能需要一分钟左右的时间才能完成。因此，将返回 UserStatus ，其值可能如下所示：
+ CREATED - 表示“用户”已成功创建，并且当前没有人脸与之关联。在进行任何成功的 “” 呼叫之前，“用户AssociateFaces” 将处于此状态。
+ 更新-表示 “用户” 正在更新以反映新 associated/disassociated 面孔，并将在几秒钟后变为活动状态。搜索结果可能包含处于这种状态的“用户”，客户可以选择在返回的结果中忽略他们。
+ ACTIVE-表示 **“**用户**”** 已更新以反映所有 associated/disassociated 面孔并且处于可搜索状态。

```
{
    "UserStatus": "UPDATING", 
    "DisassociatedFaces": [
        {
            "FaceId": "c92265d4-5f9c-43af-a58e-12be0ce02bc3"
        }
    ], 
    "UnsuccessfulFaceDisassociations": [
        {
            "Reasons": [
                "ASSOCIATED_TO_A_DIFFERENT_IDENTITY"
            ], 
            "FaceId": "f5817d37-94f6-4335-bfee-6cf79a3d806e", 
            "UserId": "demoUser1"
        }
    ]
}
```