

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

# Amazon Augmented AI를 사용한 부적절한 콘텐츠 검토
<a name="a2i-rekognition"></a>

Amazon Augmented AI(Amazon A2I)를 사용하면 기계 학습 예측의 인적 검토에 필요한 워크플로우를 구축할 수 있습니다.

Amazon Rekognition은 Amazon A2I와 직접 통합되어 안전하지 않은 이미지를 감지하는 사용 사례에 대한 인적 검토를 쉽게 구현할 수 있습니다. Amazon A2I는 이미지 조정을 위한 인적 검토 워크플로우를 제공합니다. 이를 통해 Amazon Rekognition의 예측을 쉽게 검토할 수 있습니다. 사용 사례에 대한 신뢰도 임계값을 정의하고 시간이 지남에 따라 조정할 수 있습니다. Amazon A2I를 이용하면 조직 또는 Amazon Mechanical Turk 내에서 검토자 풀을 사용할 수 있습니다. 품질과 보안 절차 준수를 위해 AWS에서 사전 검열을 거친 공급업체 인력도 이용할 수 있습니다.

다음 단계에서는 Amazon Rekognition을 이용해 Amazon A2I를 설정하는 방법을 안내합니다. 먼저, 인적 검토를 트리거하는 조건이 있는 Amazon A2I를 사용해 흐름 정의를 생성합니다. 그런 다음 흐름 정의의 Amazon 리소스 이름(ARN)을 Amazon Rekognition `DetectModerationLabel` 작업에 전달합니다. `DetectModerationLabel` 응답에서 인적 검토가 필요한지 여부를 확인할 수 있습니다. 인적 검토의 결과는 흐름 정의에 의해 설정된 Amazon S3 버킷에서 사용할 수 있습니다.

