Skip to content

Classic API: Machine Learning

Hayun Lee edited this page Dec 21, 2020 · 3 revisions

Parent Document: ANT APIs

Machine Learning API is the set of APIs for running inference with leveraging machine learning algorithms such as ANN(artificial neural networks), DNN(deep neural networks).

MLAPI Object

You need to load machine learning API(MLAPI) object before you use its API as following. With MLAPI, you can retrieve MLAPIInferenceUnit object from this MLAPI object.

var mlApi = require(process.env.ANT_BIN_DIR + 'ant').ml();

loadAsync()

void loadAsync(String modelPackagePath, Object params, Function callback)

callback: void (Object iu)

It makes machine learning daemon read machine learning model descriptor which is located at modelPackagePath, and creates an InferenceUnit object. The loaded InferenceUnit object will be registered to inference unit directory. After loading, callback will be called with the inference unit as argument iu.

  • Argument 0: String modelPackagePath

    Absolute path of machine learning model’s descriptor file

  • Argument 1: Object params

    Parameter of inference unit. It can accept only parameters that is defined in model descriptor.

  • Argument 2: Function callback

    • Callback Argument 0: Object iu
  • Return: void

getInferenceUnitsAsync()

void getInferenceUnitsAsync(Function callback)

callback: void (Array<Object> ius)

It retrieves the list of inference units that are registered to inference unit directory of MLDaemon. After retrieving inference unit list, callback will be called with the list as argument ius.

  • Argument 0: Function callback
    • Callback Argument 0: Array<Object> ius
  • Return: void

MLAPIInferenceUnit Object

MLAPIInferenceUnit object represents InferenceUnit running on the machine learning framework, the basic unit of machine learning inference.

setInputAsync()

void setInputAsync(String sourceUri, String inputName, Function callback)

callback: void (void)

It sets a connection of an input source(of which URI is sourceUri) and a input of inference unit(of which name is inputName).

  • Argument 0: String inputName

    The name of inference unit’s input

  • Argument 1: String sourceUri

    The URI of input source. If sourceUri is null or empty string, reset the connection.

  • Argument 2: Function callback

    Callback function called when setting input is done.

  • Return: void

setOnOutputAsync()

void setOnOutputAsync(Function callback)

callback: void (Object outputs)

It sets callback of output event which occurs after running InferenceUnit.

  • Argument 0: Function callback

    Callback function which handles output event of machine learning inference. If callback is null, reset the callback.

    • Callback Argument 0: Object outputs
  • Return: void

startAsync()

void startAsync(Function callback)

callback: void (void)

It starts the execution of InferenceUnit.

  • Argument 0: Function callback
    • Callback function when the command is finished
  • Return: void

stopAsync()

void stopAsync(Function callback)

callback: void (void)

It stops the execution of InferenceUnit.

  • Argument 0: Function callback
    • Callback function when the command is finished
  • Return: void

unloadAsync()

void unloadAsync(Function callback)

callback: void (void)

It unloads the InferenceUnit.

  • Argument 0: Function callback
    • Callback function when the command is finished
  • Return: void

name

String name

Human-readable name of InferenceUnit

type

String type

The type of InferenceUnit

Clone this wiki locally