38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
|
// This file was auto-generated by ML.NET Model Builder.
|
||
|
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Text;
|
||
|
using Microsoft.ML;
|
||
|
using Mask_MLML.Model;
|
||
|
|
||
|
namespace Mask_MLML.Model
|
||
|
{
|
||
|
public class ConsumeModel
|
||
|
{
|
||
|
private static Lazy<PredictionEngine<ModelInput, ModelOutput>> PredictionEngine = new Lazy<PredictionEngine<ModelInput, ModelOutput>>(CreatePredictionEngine);
|
||
|
|
||
|
// For more info on consuming ML.NET models, visit https://aka.ms/mlnet-consume
|
||
|
// Method for consuming model in your app
|
||
|
public static ModelOutput Predict(ModelInput input)
|
||
|
{
|
||
|
ModelOutput result = PredictionEngine.Value.Predict(input);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
public static PredictionEngine<ModelInput, ModelOutput> CreatePredictionEngine()
|
||
|
{
|
||
|
// Create new MLContext
|
||
|
MLContext mlContext = new MLContext();
|
||
|
|
||
|
// Load model & create prediction engine
|
||
|
string modelPath = @"C:\Users\HUAWEI\AppData\Local\Temp\MLVSTools\Mask.MLML\Mask.MLML.Model\MLModel.zip";
|
||
|
ITransformer mlModel = mlContext.Model.Load(modelPath, out var modelInputSchema);
|
||
|
var predEngine = mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(mlModel);
|
||
|
|
||
|
return predEngine;
|
||
|
}
|
||
|
}
|
||
|
}
|