Amazon Rekognition과 함께 Amazon A2I를 사용하는 방법에 대한 종합적인 데모를 보려면 *Amazon SageMaker AI 개발자 안내서*에서 다음 자습서 중 하나를 참조하세요.
+ [데모: Amazon A2I 콘솔에서 시작](https://docs.aws.amazon.com/sagemaker/latest/dg/a2i-get-started-console.html)
+ [데모: Amazon A2I API를 사용하여 시작](https://docs.aws.amazon.com/sagemaker/latest/dg/a2i-get-started-api.html)

  API 사용을 시작하기 위해 예제 Jupyter Notebook을 실행할 수도 있습니다. SageMaker AI 노트북 인스턴스에서 [Amazon Augmented AI(Amazon A2I)와 Amazon Rekognition 통합 [예제]](https://github.com/aws-samples/amazon-a2i-sample-jupyter-notebooks/blob/master/Amazon%20Augmented%20AI%20(A2I)%20and%20Rekognition%20DetectModerationLabels.ipynb) 노트북을 사용하려면 [Amazon A2I Jupyter Notebook으로 SageMaker 노트북 인스턴스 사용](https://docs.aws.amazon.com/sagemaker/latest/dg/a2i-task-types-general.html#a2i-task-types-notebook-demo)을 참조하세요.

**Amazon A2I에서 DetectModerationLabels 실행**
**참고**  
동일한 AWS 리전에서 모든 Amazon A2I 및 Amazon Rekognition 리소스를 생성합니다.

1. *SageMaker AI 설명서*의 [Amazon Augmented AI 시작하기](https://docs.aws.amazon.com/sagemaker/latest/dg/a2i-getting-started.html)에 나열된 사전 요구 사항을 완료하세요.

   또한 *SageMaker AI 설명서*의 [Amazon Augmented AI에서의 권한 및 보안](https://docs.aws.amazon.com/sagemaker/latest/dg/a2i-permissions-security.html) 페이지에서와 같이 IAM 권한을 설정해야 합니다.

1. *SageMaker AI 설명서*의 [인적 검토 워크플로 생성](https://docs.aws.amazon.com/sagemaker/latest/dg/create-human-review-console.html)에 관한 지침을 따르세요.

   인적 검토 워크플로우는 이미지 처리를 관리합니다. 여기에는 인적 검토를 트리거하는 조건, 이미지가 전송되는 작업 팀, 작업 팀이 사용하는 UI 템플릿 및 작업 팀의 결과가 전송되는 Amazon S3 버킷이 포함됩니다.

   `CreateFlowDefinition` 호출 내에서 `HumanLoopRequestSource`를 "AWS/Rekognition/DetectModerationLabels/Image/V3"으로 설정해야 합니다. 그런 다음 인적 검토를 트리거하는 조건을 설정하는 방법을 결정해야 합니다.

   Amazon Rekognition에서는 `ModerationLabelConfidenceCheck` 및 `Sampling`의 두 가지 `ConditionType` 옵션을 사용할 수 있습니다.

   `ModerationLabelConfidenceCheck` 는 중재 레이블의 신뢰도가 범위 내에 있을 때 인적 루프를 생성합니다. 마지막으로, `Sampling`은 인적 검토를 위해 처리된 문서의 임의의 백분율을 보냅니다. 각 `ConditionType`은 다른 `ConditionParameters` 세트를 사용하여 인적 검토 결과를 설정합니다.

   `ModerationLabelConfidenceCheck` 에는 사람이 검토해야 할 키를 설정하는 `ConditionParameters` `ModerationLableName`이 있습니다. 또한 LessThan, GreaterThan 및 Equals를 사용하여 인적 검토에 보낼 백분율 범위를 설정하는 신뢰도도 있습니다. `Sampling`에는 인적 검토로 보낼 문서의 백분율을 설정하는 `RandomSamplingPercentage`이 있습니다.

   다음 코드 예제는 `CreateFlowDefinition`의 부분 호출입니다. "Suggestive"(외설적 콘텐츠) 레이블에서는 98% 미만, "Female Swimwear or Underwear"(여성 수영복 또는 속옷) 레이블에는 95% 이상으로 평가된 경우 인적 검토를 위해 이미지를 보냅니다. 즉, 이미지가 외설적인 것으로 간주되지는 않지만 수영복이나 속옷을 착용한 여성이 있는 경우 인적 검토를 통해 이미지를 다시 확인할 수 있습니다.

   ```
       def create_flow_definition():
       '''
       Creates a Flow Definition resource
   
       Returns:
       struct: FlowDefinitionArn
       '''
       humanLoopActivationConditions = json.dumps(
           {
               "Conditions": [
                   {
                     "And": [
                       {
                           "ConditionType": "ModerationLabelConfidenceCheck",
                           "ConditionParameters": {
                               "ModerationLabelName": "Suggestive",
                               "ConfidenceLessThan": 98
                           }
                       },
                       {
                           "ConditionType": "ModerationLabelConfidenceCheck",
                           "ConditionParameters": {
                               "ModerationLabelName": "Female Swimwear Or Underwear",
                               "ConfidenceGreaterThan": 95
                           }
                       }
                     ]
                  }
               ]
           }
       )
   ```

   `CreateFlowDefinition`은 `DetectModerationLabels`를 호출할 때 다음 단계에서 사용하는 `FlowDefinitionArn`을 반환합니다.

   자세한 내용은 *SageMaker AI API 참조*의 [CreateFlowDefinition](https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateFlowDefinition.html)을 참조하세요.

1. [부적절한 이미지 감지](procedure-moderate-images.md)에 나온 것처럼 `DetectModerationLabels`를 호출할 때 `HumanLoopConfig` 파라미터를 설정합니다. `HumanLoopConfig` 세트를 사용하는 `DetectModerationLabels` 직접 호출의 예는 4단계를 참조하세요.

   1. `HumanLoopConfig` 파라미터 내에서 `FlowDefinitionArn`을 2단계에서 생성한 흐름 정의의 ARN으로 설정합니다.

   1. `HumanLoopName`을 설정합니다. 이는 지역 내에서 고유해야 하며 소문자여야 합니다.

   1. (선택 사항) `DataAttributes`를 사용하여 Amazon Rekognition에 전달한 이미지에 개인 식별 정보가 없는지 여부를 설정할 수 있습니다. Amazon Mechanical Turk에 정보를 보내려면 이 파라미터를 설정해야 합니다.

1. `DetectModerationLabels`를 실행합니다.

   다음 예제에서는 AWS CLI 및를 사용하여 `HumanLoopConfig` 세트`DetectModerationLabels`로 AWS SDK for Python (Boto3) 를 실행하는 방법을 보여줍니다.

------
#### [ AWS SDK for Python (Boto3) ]

   다음 요청 예제에서는 SDK for Python(Boto3)을 사용합니다. 자세한 내용은 *AWS SDK for Python(Boto) API 참조*의 [detect\_moderation\_labels](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/rekognition.html#Rekognition.Client.detect_moderation_labels)를 참조하세요.

   ```
   import boto3
   
   rekognition = boto3.client("rekognition", aws-region)
   
   response = rekognition.detect_moderation_labels( \
           Image={'S3Object': {'Bucket': bucket_name, 'Name': image_name}}, \
           HumanLoopConfig={ \
               'HumanLoopName': 'human_loop_name', \
               'FlowDefinitionArn': , "arn:aws:sagemaker:aws-region:aws_account_number:flow-definition/flow_def_name" \
               'DataAttributes': {'ContentClassifiers': ['FreeOfPersonallyIdentifiableInformation','FreeOfAdultContent']}
            })
   ```

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

   다음 요청 예제에서는 AWS CLI를 사용합니다. 자세한 내용은 [AWS CLI 명령 참조](https://docs.aws.amazon.com/cli/latest/reference/)의 [detect-moderation-labels](https://docs.aws.amazon.com/cli/latest/reference/rekognition/detect-moderation-labels.html) 섹션을 참조하세요.**

   ```
   $ aws rekognition detect-moderation-labels \
       --image "S3Object={Bucket='{{bucket_name}}',Name='{{image_name}}'}" \
       --human-loop-config HumanLoopName="{{human_loop_name}}",FlowDefinitionArn="arn:aws:sagemaker:{{aws-region}}:{{aws_account_number}}:flow-definition/{{flow_def_name}}",DataAttributes='{ContentClassifiers=["FreeOfPersonallyIdentifiableInformation", "FreeOfAdultContent"]}'
   ```

   ```
   $ aws rekognition detect-moderation-labels \
       --image "S3Object={Bucket='{{bucket_name}}',Name='{{image_name}}'}" \
       --human-loop-config \
           '{"HumanLoopName": "{{human_loop_name}}", "FlowDefinitionArn": "arn:aws:sagemaker:{{aws-region}}:{{aws_account_number}}:flow-definition/{{flow_def_name}}", "DataAttributes": {"ContentClassifiers": ["FreeOfPersonallyIdentifiableInformation", "FreeOfAdultContent"]}}'
   ```

------

   `HumanLoopConfig`가 활성화된 상태로 `DetectModerationLabels`를 실행하면 Amazon Rekognition이 SageMaker AI API 작업 `StartHumanLoop`를 직접 호출합니다. 이 명령은 `DetectModerationLabels`에서 답변을 받고 예제의 흐름 정의 조건에 대해 확인합니다. 검토 조건을 충족하는 경우 `HumanLoopArn`을 반환합니다. 흐름 정의에서 설정한 작업 팀의 구성원은 이제 이미지를 검토할 수 있게 되었다는 의미입니다. Amazon Augmented AI 런타임 작업을 호출하면 `DescribeHumanLoop`는 루프의 결과에 대한 정보를 제공합니다. 자세한 내용은 *Amazon Augmented AI API 참조 설명서*의 [DescribeHumanLoop](https://docs.aws.amazon.com/augmented-ai/2019-11-07/APIReference/API_DescribeHumanLoop.html)를 참조하세요.

   이미지를 검토한 후에는 흐름 정의의 출력 경로에 지정된 버킷에서 결과를 확인할 수 있습니다. 또한 검토가 완료되면 Amazon A2I는 Amazon CloudWatch Events의 알림을 보냅니다. 어떤 이벤트를 찾아봐야 하는지 알아보려면 *SageMaker AI 설명서*에서 [CloudWatch 이벤트](https://docs.aws.amazon.com/sagemaker/latest/dg/augmented-ai-cloudwatch-events.html)를 참조하세요.

   자세한 내용은 *SageMaker AI 설명서*에서 [Amazon Augmented AI 시작하기](https://docs.aws.amazon.com/sagemaker/latest/dg/a2i-getting-started.html) 참조하세요.