Mole Analysis

Mole Analysis Use Case for HMS ML Kit Custom Model

Open Source Love svg3 hms-2022 mindsporeLite hms-mlkit mlkit-custom image-class

Kotlin Minimum SDK Version Android Gradle Version Gradle Version


What is Melanoma?

Melanoma is the most serious among skin cancers because it can spread to various parts of the body. Its incidence has also increased in our country and it has fatal results.The key to the treatment of this serious melanoma is early diagnosis. Providing this is simple: The person should detect the changes by self-controlling the moles in his body.Therefore, it is important for a person to be aware of the changes in the moles in his body and to follow them. We trained our model on cancerous me-cells using Huawei ML Kit Custom Model Generation with our Mole Analysis application, which will help you in your diagnosis and follow-up.

Sign of Melanoma?

Factors that may increase your risk of melanoma include: Fair skin, A history of sunburn, Excessive ultraviolet (UV) light exposure, Living closer to the equator or at a higher elevation, Having many moles or unusual moles, A family history of melanoma, Weakened immune system.

If you have one of the risk factors for melanoma, experts recommend doing a skin self-exam. One of the most common methods for detecting melanomas is the ABCDE method. Developed by doctors to help patients easily remember the symptoms of melanoma, it details the warning signs in moles that often indicate cancer. Monthly skin checks are important as most melanomas start as a new mole or skin growth.

How will the Mole Analysis app help me ?

Mole Analysis application is trained with Huawei ML Kit model with collected mole data. Although there is an accuracy rate of 89% according to Train and Test data, but also of course there is a possibility of error. The machine learning trained Mole Analysis app will give you an idea to detect your changes and get a preliminary idea by comparing it with the data it is trained on.

You can get an idea of the symptoms of melanoma with the Mole Analysis app, but it’s NOT a definitive diagnosis. We aim to provide early diagnosis and early diagnosis despite its potential risk. We recommend that you CONSULT A DOCTOR about the results for a definitive diagnosis.

About Huawei ML Kit

ML Kit allows your apps to easily leverage Huawei’s long-term proven expertise in machine learning to support diverse artificial intelligence (AI) applications throughout a wide range of industries. Thanks to Huawei’s technology accumulation, ML Kit provides diversified leading machine learning capabilities that are easy to use, helping you develop various AI apps. More..

Mindspore Lite

As an on-device inference framework of the custom model, the on-device inference framework MindSpore Lite provided by ML Kit facilitates integration and development and can be running on devices


  • It provides simple and complete APIs for you to integrate the inference framework of an on-device custom model. In this way, you can customize the model in the simplest and quickest way, providing you with excellent experience of machine learning.
  • It is compatible with all mainstream model inference platforms or frameworks, such as MindSpore Lite, TensorFlow Lite, Caffe, and Onnx in the market. Different models can be converted into the .ms format without any loss, and then run perfectly through the on-device inference framework.
  • Custom models occupy small storage space and can be quantized and compressed. Models can be quickly deployed and executed. In addition, models can be hosted on the cloud and downloaded as required, reducing the APK size.
  • The kernel code of the inference framework is open-source for global developers. It gathers the wisdom of global contributors to improve and continuously iterate itself. It not only brings you a friendly development ecosystem, but also is your mentor on the path of machine learning inference.

Model Preparation

Used Dataset

ISIC Melanoma Research Datasets The HAM10000 dataset


  1. Two labels were identified:
  • Benign: Non-cancerous
  • Malignant: Suspected of Melonama
  1. Incomprehensible data in the dataset has been cleared. (important to increase the success of the model, but challenge for the mole dataset)

  2. Data is foldered by labels

  3. The dataset is split into Train: 80%, Test: 20%. At the same time, a close number of data was separated according to the labels.

  • Train Dataset: 8k Benign, 8k Malignant image files
  • Test Dataset: 1.5k Benign, 1.5k Malignant image files

Getting Started

Development Enviroment

  • JDK version: 1.8.211 or later
  • Android Studio version: 3.X or later
  • minSdkVersion: 19 or later (mandatory)
  • targetSdkVersion: 30 (recommended)
  • compileSdkVersion: 30 (recommended)
  • Gradle version: 4.6 or later (recommended)
  • Test device: a Huawei phone running EMUI 5.0 or later, or a non-Huawei phone running

How To Start

  • Register a developer account on HUAWEI Developers and configure.
  • Register in to Huawei Developer Console and Create and configure an app
  • To use ML Kit, you need to enable it in AppGallery Connect. For details, please refer to Enabling Services.
  • Adding the AppGallery Connect Configuration File of Your App – Sign in to AppGallery Connect and click My projects. – Find your project and click the app for which you want to integrate the HMS Core SDK. – On the Project Setting page, set SHA-256 certificate fingerprint to the SHA-256 fingerprint you’ve generated. – Go to Project settings > General information. In the App information area, download the agconnect-services.json file.
  • Configuring the Maven Repository Address for the HMS Core SDK
  • Open the build.gradle file in the root directory of your Android Studio project.
  • Add the AppGallery Connect plugin and the Maven repository.

buildscript { 
    repositories { 
        // Configure the Maven repository address for the HMS Core SDK. 
        maven {url ''} 
    dependencies { 
        // Add the AppGallery Connect plugin configuration. You are advised to use the latest plugin version. 
        classpath 'com.huawei.agconnect:agcp:' 
allprojects { 
    repositories { 
        // Configure the Maven repository address for the HMS Core SDK. 
        maven {url ''} 

Adding Build Dependencies (app build gradle)

 implementation 'com.huawei.hms:base:'
    //HMS Custom Model
    implementation 'com.huawei.hms:ml-computer-model-executor:'
    implementation 'mindspore:mindspore-lite:'

Permissions ( AndroidManifest.xml )

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Important adding this aaptOptions for your model .ms file

aaptOptions {
        noCompress "ms", "mnn", "cambricon"
        cruncherEnabled false
        useNewCruncher false

ML Kit Model Training

Preparing the Environment


  1. Install the HMS Tool Kit plugin in Android Studio. Installation
  2. HMS Toolkit > Coding Assistant > AI > AI Create
  3. HMS Toolkit automatically downloads resources. 4- Python version should be 3.7.5 and Python environment variable to path. 5- The MindSpore tool is automatically installed. If the installation fails, the following dialog box is displayed, asking you whether to install it manually.

    • Open the command line tool to manually install MindSpore.
run pip install MindSpore installation file 

Model Training

  1. In Coding Assistant, go to AI > AI Create > Image.
  2. Drag or add the image classification folders to the Please select train image folder area, then set Output model file path and train parameters.
  3. Advanced
    • Iteration count: The default value is 100.
    • Learning rate: The default value is 0.01.
  4. Click Create Model to start training and generate an image classification model. Then you will see results:

Learning Results:

  1. After the model training is complete, you can verify the model by adding the image folders in the Add test image area


As with any machine learning project, the challenges and aspects of this project that need improvement:

  • Mole data is very difficult to distinguish
  • The process of cleaning the data is challenging
  • Analysis of no moles when irrelevant data is loaded
  • Importance of camera angle


The resources used in the development of the project are as follows:

License GitHub visitors Copyright © 2022


View Github