Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Moderation (Image)

Updated on 2022-12-05 GMT+08:00

This section provides an example of how to use a Java SDK to call Moderation (Image). You can directly call APIs to use SDK functions. The procedure is as follows:

Step 1: Subscribe to a Service. In the left navigation pane, choose Service List or Service Management, and subscribe to Moderation (Image).

(Optional) Step 2: Enable Object Storage Service (OBS) Authorization. If you want to use the data stored on OBS, enable OBS authorization.

Step 3: (Optional) Configure a Moderation Rule. Detect pornographic content in different scenarios.

Step 4: Configure the Environment. Obtain the SDK and sample project and import them to the development environment.

Step 5: Perform Authentication. Use AK/SK for authentication.

Step 6: Call a Service API. Call the service API. You can view the status code and error code at any time during the usage.

Step 1: Subscribe to a Service

Subscribe to Moderation (Image) by following the instructions in Subscribing to the Service.

(Optional) Step 2: Enable Object Storage Service (OBS) Authorization

If you want to use the data stored on OBS, enable OBS authorization. The procedure is as follows:

  1. Log in to the management console and choose Service List > Content Moderation. In the navigation pane, choose Service Management.
  2. Enable OBS Authorization.
    NOTE:
    • The region of OBS must be consistent with that of Content Moderation.
    • OBS authorization must be performed by an account, not by an IAM user.
    • Once enabled, OBS authorization cannot be disabled.

Step 3: (Optional) Configure a Moderation Rule

You can configure review rules to detect pornographic content in different scenarios. For details, see Configuring Moderation Rules.

Step 4: Configure the Environment

You can compile code to call the API of Moderation (Text) based on the SDK. You need to configure the environment when using the SDK and calling APIs. The procedure is as follows:

  1. To obtain the SDK and related document of Content Moderation, click here.
  2. For details about how to configure the environment, see Preparing a Java Development Environment.
  3. Import an SDK project on Eclipse.

    1. Open Eclipse and configure the correct JRE path in Windows > Preferences > Java > Installed JREs.
    2. In the navigation pane on the left, choose General > Workspace. In the Text file encoding area, select Other, set the parameter value to UTF-8, click Apply, and click OK.
    3. On the Eclipse menu bar, choose File > Import. In the dialog box that is displayed, choose Maven > Existing Maven Projects, click Next, click Browse, and select the local path where ais-moderation-java-sdk resides.
    4. Click Finish to import the SDK. After the SDK is imported, open the project. Figure 1 shows the project directory.
      Figure 1 Project directory

Step 5: Perform Authentication

Content Moderation supports token-based and AK/SK-based authentication. This section uses AK/SK-based authentication as an example.

  1. Obtain an AK/SK.

    The AK/SK is the access key. To obtain the AK/SK, log in to the My Credentials page, choose Access Keys in the left navigation pane, and click Create Access Key in the right pane.

    Figure 2 Creating an access key

  2. Configure the AK/SK in the Java SDK for AK/SK authentication.

    Change the values of AK and SK of the function in the ModerationImageContentDemo.java file of the project to the obtained AK/SK. The sample code is as follows:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    // 1. Configure the basic information for accessing Image Moderation and generate a client connection object.
    AisAccess service = ServiceAccessBuilder.builder()		
            .ak("######")                       // your ak
            .sk("######")                       // your sk
           .region("ap-southeast-1")           // Content Moderation in CN-Hong Kong (ap-southeast-1) and AP-Singapore (ap-southeast-3)
            .connectionTimeout(5000)            // Timeout limit for connecting to the target URL
            .connectionRequestTimeout(1000)     // Timeout limit for obtaining available connections from the connection pool
            .socketTimeout(20000)               // Timeout limit for obtaining server response data
            .build();
    

Step 6: Call a Service API

  1. Select a local image or use the default image of the sample project, and modify the image file path (data/moderation-demo-1.jpg) in the ModerationImageContentDemo.java file.

    1
    2
    3
    4
    5
    6
    public static void main(String[] args) throws IOException {
    	ModerationImageContentDemo tool = new ModerationImageContentDemo();
    	tool.imageContentCheck("https://sdk-obs-source-save.obs.cn-north-4.myhuaweicloud.com/XXX.jpg");
    	byte[] imageBytes = FileUtils.readFileToByteArray(new File("data/moderation-demo-1.jpg"));
    	tool.imageContentCheck(imageBytes);
    	}
    

  2. Execute the ModerationImageContentDemo.java file. If 200 is displayed on the console, the program is successfully executed. The image moderation result is displayed on the console. See Figure 3.

    Figure 3 Execution result

  3. View the number of API calls. Choose Service List > Image Moderation, and view call statistics and call details. See Figure 4.

    Figure 4 Call statistics
    • The Call Statistics section provides three statistical charts, displaying daily calls, daily blocked text, and daily reviewed text. You can set a time range to view the change of the number of API calls within the time range.
    • The Call Details section lists the total number of calls, blocks, reviews, and passes every day. You can click Export to download and view the total number of API calls, helping you better understand the service calling and review status.
    • Images are stored in OBS buckets. Therefore, the images that are determined as block or review images cannot be exported.
      NOTE:
      • block indicates that sensitive information is contained and the information is blocked.
      • pass indicates that sensitive information is not contained and the information is approved.
      • review indicates that manual review is required.

  4. View monitoring metrics. You can click View Metric to view historical data such as successful and failed calls on the Cloud Eye console. See Figure 5.

    Figure 5 Viewing metrics

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback