diff --git a/src/Microsoft.ML.Data/DataLoadSave/TransformerChain.cs b/src/Microsoft.ML.Data/DataLoadSave/TransformerChain.cs index a20bc5113c..8402cf643a 100644 --- a/src/Microsoft.ML.Data/DataLoadSave/TransformerChain.cs +++ b/src/Microsoft.ML.Data/DataLoadSave/TransformerChain.cs @@ -300,5 +300,13 @@ public static TransformerChain LoadFrom(IHostEnvironment env, Stre } } } + + public static TransformerChain LoadFromPath(IHostEnvironment env, string modelPath) + { + using (var stream = File.OpenRead(modelPath)) + { + return LoadFrom(env, stream); + } + } } } diff --git a/src/Microsoft.ML.Data/Model/ModelOperationsCatalog.cs b/src/Microsoft.ML.Data/Model/ModelOperationsCatalog.cs index 0443240e1d..8e9bd0df28 100644 --- a/src/Microsoft.ML.Data/Model/ModelOperationsCatalog.cs +++ b/src/Microsoft.ML.Data/Model/ModelOperationsCatalog.cs @@ -40,6 +40,13 @@ internal ModelOperationsCatalog(IHostEnvironment env) /// The loaded model. public ITransformer Load(Stream stream) => TransformerChain.LoadFrom(_env, stream); + /// + /// Load the model from a filePath of the model. + /// + /// The path of the model to load./> + /// The loaded model. + public ITransformer Load(string modelPath) => TransformerChain.LoadFromPath(_env, modelPath); + /// /// The catalog of model explainability operations. /// diff --git a/test/Microsoft.ML.Tests/Scenarios/Api/CookbookSamples/CookbookSamplesDynamicApi.cs b/test/Microsoft.ML.Tests/Scenarios/Api/CookbookSamples/CookbookSamplesDynamicApi.cs index cebf20503e..413c54f83d 100644 --- a/test/Microsoft.ML.Tests/Scenarios/Api/CookbookSamples/CookbookSamplesDynamicApi.cs +++ b/test/Microsoft.ML.Tests/Scenarios/Api/CookbookSamples/CookbookSamplesDynamicApi.cs @@ -130,9 +130,7 @@ private void TrainRegression(string trainDataPath, string testDataPath, string m // Potentially, the lines below can be in a different process altogether. // When you load the model, it's a 'dynamic' transformer. - ITransformer loadedModel; - using (var stream = File.OpenRead(modelPath)) - loadedModel = mlContext.Model.Load(stream); + ITransformer loadedModel = mlContext.Model.Load(modelPath); } [Fact]