dotnet / dotnet/machinelearning

Using AddPredictionEnginePool ModelName difference in Predict shows expected error

Open
#6,912 2 comments 0 reactions 0 assignees View on GitHub
area-Integration
Dominant language
C#
Stars
9.4k
Forks
2k
Avg merge
2d 20h
Merged PRs (30d)
11

Description

- 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()
.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(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.PoolLoader`2..ctor(IServiceProvider sp, PredictionEnginePoolOptions`2 poolOptions)
at Microsoft.Extensions.ML.PredictionEnginePool`2.AddPool(String modelName)
at Microsoft.Extensions.ML.PredictionEnginePool`2.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\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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.