kony.ml Namespace
The koy.ml Namespace provides your app an ability to classify images taken from the camera, a file or the device gallery.
Functions
The kony.ml namespace provides the following function:
Creates an image classifier object. This object then helps to classify the images based on the trained model categories.
You can classify images captured using a camera, from a file or the device gallery.
Syntax
kony.ml.ImageClassifier(config);
Input Parameters
config: A JSON object that consists of configuration parameters.
The config parameter consists of the following keys:
Key | Value Type | Description |
---|---|---|
modelPath | String/ File |
Holds the name of the model. NOTE: File name must be given without extensions if modelPathSource type is MODEL_SOURCE_TYPE_BUNDLED. |
modelPathSource | Constant |
Source of the modelPath. This key contains any of the following constants.
|
onSuccess | Function |
Callback function that receives prediction results. function onSuccess(recognitionArray) Parameter recognitionArray: It is an array object holding prediction results. This array will hold only the top three results in the recognition objects. The values in these keys are read only. Each recognition object contains the following keys:
The recognitionArray is always sorted in a descending order based on the value provided in the confidence key. |
onFailure | Function |
Callback function that is invoked if any error occurs. function onFailure(errorCode) Parameters
|
modelInputSize | JSON object |
Models will be trained for various sizes of the image. This key takes input size for the model. The Input image given using the recognizeImage method is scaled to the provided values of the width and height of modelnputSize. The object contains below keys:
For example, modelInputSize = {"width": 224, "height": 224} |
modelType | Constant |
This is applicable to Android platform only. Models are of two types: Quantized and Float.This param provides information of the type of the model. It will contains any of the following constants:
|
labelPath | String/File |
This is applicable only to the Android platform. File name of the label's text file. This file contains the list of categories/labels on which the model was trained on. NOTE: File name must be given without extensions. |
labelPathSource | Constant |
This is applicable only to the Android platform. Must contain one of the below constants.
|
device | Constant |
This is applicable only to the Android platform. The runtime device type used for executing classification. Contain one of the following constants.
|
numOfThreads | Number |
This is applicable only to the Android platform. Sets the number of threads to be used for identifying the image. NOTE: You can increase the number of threads to speed up the process of identifying an image. Increasing the number of threads will, however, make your model use more resources and power. |
Example
//Sample code to create an image classifier object using TestingModel model. function successCallback(recognitionArray) { var size = recognitionArray.length; for (i = 0; i < size; i++) { kony.print(recognitionArray[i].title + "--------->" + recognitionArray[i].confidence); } } function failureCallback(errorCode) { alert(errorCode); } var config = { "modelPath": TestingModel, "modelPathSource": kony.ml.LABEL_SOURCE_TYPE_BUNDLED, "onSuccess": successCallback, "onFailure": failureCallback, "modelInputSize": { "width": 224, "height": 224 }, "labelPath": sample.txt, "labelPathSource": kony.ml.LABEL_SOURCE_TYPE_BUNDLED, "device": kony.ml.MODEL_DEVICE_CPU, "modelType": kony.ml.MODEL_TYPE_QUANTIZED } var imageClassifier = new kony.ml.imageClassifier(config);
Platform Availability
- iOS
- Android