Android#
Deploy to Android Studio#
MLange supports both for Kotlin and Java implementations.
Deploy your own On-device AI Android application easily.
There are only two steps are needed.
Add module dependency in your library
Initialize
ZeticMLangeModel
with your Model Key / Personal Key and run
Prerequisite#
Step-by-step Guideline#
1. Add ZeitcMLange
dependency#
You can choose
Groovy
build orKotlin DSL
buildbuild.gradle (Groovy)
android { ... packagingOptions { jniLibs { useLegacyPackaging true } } } dependencies { implementation 'com.zeticai.mlange:mlange:1.3.0' }
build.gradle.kts (Kotlin DSL)
android { ... packaging { jniLibs { useLegacyPackaging = true } } } dependencies { implementation("com.zeticai.mlange:mlange:1.3.0") }
2. Initialize and run ZeticMLangeModel
model with Model Key#
MLange supports both Kotlin and Java implementation
Zetic MLange model running (Java)
// 1. Zetic MLange model running // (1) Load Zetic MLange model ZeticMLangeModel model = new ZeticMLangeModel(CONTEXT, $PERSONAL_KEY, $MODEL_NAME); // (2) Prepare model inputs Tensor[] inputs = // Prepare your inputs; // (3) Run and get output buffers of the model Tensor[] outputs = model.run(inputs);
Zetic MLange model running (Kotlin)
// 1. Zetic MLange Model Running // (1) Load Zetic MLange model val model = ZeticMLangeModel(CONTEXT, $PERSONAL_KEY, $MODEL_NAME) // (2) Prepare model inputs val inputs: Array<Tensor> = // Prepare your inputs // (3) Run and get output tensors of the model val outputs = model.run(inputs)
ZETIC.MLange Android Sample App#
Please refer ZETIC MLange Apps for more details
(+) Additional API for MLange-Android usage#
As a default we set the model to use FP16 data type over NPU.
We set 2 more options for user to choose runtime mode for (1) Better output accuracy and (2) High-speed inference.
You can set model option while you load the model like sample code below.
// (1) Output Accuracy mode - `FP32 - (CPU, GPU)` mode val model = ZeticMLangeModel(CONTEXT, $PERSONAL_KEY, $MODEL_NAME, ZeticMLangeModel.ZETIC_MLANGE_RUN_MODE_FP32) // (2) High-speed inference mode - `Quantized - (NPU)` mode val model = ZeticMLangeModel(CONTEXT, $PERSONAL_KEY, $MODEL_NAME, ZeticMLangeModel.ZETIC_MLANGE_RUN_MODE_QUANTIZED)
// (1) Output Accuracy mode - `FP32 - (CPU, GPU)` mode ZeticMLangeModel model = new ZeticMLangeModel(CONTEXT, $PERSONAL_KEY, MODEL_NAME, ZeticMLangeModel.ZETIC_MLANGE_RUN_MODE_FP32); // (2) High-speed inference mode - `Quantized - (NPU)` mode ZeticMLangeModel model = new ZeticMLangeModel(CONTEXT, $PERSONAL_KEY, $MODEL_NAME, ZeticMLangeModel.ZETIC_MLANGE_RUN_MODE_QUANTIZED);