MLFeature
abstract class NatML.MLFeature
The MLFeature
class is an abstract base class representing input and output features used in making predictions. All predictors accept one or more features, which are then provided to the model to make predictions.
Creating a Feature
NatML provides implicit conversions from common data types into MLFeature
instances:
From an Array
// With a `float` array
float[] array = ...;
// Create a feature
MLFeature feature = array;
// Then make a prediction
predictor.Predict(feature);
// This works too
predictor.Predict(array);
NatML provides an implicit conversion from a float[]
to an MLArrayFeature
.
When this conversion is used, the created feature will have no shape
information.
From a Texture2D
// With a `Texture2D`
Texture2D texture = ...;
// Create a feature
MLFeature feature = texture;
// Then make a prediction
predictor.Predict(feature);
// This works too
predictor.Predict(texture);
NatML provides an implicit conversion from a Texture2D
to an MLImageFeature
.
From a WebCamTexture
// With a `WebCamTexture`
WebCamTexture webCamTexture = ...;
// Create a feature
MLFeature feature = webCamTexture;
NatML provides an implicit conversion from a WebCamTexture
to an MLImageFeature
.
From an AudioClip
// With an `AudioClip`
AudioClip audioClip = ...;
// Create a feature
MLFeature feature = audioClip;
NatML provides an implicit conversion from an AudioClip
to an MLAudioFeature
.
From a String
// With a `string`
var text = "hello, world";
// Create a feature
MLFeature feature = text;
NatML provides an implicit conversion from a string
to an MLTextFeature
.
Inspecting the Feature
/// <summary>
/// Feature type.
/// </summary>
MLFeatureType type { get; }
Every feature has a corresponding MLFeatureType
that provides information about the feature's shape, data type, and so on.
Last updated
Was this helpful?