Skip to content

detect_moderation_labels async

detect_moderation_labels(
    image: Image,
    *,
    config_overrides: Optional[AsyncRekognitionClientConfig] = None,
    min_confidence: Optional[Percent] = None,
    human_loop_config: Optional[HumanLoopConfig] = None,
    project_version: Optional[ProjectVersionId] = None,
) -> DetectModerationLabelsResponse

Detects unsafe content in a specified JPEG or PNG format image. Use DetectModerationLabels to moderate images depending on your requirements. For example, you might want to filter images that contain nudity, but not images containing suggestive content.

To filter images, use the labels returned by DetectModerationLabels to determine which types of content are appropriate.

For information about moderation labels, see Detecting Unsafe Content in the Amazon Rekognition Developer Guide.

You pass the input image either as base64-encoded image bytes or as a reference to an image in an Amazon S3 bucket. If you use the AWS CLI to call Amazon Rekognition operations, passing image bytes is not supported. The image must be either a PNG or JPEG formatted file.

You can specify an adapter to use when retrieving label predictions by providing a ProjectVersionArn to the ProjectVersion argument.

Parameters:

  • image (Image) –

    The input image as base64-encoded bytes or an S3 object. If you use the AWS CLI to call Amazon Rekognition operations, passing base64-encoded image bytes is not supported.

    If you are using an AWS SDK to call Amazon Rekognition, you might not need to base64-encode image bytes passed using the Bytes field. For more information, see Images in the Amazon Rekognition developer guide.

  • min_confidence (Optional[Percent], default: None ) –

    Specifies the minimum confidence level for the labels to return. Amazon Rekognition doesn't return any labels with a confidence level lower than this specified value.

    If you don't specify MinConfidence, the operation returns labels with confidence values greater than or equal to 50 percent.

  • human_loop_config (Optional[HumanLoopConfig], default: None ) –

    Sets up the configuration for human evaluation, including the FlowDefinition the image will be sent to.

  • project_version (Optional[ProjectVersionId], default: None ) –

    Identifier for the custom adapter. Expects the ProjectVersionArn as a value. Use the CreateProject or CreateProjectVersion APIs to create a custom adapter.

Raises:

  • AccessDeniedException –

    You are not authorized to perform the action.

  • HumanLoopQuotaExceededException –

    The number of in-progress human reviews you have has exceeded the number allowed.

  • ImageTooLargeException –

    The input image size exceeds the allowed limit. If you are calling DetectProtectiveEquipment, the image size or resolution exceeds the allowed limit. For more information, see Guidelines and quotas in Amazon Rekognition in the Amazon Rekognition Developer Guide.

  • InternalServerError –

    Amazon Rekognition experienced a service issue. Try your call again.

  • InvalidImageFormatException –

    The provided image format is not supported.

  • InvalidParameterException –

    Input parameter violated a constraint. Validate your parameter before calling the API operation again.

  • InvalidS3ObjectException –

    Amazon Rekognition is unable to access the S3 object specified in the request.

  • ProvisionedThroughputExceededException –

    The number of requests exceeded your throughput limit. If you want to increase this limit, contact Amazon Rekognition.

  • ResourceNotFoundException –

    The resource specified in the request cannot be found.

  • ResourceNotReadyException –

    The requested resource isn't ready. For example, this exception occurs when you call DetectCustomLabels with a model version that isn't deployed.

  • ThrottlingException –

    Amazon Rekognition is temporarily unable to process the request. Try your call again.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_rekognition/_services/async_rekognition.py
