NatML
Search…
MLModelDataEmbed
class NatML.MLModelDataEmbedAttribute
The MLModelDataEmbed attribute allows developers to embed model data from NatML Hub at build time so that the model data is available without downloading at runtime. This is useful when building applications that might not have internet access.
Note that the build size of the application will increase as a result of the embedded model data.

Embedding Model Data

1
/// <summary>
2
/// Embed ML model data from NatML.
3
/// </summary>
4
/// <param name="tag">Predictor tag.</param>
5
/// <param name="accessKey">NatML access key. If `null` the project access key will be used.</param>
6
MLModelDataEmbedAttribute (string tag, string accessKey = null);
Copied!
The attribute can be placed on any class or struct definition. At build time, NatML will find all such attributes, and embed the corresponding model data in the build. The attribute can be used like so:
1
// An example script that embeds the `ssd-lite` model data from NatML Hub
2
[MLModelDataEmbed("@natsuite/ssd-lite")]
3
class ObjectDetector : MonoBehaviour {
4
5
async void Start () {
6
// Fetch the model data from memory
7
// In a build, this will complete immediately
8
var modelData = await MLModelData.FromHub("@natsuite/ssd-lite");
9
// Use the model data
10
...
11
}
12
}
Copied!
Copy link