Image Moderation

Function

This API analyzes and identifies whether the uploaded images contain pornographic elements, political figures, or terrorism-related content, and returns the result to you.

Prerequisites

  • Before using Image Moderation, you need to apply for the service and complete authentication. For details, see Getting Started with Moderation (Image).
  • By default, the maximum number of concurrent API calls is 10. To increase concurrency, contact Huawei technical support.

URI

URI format

POST /v1.0/moderation/image

Request Message

Table 1 describes the request parameters.

Table 1 Request parameters

Parameter

Mandatory

Type

Description

image

Configure either this parameter or url.

String

Indicates the Base64 character string converted from the image. The size cannot exceed 10 MB.

The face of a political figure must contain at least 50 x 50 pixels.

The supported image formats include JPG, PNG, and BMP.

url

Configure either this parameter or image.

String

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:

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

Indicates the detection scenario. Possible values are as follows:

  • politics: checks whether political figures exist.
  • terrorism: checks whether terrorism-related content or sensitive political information exists.
  • porn: checks whether pornographic content exist.
  • ad: checks whether advertisements exist.
  • all: checks all elements in the politics, terrorism, and porn scenarios.

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

If this parameter is left blank or does not exist, both politics and terrorism scenarios are checked, but the porn scenario is not included.

NOTE:

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

ad_categories

No

Array

Indicates the scenario of text moderation for images. This parameter is valid only when the values of categories contain ad.

The following scenarios are supported:
  • System-defined scenario:
    • qr_code: QR code detection
    • politics: sensitive political information detection
    • porn: pornographic information detection
    • ad: advertisement detection
    • abuse: offensive content detection
    • contraband: contraband information detection
  • User-defined scenario: custom blacklist dictionary
    NOTE:

threshold

No

Number

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.

The default value of the politics scenario is 0.95.

The default value of the terrorism scenario is 0.

The default value of the ad scenario is 0.

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

NOTE:
  • 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.
  • The threshold parameter does not support filtering of the porn scenario.
  • The threshold parameter does not affect the suggestion in the response.

moderation_rule

No

String

Name of the review rule. The default rule is used by default.

NOTE:

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

Response Message

Table 2 describes the response parameters.

Table 2 Response parameters

Parameter

Type

Description

result

Object

Indicates the calling result when the API is successfully called.

This parameter is not included when the API fails to be called.

detail

Object

Indicates a list of detection results of a specific scenario. politics lists the detection results of political figures, terrorism lists the detection results of terrorism-related content or sensitive political information, and 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 detail list is empty.

confidence

Number

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

face_detail

Object

Indicates the facial information in the politics scenario, including the following four attributes:

h: indicates the height of the face area.

w: indicates the width of the face area.

x: indicates the distance from the upper left corner of the face area to the y axis.

y: indicates the distance from the upper left corner of the face area to the x axis.

label

String

Indicates the label of each detection result. Possible values are as follows:

In the politics scenario, label indicates the information about the corresponding political figure.

In the terrorism scenario, label indicates the information about the terrorism-related elements or sensitive political information.
  • Currently, the terrorism scenario supports the following labels:
    • normal: indicates that the image does not contain terrorism-related elements.
    • knife: indicates that the image contains a knife.
    • gun: indicates that the image contains a gun.
    • fire: indicates that the image contains the fire.
    • bloody: indicates that the image contains a bloody scene.
    • terrorist: indicates that the image contains a terrorist organization and symbol.
    • fascist: indicates that the image contains a fascist organization and symbol.
    • cult: indicates that the image contains a heretical organization and symbol.
    • negative_politics: indicates that the image contains a negative political organization and symbol.
    • negative_political_events: indicates that the image contains a sensitive political event and symbol.
    • special_characters: indicates that the image contains special characters.
    • kidnap: indicates that the image contains kidnapping.
    • corpse: indicates that the image contains a corpse.
    • riot: indicates that the image contains a riot.
    • parade: indicates that the image contains a demonstration.
    • sensitive_landmarks: indicates that the image contains a sensitive landmark.
    • military_weapon: indicates that the image contains a military weapon.
    • army: indicates that the image contains police force.
    • positive_politics: indicates that the image contains a positive political organization and symbol.
    • crowd: indicates that the image contains crowd.

