We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All

Documents from this version have been archived, and will not continue to be maintained. Please use the latest version.

HMS Core GuidesML KitPreparationsIntegrating the HMS SDKAdding Build DependenciesIntegrating the Face Detection SDK

Integrating the Face Detection SDK

ML Kit provides two SDK integration modes: full SDK and base SDK. You can select either one based on your needs. For details, please refer to Full SDK and base SDK in Overview.

Mode 1: Full SDK Integration (Recommended)

Integrate the base SDK package and then the model package. The following table describes the model package.

Expand

Package Type

Function

Package Name

SDK Size

Storage Position

Contour and key point detection model package

Detects the face contour and key points.

ml-computer-vision-face-shape-point-model

4.9M

com.huawei.hms:ml-computer-vision-face-shape-point-model:1.0.4.300

Facial expression detection model package

Detects facial expressions such as smiling and anger.

ml-computer-vision-face-emotion-model

2.8M

com.huawei.hms:ml-computer-vision-face-emotion-model:1.0.4.300

Facial feature detection model package

Detects facial features such as the age, gender possibility, and possibility of wearing a hat.

ml-computer-vision-face-feature-model

4.4M

com.huawei.hms:ml-computer-vision-face-feature-model:1.0.4.300

When you integrate the face detection model packages, the sizes of the integrated packages are greater than those listed in the preceding table because the algorithm package (about 6.4 MB) is automatically downloaded during integration.

The following is the sample code for integration in full SDK mode:

Collapse
Word wrap
Dark theme
Copy code
  1. dependencies{
  2.    // Import the base SDK.
  3.    implementation 'com.huawei.hms:ml-computer-vision-face:1.0.4.300'
  4.    // Import the contour and key point detection model package.
  5.    implementation 'com.huawei.hms:ml-computer-vision-face-shape-point-model:1.0.4.300'
  6.    // Import the facial expression detection model package.
  7.    implementation 'com.huawei.hms:ml-computer-vision-face-emotion-model:1.0.4.300'
  8.    // Import the facial feature detection model package.
  9.    implementation 'com.huawei.hms:ml-computer-vision-face-feature-model:1.0.4.300'
  10. }

Mode 2: Base SDK Integration

The sample code is as follows:

Collapse
Word wrap
Dark theme
Copy code
  1. dependencies{
  2.    implementation 'com.huawei.hms:ml-computer-vision-face:1.0.4.300'
  3. }

Adding Configurations to the File Header

After integrating the SDK, add the following configuration to the file header:

Collapse
Word wrap
Dark theme
Copy code
  1. apply plugin: 'com.huawei.agconnect'
Notice:

Add the configuration following the configuration item below:

Collapse
Word wrap
Dark theme
Copy code
  1. apply plugin: 'com.android.application'

Automatically Updating the Latest Machine Learning Model

To enable your app to automatically update the latest machine learning model on a device after the user installs your app downloaded from HUAWEI AppGallery, add the following statements to the AndroidManifest.xml file of your app:

Collapse
Word wrap
Dark theme
Copy code
  1. <manifest
  2.    ...
  3.    <meta-data              
  4.        android:name="com.huawei.hms.ml.DEPENDENCY"  
  5.        android:value= "face"/>
  6.    ...
  7. </manifest>


This page may contain third-party content. For details, click here.