Image Moderation (V2)
Function
This API analyzes and identifies whether the uploaded images contain pornographic elements or terrorism-related content, and returns the result to you.
- By default, the maximum number of concurrent API calls is 10. To increase concurrency, contact Huawei technical support.
- You can configure moderation rules to detect pornographic content in different scenarios. For details, see Configuring Moderation Rules.
URI
POST /v2/{project_id}/moderation/image
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
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
String |
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. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
url |
No |
String |
Configure either this parameter or image. 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. |
image |
No |
String |
Configure either this parameter or url. Indicates the Base64 character string converted from the image. The size cannot exceed 10 MB. The supported image formats include JPEG, PNG, BMP, WEBP, and GIF. |
moderation_rule |
No |
String |
Indicates the name of the moderation rule. The default rule is used by default.
NOTE:
For details about how to create and use moderation rules, see Configuring Moderation Rules. |
categories |
No |
Array of strings |
Indicates the detection scenario. The following scenarios are supported:
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 |
Float |
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:
|
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
result |
ImageDetectionResultBody object |
Indicates the calling result of a successful API call. This parameter is not included when the API fails to be called. |
Parameter |
Type |
Description |
---|---|---|
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 detail list is empty. |
suggestion |
String |
Indicates whether the check is passed.
NOTE:
|
category_suggestions |
Map<String,String> |
Indicates the check result of each scenario. Available values are as follows:
NOTE:
This service does not save your API calling results. |
Parameter |
Type |
Description |
---|---|---|
porn |
Array of ImageDetectionResultSimpleDetail objects |
Indicates that pornographic content was detected. |
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).
|
Status code: 400
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/v2/{project_id}/moderation/image, and project_id is the project ID. For details, see Obtaining a Project ID and Name.
- Method 1: Use the Base64 code of an uploaded image to check whether the image contains pornographic content. Use the default moderation rule.
POST https://{endpoint}/v2/{project_id}/moderation/image { "categories" : [ "porn" ], "moderation_rule" : "default", "url" : "", "image" : "/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAA...", "threshold" : "" }
- Method 2: Use the URL of an uploaded image to check whether the image contains pornographic content. Use the default moderation rule.
POST https://{endpoint}/v2/{project_id}/moderation/image { "categories" : [ "porn"], "moderation_rule" : "default", "url" : "https://BucketName.obs.myhuaweicloud.com/ObjectName", "image" : "", "threshold" : "" }
Example Responses
Status code: 200
Example of a successful response
{ "result": { "detail": { "porn": [ { "confidence": 0.7315528178215026, "label": "xxx" }, { "confidence": 0.26844718217849733, "label": "yyy" } ] }, "suggestion": "block", "category_suggestions": { "porn": "review" } } }
Status code: 400
Example of a failed response
{ "error_code" : "AIS.0402", "error_msg" : "The image format is not supported." }
Status Codes
Status Code |
Description |
---|---|
200 |
Example of a successful response |
400 |
Example of a failed response |
Error Codes
For details, see Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot