ML model service API | Service APIs
ML model service API
The ML model service API allows you to make inferences based on a provided ML model.
The ML model service supports the following methods:
| Method Name | Description |
|---|---|
Infer |
Take an already ordered input tensor as an array, make an inference on the model, and return an output tensor map. |
Metadata |
Get the metadata: name, data type, expected tensor/array shape, inputs, and outputs associated with the ML model. |
Reconfigure |
Reconfigure this resource. |
DoCommand |
Execute model-specific commands that are not otherwise defined by the service API. |
GetResourceName |
Get the ResourceName for this instance of the ML model service. |
Close |
Safely shut down the resource and prevent further use. |
API
Infer
Take an already ordered input tensor as an array, make an inference on the model, and return an output tensor map.
Parameters:
input_tensors(Dict[ str, typing.NDArray]) (required): A dictionary of input flat tensors as specified in the metadata.extra(Mapping[ str, Any]) (optional): Extra options to pass to the underlying RPC call.timeout( float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.
Returns:
- (Dict[ str, typing.NDArray]): : A dictionary of output flat tensors as specified in the metadata.
Example:
Copy
For more information, see the Python SDK Docs.
Parameters:
ctx(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.tensors(ml.Tensors): The input map of tensors, as specified in the metadata.
Returns:
- (ml.Tensors): The output map of tensors, as specified in the metadata, after being run through an inference engine.
- (error): An error, if one occurred.
Example:
Copy
For more information, see the Go SDK Docs.
Metadata
Get the metadata: name, data type, expected tensor/array shape, inputs, and outputs associated with the ML model.
Parameters:
extra(Mapping[ str, Any]) (optional): Extra options to pass to the underlying RPC call.timeout( float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.
Returns:
- (viam.services.mlmodel.mlmodel.Metadata): : The metadata.
Example:
Copy
For more information, see the Python SDK Docs.
Parameters:
ctx(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
Returns:
- (MLMetadata): Name, type, expected tensor/array shape, inputs, and outputs associated with the ML model.
- (error): An error, if one occurred.
Example:
Copy
For more information, see the Go SDK Docs.
Reconfigure
Reconfigure this resource. Reconfigure must reconfigure the resource atomically and in place.
Parameters:
ctx(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.deps(Dependencies): The resource dependencies.conf(Config): The resource configuration.
Returns:
- (error): An error, if one occurred.
For more information, see the Go SDK Docs.
DoCommand
Execute model-specific commands that are not otherwise defined by the service API. Most models do not implement DoCommand. Any available model-specific commands should be covered in the model’s documentation. If you are implementing your own ML model service and want to add features that have no corresponding built-in API method, you can implement them with DoCommand.
Parameters:
ctx(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.cmd(map[string]interface{}): The command to execute.
Returns:
- (map[string]interface{}): The command response.
- (error): An error, if one occurred.
Example:
Copy
For more information, see the Go SDK Docs.
GetResourceName
Get the ResourceName for this instance of the ML model service.
Parameters:
name( str) (required): The name of the Resource.
Returns:
- ( viam.proto.common.ResourceName): : The ResourceName of this Resource.
Example:
Copy
For more information, see the Python SDK Docs.
Parameters:
- None.
Returns:
Example:
Copy
For more information, see the Go SDK Docs.
Close
Safely shut down the resource and prevent further use.
Parameters:
- None.
Returns:
- None.
Example:
Copy
For more information, see the Python SDK Docs.
Parameters:
ctx(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
Returns:
- (error): An error, if one occurred.
Example:
Copy
For more information, see the Go SDK Docs.