Updated on 2024-03-27 GMT+08:00

Image Moderation (Batch) (V2)

Function

This API analyzes and identifies whether the uploaded images contain pornographic elements, and returns the result to you.

URI

POST /v2/{project_id}/moderation/image/batch

Table 1 Path parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Indicates the user token.

Used to obtain the permission to operate APIs. For details about how to obtain the token, see Authentication. The value of X-Subject-Token in the response header is the token.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

urls

Yes

Array of strings

Indicates the URL of an image. The options are as follows:

  • HTTP/HTTPS URLs on the public network
  • HUAWEI CLOUD OBS URLs. To use OBS data, authorization is required, including service authorization, temporary authorization, and anonymous public authorization. For details, see Configuring the Access Permission of OBS.
NOTE:

You can configure a maximum of 10 URLs. The API response time depends on the image download time. If the image download takes a long time, the API call will fail. Ensure that the storage service where the image to be detected resides is stable and reliable. You are advised to use HUAWEI CLOUD OBS.

categories

No

Array of strings

Indicates the detection scenario. Possible values are as follows:

  • porn: pornographic elements

You can set the parameter to the preceding values to check the corresponding elements.

NOTE:

The number of detection times in each scenario is calculated by category.

threshold

No

Double

Indicates the threshold for filtering the detection results. Only the results whose confidence score is greater than or equal to the threshold are displayed in the detail list. The value ranges from 0 to 1. If this parameter is left unspecified, the default values of different scenarios are used.

If there is no special requirement, do not pass this parameter, or leave this parameter unspecified as shown in the example request.

NOTE:
  1. If the maximum confidence score of a specific detection scenario is smaller than the value of threshold, the detail list is empty. If the value of threshold is too small, too many results are displayed in the detail list.
  2. The threshold parameter does not support filtering of the porn scenario.
  3. The threshold parameter does not affect the suggestion in the response.

moderation_rule

No

String

Indicates the name of the moderation rule. The default value is default.

NOTE:

For details about how to create and use moderation rules, see Configuring Moderation Rules.

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

result

Array of ImageBatchModerationResultBody objects

Indicates the calling result of a successful API call. This parameter is not included when the API fails to be called.

Table 5 ImageBatchModerationResultBody parameters

Parameter

Type

Description

url

String

Indicates the URL of an image.

suggestion

String

Indicates whether the images pass the check.

  • block: The images contain sensitive information and fail to pass the check.
  • pass: indicates that no sensitive information is detected and the information passes the check.
  • review: The images need to be manually reviewed.
NOTE:
  1. When multiple scenarios are detected at the same time, the value of suggestion is subject to the scenario where sensitive information is most likely to be contained. That is, if a block occurs in any scenario, the value of suggestion is block. If all scenarios pass the check, the value of suggestion is pass. In addition, if manual review is required in any scenario, the value of suggestion is review.
  2. This service does not save your API call results (such as historical block information). You are advised to retain the logs of API call results.

detail

ImageDetectionResultDetail object

Indicates a list of detection results of a specific scenario. porn lists the detection results of pornographic elements. If the maximum confidence score of a specific detection scenario is smaller than the value of threshold, the list of detection results is empty.

category_suggestions

Object

Indicates the check result of each scenario. Possible values are as follows:

  • block: indicates that sensitive information is detected and the information fails to pass the check.
  • pass: indicates that no sensitive information is detected and the information passes the check.
  • review: indicates that the image needs to be manually reviewed.
Table 6 ImageDetectionResultDetail parameters

Parameter

Type

Description

porn

Array of ImageDetectionResultSimpleDetail objects

Indicates that pornographic content was detected.

Table 7 ImageDetectionResultSimpleDetail parameters

Parameter

Type

Description

confidence

Float

Indicates the confidence score. The value ranges from 0 to 1.

label

String

Indicates the label of each detection result. The options are as follows:

In the porn scenario, label indicates pornographic elements (porn information or suggestive content).

  • The porn scenario supports the following labels:
    • normal: The uploaded image does not contain pornography.
    • porn: The image contains porn information.
    • sexy: The image contains suggestive content.

Status code: 400

Table 8 Response body parameters

Parameter

Type

Description

error_code

String

Indicates the error code of a failed API call. For details, see Error Codes.

This parameter is not included when the API is successfully called.

error_msg

String

Indicates the error message of a failed API call.

This parameter is not included when the API is successfully called.

fail_category

String

Indicates the API calling failure scenario when there are multiple scenarios.

Example Requests

endpoint is the request URL for calling an API. Endpoints vary depending on services and regions. For details, see Endpoints.

For example, the endpoint of the service deployed in the CN-Hong Kong region is moderation.ap-southeast-1.myhuaweicloud.com, the request URL is https://moderation.ap-southeast-1.myhuaweicloud.com/v3/{project_id}/moderation/image/batch, and project_id is the project ID. For details, see Obtaining a Project ID and Name.

Check whether an uploaded image contains pornographic or terrorism-related content.

POST https://{endpoint}/v2/{project_id}/moderation/image/batch

{
  "urls" : [ "https://bucketname.obs.myhwclouds.com/ObjectName1", "https://bucketname.obs.myhwclouds.com/ObjectName2" ],
  "categories" : [  "terrorism", "porn" ],
  "threshold" : ""
}

Example Responses

Status code: 200

Example of a successful response

{
  "result" : [ {
    "url" : "https://BucketName.obs.myhuaweicloud.com/ObjectName1",
    "suggestion" : "block",
    "detail" : {
      "porn" : [ {
        "confidence" : 1,
        "label" : "normal"
      }, {
        "confidence" : 0.5684471821784973,
        "label" : "porn"
      }, {
        "confidence" : 0,
        "label" : "sexy"
      } ]
    }
  } ]
}

Status code: 400

Example of a failed response

{
  "error_code" : "AIS.0005",
  "error_msg" : "The service does not exist."
}

Status Codes

Status Code

Description

200

Example of a successful response

400

Example of a failed response

Error Codes

For details, see Error Codes.