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 Image Classification SDK

Integrating the Image Classification 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

Package Name

SDK Size

Storage Position

Model package + Algorithm package

ml-computer-vision-image-classification-model

6.1M

com.huawei.hms:ml-computer-vision-image-classification-model:1.0.4.300

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-classification:1.0.4.300'
  4.    // Import the image classification model package.
  5.    implementation 'com.huawei.hms:ml-computer-vision-image-classification-model:1.0.4.300'
  6. }

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-classification:1.0.4.300'
  3. }

Adding Configurations to the File Header

After integrating the SDK in either mode, 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= "label"/>
  6.    ...
  7. </manifest>
This page may contain third-party content. For details, click here.