dotnet / machinelearning

ML.NET is an open source and cross-platform machine learning framework for .NET.
https://dot.net/ml
MIT License
9.02k stars 1.88k forks source link

Using AddPredictionEnginePool ModelName difference in Predict shows expected error #6912

Open BartNSTCL opened 9 months ago

BartNSTCL commented 9 months ago

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 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.b__11_1(ModelOutput input) in C:\Users\bart.lynn\source\repos\CTL Projects\CTLWebsiteNet\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.

pietersap commented 4 months ago

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