protected void SaveMLModel(ITransformer mlModel, DataViewSchema trainingDataViewSchema, string path) { if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentException(); } if (!ModelFilesStorage.Exists(path)) { ModelFilesStorage.CreateFileAsync(path, new byte[0]); } var st = ModelFilesStorage.GetWriteStream(path); MLContext.Model.Save(mlModel, trainingDataViewSchema, st); }
protected virtual PredictionEngine <PTurnData, FacedUpCardPrediction> LoadPredictionEngine() { if (string.IsNullOrWhiteSpace(Options.MlModelFileName)) { throw new InvalidOperationException(); } var mlContext = new MLContext(); using var modelSt = ModelFilesStorage.GetReadStream(Options.MlModelFileName); ITransformer loadedModel = mlContext.Model.Load(modelSt, out var modelInputSchema); var predictionEngine = mlContext.Model.CreatePredictionEngine <PTurnData, FacedUpCardPrediction>(loadedModel); modelSt.Dispose(); return(predictionEngine); }