Skip to content

[1.0.0-preview] Bug? - Getting an exception while loading .ZIP model MultiClass-Classification trained with SdcaNonCalibrated #3209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
prathyusha12345 opened this issue Apr 5, 2019 · 5 comments · Fixed by #3217
Assignees
Labels
bug Something isn't working

Comments

@prathyusha12345
Copy link

prathyusha12345 commented Apr 5, 2019

I am trying to migrate IRIS Classification sample in the repo here to v1.0.0-preview.

While loading the model for prediction I am getting the below error at the statement

            trainedModel = mlContext.Model.Load(stream, out var modelInputSchema);
System.InvalidOperationException
  HResult=0x80131509
  Message=Error during class instantiation
  Source=Microsoft.ML.Core
  StackTrace:
   at Microsoft.ML.Runtime.ComponentCatalog.LoadableClassInfo.CreateInstanceCore(Object[] ctorArgs)
   at Microsoft.ML.Runtime.ComponentCatalog.TryCreateInstance[TRes](IHostEnvironment env, Type signatureType, TRes& result, String name, String options, Object[] extra)
   at Microsoft.ML.Runtime.ComponentCatalog.TryCreateInstance[TRes,TSig](IHostEnvironment env, TRes& result, String name, String options, Object[] extra)
   at Microsoft.ML.ModelLoadContext.TryLoadModelCore[TRes,TSig](IHostEnvironment env, TRes& result, Object[] extra)
   at Microsoft.ML.ModelLoadContext.TryLoadModel[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, Entry ent, String dir, Object[] extra)
   at Microsoft.ML.ModelLoadContext.LoadModel[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, Entry ent, String dir, Object[] extra)
   at Microsoft.ML.ModelLoadContext.LoadModelOrNull[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, String dir, Object[] extra)
   at Microsoft.ML.ModelLoadContext.LoadModel[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, String dir, Object[] extra)
   at Microsoft.ML.ModelOperationsCatalog.Load(Stream stream, DataViewSchema& inputSchema)
   at MulticlassClassification_Iris.Program.TestSomePredictions(MLContext mlContext) in C:\GitRepos\machinelearning-samples-v1.0.0-Preview\samples\csharp\getting-started\MulticlassClassification_Iris\IrisClassification\IrisClassificationConsoleApp\Program.cs:line 99
   at MulticlassClassification_Iris.Program.Main(String[] args) in C:\GitRepos\machinelearning-samples-v1.0.0-Preview\samples\csharp\getting-started\MulticlassClassification_Iris\IrisClassification\IrisClassificationConsoleApp\Program.cs:line 36

Inner Exception 1:
TargetInvocationException: Exception has been thrown by the target of an invocation.

Inner Exception 2:
InvalidOperationException: Error during class instantiation

Inner Exception 3:
TargetInvocationException: Exception has been thrown by the target of an invocation.

Inner Exception 4:
InvalidOperationException: Error during class instantiation

Inner Exception 5:
TargetInvocationException: Exception has been thrown by the target of an invocation.

Inner Exception 6:
FormatException: Couldn't load model: 'TransformerChain\Transform_002\Transform_000\Model'

the dataset format is like this

#Label	Sepal length	Sepal width	Petal length	Petal width
0	5.4	3.7	1.5	0.2
0	4.8	3.4	1.6	0.2
0	4.8	3.0	1.4	0.1
0	4.3	3.0	1.1	0.1

I have pushed the code to the Github repo here https://github.com/dotnet/machinelearning-samples/tree/migration/1.1.0-preview/samples/csharp/getting-started/MulticlassClassification_Iris

I did not understand the reason for the error. Could anyone help

@prathyusha12345
Copy link
Author

Before this exception I am getting schema mismatch exception as below

Schema mismatch for label column '': expected Key < UInt32 >, got Single
Parameter name: labelCol

To fix this exception I have added MapValuetoKey() and MapKeyToValue() transformations. Then when I start executing sample I am getting the other exception that it couldn't load model as mentioned earlier.

@prathyusha12345
Copy link
Author

prathyusha12345 commented Apr 5, 2019

adding @CESARDELATORRE for reference. This issue is happening only with SdcaNonCalibrated trainer

@CESARDELATORRE CESARDELATORRE changed the title Getting an exception while loading the model in MultiClass Classification_IRIS [1.0.0-preview] Getting an exception while loading .ZIP model MultiClass-Classification trained with SdcaNonCalibrated Apr 5, 2019
@CESARDELATORRE CESARDELATORRE changed the title [1.0.0-preview] Getting an exception while loading .ZIP model MultiClass-Classification trained with SdcaNonCalibrated [1.0.0-preview] Bug? - Getting an exception while loading .ZIP model MultiClass-Classification trained with SdcaNonCalibrated Apr 5, 2019
@CESARDELATORRE
Copy link
Contributor

CESARDELATORRE commented Apr 5, 2019

Just to mention that right after training the model (multi-class classification) with SdcaNonCalibrated, the model works for making predictions.
However, we save it to a .ZIP file and when we try to load it is when we get the exception.

Also, we have tried with 3 different samples and three different datasets. We get the same behavior.
When using SdcaNonCalibrated it fails in all those samples with different datasets.

If using another algorithm such as OVAAveragedPercentronTrainer, the model loads properly from the .ZIP file and the scenario works good end-to-end.

So looks like a bug related to SdcaNonCalibrated?

@prathyusha12345
Copy link
Author

@Ivanidzo4ka Do I need to upgrade to latest version of ML.Net instead of ML.Net 1.0.0-preview to fix this error my sample?

@Ivanidzo4ka
Copy link
Contributor

Here is PR towards 1.0 branch. #3220
I hope all you need to do on your side is to update to latest 1.0.0-preview nuget after it would get merge.
@shauheen for clarification.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants