MLPredictorExtensions
class NatML.MLPredictorExtensions
Async Predictions
/// <summary>
/// Create an async predictor from a predictor.
/// This typically results in significant performance improvements,
/// as predictions are run on a worker thread.
/// </summary>
/// <param name="predictor">Backing predictor to create an async predictor with.</param>
/// <returns>Async predictor which runs predictions on a worker thread.</returns>
static MLAsyncPredictor<TOutput> ToAsync<TOutput> (this IMLPredictor<TOutput> predictor);// Create a predictor
var predictor = new MobileNetv2Predictor(...);
// Then make it async!
var asyncPredictor = predictor.ToAsync();// Before, we used to make predictions on the main thread:
var (label, confidence) = predictor.Predict(...);
// Now, we can make predictions on a dedicated worker thread:
var (label, confidence) = await asyncPredictor.Predict(...);Last updated