From d45634d2cfc4ec115a6014ca9a04c379eb53c7cc Mon Sep 17 00:00:00 2001 From: Zeeshan Siddiqui Date: Sun, 17 Mar 2019 23:43:06 -0700 Subject: [PATCH] Add MLContext.Model.Load overload that takes a file path. --- src/Microsoft.ML.Data/Model/ModelOperationsCatalog.cs | 11 +++++++++++ .../DataPipe/TestDataPipeBase.cs | 3 +-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.ML.Data/Model/ModelOperationsCatalog.cs b/src/Microsoft.ML.Data/Model/ModelOperationsCatalog.cs index 0443240e1d..79b39ffa3c 100644 --- a/src/Microsoft.ML.Data/Model/ModelOperationsCatalog.cs +++ b/src/Microsoft.ML.Data/Model/ModelOperationsCatalog.cs @@ -40,6 +40,17 @@ internal ModelOperationsCatalog(IHostEnvironment env) /// The loaded model. public ITransformer Load(Stream stream) => TransformerChain.LoadFrom(_env, stream); + /// + /// Load the model from a file path. + /// + /// Path to model. + /// The loaded model. + public ITransformer Load(string modelPath) + { + using (var stream = File.OpenRead(modelPath)) + return Load(stream); + } + /// /// The catalog of model explainability operations. /// diff --git a/test/Microsoft.ML.TestFramework/DataPipe/TestDataPipeBase.cs b/test/Microsoft.ML.TestFramework/DataPipe/TestDataPipeBase.cs index e89dbdf853..9dfee880dc 100644 --- a/test/Microsoft.ML.TestFramework/DataPipe/TestDataPipeBase.cs +++ b/test/Microsoft.ML.TestFramework/DataPipe/TestDataPipeBase.cs @@ -84,8 +84,7 @@ protected void TestEstimatorCore(IEstimator estimator, ML.Model.Save(transformer, fs); ITransformer loadedTransformer; - using (var fs = File.OpenRead(modelPath)) - loadedTransformer = ML.Model.Load(fs); + loadedTransformer = ML.Model.Load(modelPath); DeleteOutputPath(modelPath); // Run on train data.