machinelearning icon indicating copy to clipboard operation
machinelearning copied to clipboard

Using AddPredictionEnginePool ModelName difference in Predict shows expected error

Open BartNSTCL opened this issue 1 year ago • 1 comments

  • OS & Version: Windows 11 Insider Build 23606.1000
  • ML.NET Version: 3.0.0
  • .NET Version: Net 8.0

Describe the bug I created a PredictionEnginePool in Program.cs as: builder.Services.AddPredictionEnginePool<ModelOutput, ModelOutput>() .FromUri( modelName: "YieldModel", uri: "/MechPropertiesModels/YieldModel.zip", period: TimeSpan.FromMinutes(10));

In my Controller, after setting up the DI (PredEnginePool), I had the following code: IEnumerable<ModelOutput> yieldOut = sampleData.Select(input => PredEnginePool.Predict<ModelOutput, ModelOutput>(modelName: "Yield", example: input)).ToList();

When I run the code, the error was: System.ArgumentNullException: Value cannot be null. (Parameter 'poolOptions') at Microsoft.Extensions.ML.PoolLoader2..ctor(IServiceProvider sp, PredictionEnginePoolOptions2 poolOptions) at Microsoft.Extensions.ML.PredictionEnginePool2.AddPool(String modelName) at Microsoft.Extensions.ML.PredictionEnginePool2.GetPredictionEngine(String modelName) at Microsoft.Extensions.ML.PredictionEnginePoolExtensions.Predict[TData,TPrediction](PredictionEnginePool`2 predictionEnginePool, String modelName, TData example) at CTLWebApi.Controllers.MachineLearningController.<PredictMechProperties>b__11_1(ModelOutput input) in C:\Users\bart.lynn\source\repos\CTL Projects\CTLWebsite_Net\CTLWebApi\Controllers\MachineLearningController.cs:line 91

I realized after some time, I had 2 different names for the Model (YieldModel, and Yield). The error pointed to missing 'poolOptions'. I tried any different searches looking for that 'poolOptions' and after a while I noticed the model name differences.

To Reproduce Steps to reproduce the behavior:

  1. Name the model something in the Program.cs
  2. Name the model something different in the Controller.
  3. Run
  4. See error

Expected behavior Maybe it should say, Model:"Yield" was not found in the pool.

Screenshots, Code, Sample Projects Code is provided above.

BartNSTCL avatar Dec 15 '23 18:12 BartNSTCL

confirmed and I agree, a more descriptive error "model Yield was not found" would be an improvement

pietersap avatar May 07 '24 16:05 pietersap