voltmx.ml Namespace
The voltmx.ml Namespace provides your app an ability to classify images taken from the camera, a file or the device gallery.
Functions
The voltmx.ml namespace provides the following function:
voltmx.ml.ImageClassifier
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
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. voltmx.ml.MODEL_SOURCE_TYPE_BUNDLED: The model is kept in the raw folder of respective platform and channel. This is the default constant. For example, Consider that you have built a mobile application. Following is the raw folder path for Android and iOS: Android: <workspace>/resources/mobile/native/android/raw ios : <workspace>/resources/mobile/native/iphone/raw voltmx.ml.MODEL_SOURCE_TYPE_FILE: This constant is applicable when the Model is stored in remote server and the same is downloaded using network APIs and then saved in a File. |
onSuccess | Function | Callback function that receives prediction results. 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: title: The name of the category. The value type is String. confidence: The percentage of certainty with which an object belongs to a category. This type of this value is double and it ranges from 0 to 1. 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. Parameters errorCode: contains various codes to identify possible errors. Here is the list of the constants:voltmx.ml.ERROR_INPUT_IMAGE_NULL: This error appears when the rawBytes given to recognizeImage method is null.voltmx.ml.ERROR_REUSE_EXCEPTION: This error appears when the recongnizeImage method is invoked after the releaseResource method is invoked.voltmx.ml.ERROR_IMAGE_PROCESSING_FAILED: This error appears when processing image gets failed.voltmx.ml.ERROR_UNKNOWN: This error appears when reason of failure is unknown. |
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: width: width of the input size. The type of this key is Number. height: height of the input size. The type of this key is Number. For example, |
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: voltmx.ml.MODEL_TYPE_QUANTIZED voltmx.ml.MODEL_TYPE_FLOAT |
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. voltmx.ml.LABEL_SOURCE_TYPE_BUNDLED: The label file must be kept in raw folder of respective platform and channel. This is the default constant. For example, Consider that you have built a mobile application. Following is the raw folder path for Android Android: <workspace>/resources/mobile/native/android/raw voltmx.ml.LABEL_SOURCE_TYPE_FILE: This option can be used in case the label is stored in remote server and the same is downloaded using network APIs and saved in File . |
device | Constant | This is applicable only to the Android platform. The runtime device type used for executing classification. Contain one of the following constants. voltmx.ml.MODEL_DEVICE_CPU voltmx.ml.MODEL_DEVICE_GPU voltmx.ml.MODEL_DEVICE_NNAPI |
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
Platform Availability
iOS and Android.