Using an emitted class with CreatePredictionEngine and Predict
hey all,
For an application I'm writing, I need to use CreatePredictionEngine with two emitted classes for TSrc
and TDst
. Those are emitted via System.Reflection.Emit
. I'm creating the prediction engine as follows :
dynamic dynamicPredictionEngine;
var genericPredictionMethod = description.mlContext.Model.GetType().GetMethod("CreatePredictionEngine", new[] { typeof(ITransformer), typeof(DataViewSchema) });
var predictionMethod = genericPredictionMethod.MakeGenericMethod(inputObject.GetType(), outputObject.GetType());
dynamicPredictionEngine = predictionMethod.Invoke(mlContext.Model, new object[] { TrainedModel, PredictionPipeline });
inputObject
and outputObject
being instances of my two emitted classes.
When running such a prediction engine (with var result = dynamicPredictionEngine.Predict(inputObject);
), I get this Exception :
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'The best overloaded method match for 'Microsoft.ML.PredictionEngineBase<inputType>.Predict(inputObject)' has some invalid arguments'
To debug this, I created the inputType manually, instead of using my emitted class. This works fine if input type is created manually, and output type is emitted. I checked in the debugger to see what differs between my emitted class and the manually created one, they seem to match :
inputObject
is emitted, TaxiTrip
is manually created.
I'm totally new to this Reflection.Emit thing, and I have no idea what could cause the Predict
function to fail, since both classes seem to have the same properties here.
Does anyone have an idea?
Thanks in advance!