NatML
Search…
MLModel
class NatSuite.ML.MLModel : IMLModel
The MLModel class abstracts a self-contained machine learning model, containing a computation graph for making predictions along with feature type information and metadata.
Models are created from MLModelData instances.

Inspecting Feature Types

Models provide information about their expected input and output feature types. This type information is crucial for writing model predictors.

Input Features

1
/// <summary>
2
/// Model input feature types.
3
/// </summary>
4
MLFeatureType[] inputs { get; }
Copied!
The model provides its expected input feature types. This information is crucial in order to create input features for predictions. Typically, a predictor will handle any necessary conversions of your input feature so that it matches the type that the model expects.
The inputs are reported in the same order that they are expected by the model when making predictions.

Output Features

1
/// <summary>
2
/// Model output feature types.
3
/// </summary>
4
MLFeatureType[] outputs { get; }
Copied!
The model provides its output feature types. This information is crucial in order to convert the model's raw outputs into more usable forms by predictors.
The outputs are reported in the same order that they are produced by the model when making predictions.

Inspecting Metadata

1
/// <summary>
2
/// Get a value in the model metadata.
3
/// </summary>
4
/// <param name="key">Metadata key.</param>
5
/// <returns>Metadata value.</returns>
6
string this [string key] { get; }
Copied!
Models expose metadata that was defined when they were created. They can be accessed using the indexer:
1
// Get model description
2
var description = model["Description"];
Copied!
The MLModel class implements the IReadOnlyDictionary interface, and as such can be used like any other dictionary.
If the model does not have a given key, a KeyNotFoundException is thrown by the indexer.
The model can be enumerated for all of its metadata keys and their corresponding values:
1
foreach (KeyValuePair<string, string> metadata in model)
2
Debug.Log(quot;{metadata.Key}: {metadata.Value}");
Copied!

Disposing the Model

1
/// <summary>
2
/// Dispose the model and release resources.
3
/// </summary>
4
void Dispose ();
Copied!
Models create native resources, including threads and memory allocators. As a result, you must dispose of the model once you are done using it.
The MLModel class implements the IDisposable interface, and as such can be used with using blocks.
Do not use a model once it has been disposed. Doing so will lead to a hard crash.
Last modified 4mo ago