Once NatML has been imported, you can run ML models right in the Editor. For this example, we will classify an image using the popular MobileNet classifier architecture:
First, we'll import the MobileNet predictor into our project by following the import instructions:
The recommended way to make predictions with ML models is using Predictors. These are lightweight classes that 'know how' to format the model's input and output features.
Specifying your NatML Access Key
We will fetch our models from NatML Hub, . To do so, we need to retrieve our access key:
using UnityEngine;
using NatML.Vision;
public class Classifier : MonoBehaviour {
[Header(@"Prediction")]
public Texture2D image;
async void Start () {
// Create the MobileNet predictor
using var predictor = await MobileNetv2Predictor.Create();
// Classify the image feature
var (label, confidence) = predictor.Predict(image);
// Log the result
Debug.Log($"Image contains {label} with confidence {confidence}");
}
}