使用 Amazon Augmented AI 审核不当内容 - Amazon Rekognition

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

使用 Amazon Augmented AI 审核不当内容

通过 Amazon Augmented AI (Amazon A2I),您可以构建人工审核机器学习预测所需的工作流程。

Amazon Rekognition 可直接与 Amazon A2I 集成,以便您轻松实施人工审核,检测出不安全图像的使用案例。Amazon A2I 提供了用于图像监管的人工审核工作流程。这样一来,您可以从 Amazon Rekognition 轻松审核预测。您可以为使用案例定义置信度阈值,并随着时间的推移进行调整。借助 Amazon A2I,您可以使用自己的组织或 Amazon Mechanical Turk 中的审核人员池。您还可以使用经 AWS 预先筛选的供应商队伍,以确保质量和遵守安全程序。

以下步骤将指导您如何设置 Amazon A2I 和 Amazon Rekognition。首先,使用 Amazon A2I 创建具有人工审核触发条件的流定义。然后,将流定义的 Amazon 资源名称 (ARN) 传递给 Amazon Rekognition DetectModerationLabel 操作。在 DetectModerationLabel 响应中,可以看到是否需要人工审核。人工审核的结果位于流定义设置的 Amazon S3 存储桶中。

要查看如何将 Amazon A2I 与 Amazon Rekognition 结合使用的端到端演示,请参阅《Amazon SageMaker 开发人员指南》中的以下教程之一。

使用 Amazon A2I 运行 DetectModerationLabels
注意

在同一 AWS 区域中创建所有 Amazon A2I 资源和 Amazon Rekognition 资源。

  1. 完成《SageMaker 文档》中开始使用 Amazon Augmented AI 列出的先决条件。

    此外,请记得按照《SageMaker 文档》中 Amazon Augmented AI 中的权限和安全性页面设置您的 IAM 权限。

  2. 按照《SageMaker 文档》中有关创建人工审核工作流程的说明进行操作。

    人工审核工作流程用于管理图像的处理。它包含触发人工审核的条件、图像发送到的工作团队、工作团队使用的 UI 模板,以及工作团队的结果发送到的 Amazon S3 存储桶。

    CreateFlowDefinition 调用中,必须将 HumanLoopRequestSource 设置为“AWS/Rekognition/DetectModerationLabels/Image/V3”。之后,您需要决定希望如何设置人工审核的触发条件。

    Amazon Rekognition 为 ConditionType 提供了两个选项:ModerationLabelConfidenceCheckSampling

    当审核标签的置信度在一定范围内时,ModerationLabelConfidenceCheck 会创建人工循环。最后,Sampling 会发送随机比例的已处理文档供人工审核。每个 ConditionType 会使用一组不同的 ConditionParameters 来设置人工审核中的结果。

    ModerationLabelConfidenceCheck 具有 ConditionParameters ModerationLableName,用于设置需要人工审核的键。此外,它还具有置信度,用于设置发送到人工审核的百分比范围:LessThan、GreaterThan 和 Equals。Sampling 具有 RandomSamplingPercentage,用于设置将发送到人工审核的文档的百分比。

    以下代码示例是 CreateFlowDefinition 的部分调用。如果图像在标签“暗示”上的评级低于 98%,并且在标签“女性泳装或内衣”上的评级高于 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 将返回 FlowDefinitionArn,您在下一步中调用 DetectModerationLabels 时可使用该 ARN。

    有关更多信息,请参阅《SageMaker API 参考》中的 CreateWorkGroup

  3. 调用 DetectModerationLabels 时,请设置 HumanLoopConfig 参数,如检测不当图像中所述。有关带有 HumanLoopConfig 设置的 DetectModerationLabels 调用示例,请参阅步骤 4。

    1. HumanLoopConfig 参数中,将 FlowDefinitionArn 设置为在步骤 2 中创建的流定义的 ARN。

    2. 设置 HumanLoopName。此名称在区域内应该是唯一的,并且必须采用小写。

    3. (可选)可以使用 DataAttributes 参数,设置传递到 Amazon Rekognition 的图像是否不包含个人身份信息。必须设置此参数才能将信息发送到 Amazon Mechanical Turk。

  4. 运行 DetectModerationLabels

    以下示例向您演示如何结合使用 AWS CLI 和 AWS SDK for Python (Boto3) 来运行 DetectModerationLabelsHumanLoopConfig 设置。

    AWS SDK for Python (Boto3)

    以下请求示例使用适用于 Python (Boto3) 的 SDK。有关更多信息,请参阅《AWS SDK for Python (Boto) API 参考》中的 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 命令参考》中的 detect-moderation-labels

    $ 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"]}}'

    如果运行 DetectModerationLabels 时启用了 HumanLoopConfig,则 Amazon Rekognition 将调用 SageMaker API 操作 StartHumanLoop。此命令从 DetectModerationLabels 获取响应,并根据示例中的流定义条件对其进行检查。如果符合审核条件,则返回 HumanLoopArn。这表示您在流程定义中设置的工作团队成员现在可以审核该图像。调用 Amazon Augmented AI 运行时系统操作 DescribeHumanLoop 可提供有关循环的结果的信息。有关更多信息,请参阅《Amazon Augmented AI API 参考文档》中的 DescribeHumanLoop

    图像经审核后,可以在流定义输出路径中指定的存储桶中看到结果。审核完成后,Amazon A2I 还将通过 Amazon CloudWatch Events 向您发出通知。要查看要查找的事件,请参阅《SageMaker 文档》中的 CloudWatch Events

    有关更多信息,请参阅《SageMaker 文档》中的开始使用 Amazon Augmented AI