-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Description
System information
- OS version: 10.0.19041
- .NET SDKs: 3.1.402, 5.0.100-preview.7.20366.6
Issue
-
What did you do?
Attempted to convert a trained ML.Net LightGbm model to ONNX model with ConvertToOnnx. -
What happened?
Exception thrown: 'System.Collections.Generic.KeyNotFoundException' in System.Private.CoreLib.dll
An unhandled exception of type 'System.Collections.Generic.KeyNotFoundException' occurred in System.Private.CoreLib.dll
The given key 'Mates4_TextNormalizer' was not present in the dictionary.
- What did you expect?
ONNX model converted and saved to file without errors.
Source code
Model was trained with LightGbm, evaluated and tested working before conversion is applied.
Tried two versions: 1. loading a saved model and apply conversion; 2. end-to-end (train, evaluate and apply conversion). Both threw the same exception.
There's nothing with 'TextNormalizer' anywhere during training but there is a string named 'Mates4' in the ItemRating class, which was featurized during training with Transforms.Text.FeaturizeText. This could be related.
MLContext mlContext = new MLContext();
var data = mlContext.Data.LoadFromTextFile<ItemRating>(path: TrainingDataLocation, hasHeader: true, separatorChar: ',');
var trainTestData = mlContext.Data.TrainTestSplit(data, testFraction: 0.1);
var trainingDataView = trainTestData.TrainSet;
trainingDataView = mlContext.Data.Cache(trainingDataView);
ITransformer trainedModel;
using (FileStream stream = new FileStream(ModelPath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
trainedModel = mlContext.Model.Load(stream, out var modelInputSchema);
}
using (FileStream streamfile = File.Create(onnxModelPath))
{
mlContext.Model.ConvertToOnnx(trainedModel, trainingDataView, streamfile);
}Metadata
Metadata
Assignees
Labels
No labels