NimbusML
NimbusML copied to clipboard
NimbusML model loaded in ML.NET cannot create PredictionEngine
Found while investigating #201
Describe the bug
Cannot create a PredictionEngine
in ML.NET from a model trained in NimbusML. Can only use model.Transform(data)
to make predictions, whether single or batch.
To Reproduce Python example on UCI Adult:
train = FileDataStream.read_csv(train_file, sep=',', numeric_dtype=np.float32)
pipe = Pipeline([ColumnConcatenator(columns={'Features': ['age']}),
AveragedPerceptronBinaryClassifier(feature=['Features'], label='label')])
pipe.fit(train)
pipe.save_model(nimbus_model_file)
ML.NET code:
MLContext mlContext = new MLContext();
ITransformer mlModel = mlContext.Model.Load(GetAbsolutePath(MODEL_FILEPATH), out DataViewSchema inputSchema);
var predEngine = mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(mlModel);
Expected behavior
Expected PredictionEngine
to be created to make single prediction.
Error message
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Invalid TValue in GetGetter for column #label: Boolean: 'System.Int64'
at Microsoft.ML.Data.DataViewConstructionUtils.InputRowBase`1.GetGetter[TValue](Column column)
at Microsoft.ML.Data.RowToRowMapperTransform.RowImpl.GetGetter[TValue](Column column)
at Microsoft.ML.Transforms.OptionalColumnTransform.GetSrcGetter[T](DataViewRow input, Int32 iinfo)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.ML.Transforms.OptionalColumnTransform.CreateGetters(DataViewRow input, IEnumerable`1 activeColumns, Action& disposer)
at Microsoft.ML.Data.RowToRowMapperTransformBase.Microsoft.ML.Data.IRowToRowMapper.GetRow(DataViewRow input, IEnumerable`1 activeColumns)
at Microsoft.ML.Data.CompositeRowToRowMapper.Microsoft.ML.Data.IRowToRowMapper.GetRow(DataViewRow input, IEnumerable`1 activeColumns)
at Microsoft.ML.Data.CompositeRowToRowMapper.Microsoft.ML.Data.IRowToRowMapper.GetRow(DataViewRow input, IEnumerable`1 activeColumns)
at Microsoft.ML.PredictionEngineBase`2.PredictionEngineCore(IHostEnvironment env, InputRow`1 inputRow, IRowToRowMapper mapper, Boolean ignoreMissingColumns, SchemaDefinition outputSchemaDefinition, Action& disposer, IRowReadableAs`1& outputRow)
at Microsoft.ML.PredictionEngineBase`2..ctor(IHostEnvironment env, ITransformer transformer, Boolean ignoreMissingColumns, SchemaDefinition inputSchemaDefinition, SchemaDefinition outputSchemaDefinition)
at Microsoft.ML.PredictionEngineExtensions.CreatePredictionEngine[TSrc,TDst](ITransformer transformer, IHostEnvironment env, Boolean ignoreMissingColumns, SchemaDefinition inputSchemaDefinition, SchemaDefinition outputSchemaDefinition)
at SampleBinaryClassification.ConsoleApp.Program.Main(String[] args) in D:\Data\UCIAdult\SampleBinaryClassification\SampleBinaryClassification.ConsoleApp\Program.cs:line 32
C:\Program Files\dotnet\dotnet.exe (process 195176) exited with code -532462766.
Press any key to close this window . . .