In the porn scenario, label classifies pornographic elements (porn information or sexy information).

  • Currently, the porn scenario supports the following labels:
    • normal: indicates that the image does not contain pornographic elements.
    • porn: indicates that the image contains pornographic elements.
    • sexy: indicates that the image contains suggestive content.

In the ad scenario, label indicates the advertisement detection result.

  • The ad scenario supports the following labels:
    • normal: indicates that the image does not contain advertisement-related elements.
    • ad: indicates that the image contains advertisement-related elements.
  • The scenario of text moderation for images supports the following labels:
    • normal: The image does not contain advertisement-related elements.
    • qr_code: The image contains a QR code.
    • politics: The image contains sensitive political information.
    • porn: The image contains pornographic information.
    • ad: The image contains advertisement-related elements.
    • abuse: The image contains offensive content.
    • contraband: The image contains contraband information.
    • Items in the custom blacklist dictionary

hit_contexts

Array

Texts detected during text moderation for images

suggestion

String

Indicates whether the check is passed.

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.

NOTE:

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 included. 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.

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.

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.

Examples

  • Example request (Method 1: Use a Base64-encoded image.)
    POST https://moderation.cn-north-1.myhuaweicloud.com/v1.0/moderation/image
        
    Request Header:      
    Content-Type:application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...   
    Request Body:
    {  
       "url" : "",
       "image" : "/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAA...",
       "categories":[  
          "politics",
          "terrorism",
          "ad"
       ],
       "ad_glossaries":[
          "glossary_01",
          "glossary_02"
       ],
       "ad_categories":[  
          "qr_code",
          "politics",
          "abuse",
          "porn",
          "ad",
          "contraband"
       ],
       "threshold" : ""
    }
  • Example request (Method 2: Use the URL redirecting to the image file.)
    POST https://moderation.cn-north-1.myhuaweicloud.com/v1.0/moderation/image
        
    Request Header:      
    Content-Type:application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...   
    Request Body:
    {  
       "url" : "https://BucketName.obs.myhuaweicloud.com/ObjectName",
       "image" : "",
       "categories":[  
          "politics",
          "terrorism",
          "ad"
       ],
       "ad_glossaries":[
          "glossary_01",
          "glossary_02"
       ],
       "ad_categories":[  
          "qr_code",
          "politics",
          "abuse",
          "porn",
          "ad",
          "contraband"
       ],
       "threshold" : ""
    }
  • Example successful response
    {  
       "result":{
          "detail":{
             "politics":[
                {  
                   "confidence": 0.89155281782150264,
                   "face_detail":{
                       "h": 130,
                       "w": 103,
                       "x": 80,
                       "y": 125
                    },
                   "label": "xxx"
                },
                {
                   "confidence": 0.87563462432654422,
                   "face_detail":{
                       "h": 131,
                       "w": 203,
                       "x": 423,
                       "y": 109
                    },
                   "label": "yyy"
                }
             ],
             "terrorism":[
                {  
                   "confidence": 0.73155281782150264,
                   "label": "xxx"
                },
                {
                   "confidence": 0.26844718217849736,
                   "label": "yyy"
                }
             ],
             "ad":[
                {  
                   "hit_contexts": [
                      "xxx",
    	          "xx"
                   ],
                   "confidence": 1,
                   "label": "politics"
                },
                {
                   "confidence": 0,
                   "label": "ad"
                },
                {
                   "confidence": 0.998,
                   "label": "qr_code"
                },
                {
                   "confidence": 0,
                   "label": "normal"
                }
             ]
          },
          "suggestion": "block",
          "category_suggestions": {
                "politics":"block",
                "terrorism":"review",
                "ad":"block"
          }
       }
    }
  • Example failed response
    {
        "error_code": "AIS.0005",
        "error_msg": "The service does not exist."
    }

Status Code

  • Normal

    200

  • Abnormal

    Return Value

    Description

    400

    • The request cannot be understood by the server due to malformed syntax. The client should not repeat the request without modifications.
    • The request parameter is incorrect.

    401

    The request requires user authentication.

    403

    No operation permission.

    404

    The server has not found anything matching the Request-URI.

    500

    The server encountered an unexpected condition which prevented it from fulfilling the request.