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.
| 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:
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:
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:
|
| 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:
|
| 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.
| 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.
In the porn scenario, label classifies pornographic elements (porn information or sexy information).
In the ad scenario, label indicates the advertisement detection result.
|
| 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." }
- 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.
Last Article: Moderation (Image)
Next Article: Image Moderation (Batch)
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.