async def detect_moderation_labels(
    self,
    image: "capo_rekognition.types.image.Image",
    *,
    config_overrides: Optional[AsyncRekognitionClientConfig] = None,
    min_confidence: Optional["capo_rekognition.types.percent.Percent"] = None,
    human_loop_config: Optional[
        "capo_rekognition.types.human_loop_config.HumanLoopConfig"
    ] = None,
    project_version: Optional[
        "capo_rekognition.types.project_version_id.ProjectVersionId"
    ] = None,
) -> "capo_rekognition.types.detect_moderation_labels_response.DetectModerationLabelsResponse":
    """<p>Detects unsafe content in a specified JPEG or PNG format image. Use <code>DetectModerationLabels</code> to moderate images depending on your requirements. For example, you might want to filter images that contain nudity, but not images containing suggestive content.</p> <p>To filter images, use the labels returned by <code>DetectModerationLabels</code> to determine which types of content are appropriate.</p> <p>For information about moderation labels, see Detecting Unsafe Content in the Amazon Rekognition Developer Guide.</p> <p>You pass the input image either as base64-encoded image bytes or as a reference to an image in an Amazon S3 bucket. If you use the AWS CLI to call Amazon Rekognition operations, passing image bytes is not supported. The image must be either a PNG or JPEG formatted file. </p> <p>You can specify an adapter to use when retrieving label predictions by providing a <code>ProjectVersionArn</code> to the <code>ProjectVersion</code> argument.</p>

    Args:
        image: <p>The input image as base64-encoded bytes or an S3 object. If you use the AWS CLI to call Amazon Rekognition operations, passing base64-encoded image bytes is not supported. </p> <p>If you are using an AWS SDK to call Amazon Rekognition, you might not need to base64-encode image bytes passed using the <code>Bytes</code> field. For more information, see Images in the Amazon Rekognition developer guide.</p>
        min_confidence: <p>Specifies the minimum confidence level for the labels to return. Amazon Rekognition doesn't return any labels with a confidence level lower than this specified value.</p> <p>If you don't specify <code>MinConfidence</code>, the operation returns labels with confidence values greater than or equal to 50 percent.</p>
        human_loop_config: <p>Sets up the configuration for human evaluation, including the FlowDefinition the image will be sent to.</p>
        project_version: <p>Identifier for the custom adapter. Expects the ProjectVersionArn as a value. Use the CreateProject or CreateProjectVersion APIs to create a custom adapter.</p>

    Raises:
        capo_rekognition.errors.access_denied_exception.AccessDeniedException: <p>You are not authorized to perform the action.</p>
        capo_rekognition.errors.human_loop_quota_exceeded_exception.HumanLoopQuotaExceededException: <p>The number of in-progress human reviews you have has exceeded the number allowed.</p>
        capo_rekognition.errors.image_too_large_exception.ImageTooLargeException: <p>The input image size exceeds the allowed limit. If you are calling DetectProtectiveEquipment, the image size or resolution exceeds the allowed limit. For more information, see Guidelines and quotas in Amazon Rekognition in the Amazon Rekognition Developer Guide. </p>
        capo_rekognition.errors.internal_server_error.InternalServerError: <p>Amazon Rekognition experienced a service issue. Try your call again.</p>
        capo_rekognition.errors.invalid_image_format_exception.InvalidImageFormatException: <p>The provided image format is not supported. </p>
        capo_rekognition.errors.invalid_parameter_exception.InvalidParameterException: <p>Input parameter violated a constraint. Validate your parameter before calling the API operation again.</p>
        capo_rekognition.errors.invalid_s3_object_exception.InvalidS3ObjectException: <p>Amazon Rekognition is unable to access the S3 object specified in the request.</p>
        capo_rekognition.errors.provisioned_throughput_exceeded_exception.ProvisionedThroughputExceededException: <p>The number of requests exceeded your throughput limit. If you want to increase this limit, contact Amazon Rekognition.</p>
        capo_rekognition.errors.resource_not_found_exception.ResourceNotFoundException: <p>The resource specified in the request cannot be found.</p>
        capo_rekognition.errors.resource_not_ready_exception.ResourceNotReadyException: <p>The requested resource isn't ready. For example, this exception occurs when you call <code>DetectCustomLabels</code> with a model version that isn't deployed. </p>
        capo_rekognition.errors.throttling_exception.ThrottlingException: <p>Amazon Rekognition is temporarily unable to process the request. Try your call again.</p>
        capo_rekognition.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_rekognition.types.detect_moderation_labels_request.DetectModerationLabelsRequest]",
    ) -> AsyncOperationResponse[
        "capo_rekognition.types.detect_moderation_labels_response.DetectModerationLabelsResponse"
    ]:
        import capo_rekognition._operations.rekognition_service.detect_moderation_labels

        (
            output,
            http_response,
        ) = await capo_rekognition._operations.rekognition_service.detect_moderation_labels.async_detect_moderation_labels(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("DetectModerationLabels")
    )
    input_: capo_rekognition.types.detect_moderation_labels_request.DetectModerationLabelsRequest = {
        "image": image
    }
    if min_confidence is not None:
        input_["min_confidence"] = min_confidence
    if human_loop_config is not None:
        input_["human_loop_config"] = human_loop_config
    if project_version is not None:
        input_["project_version"] = project_version

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output