You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
API for loading ONNX model lacks access to input schema and is not consistent with regular model loading API #4335
Current API for loading models is as follows:
ITransformer mlModel = mlContext.Model.Load(path, out DataViewSchema inputSchema);
Note you have a transformer back and the input schema, plus transformer gives access to output schema as well.
For ONNX the same functionality will look something like this:
var estimator = mlContext.Transforms.ApplyOnnxModel(path);
var dataView = mlContext.Data.LoadFromEnumerable(new ModelInput[] { });
// Fit() will check the input schema of the model against the input dataview you're passing in
var transformer = estimator.Fit(dataView);
Note there's no way to get the input schema, you have to know it before you can do anything with the model. Also Fit() call is confusing and inconsistent with the much cleaner API above, it doesn't actually do anything other than verify the [unavailable from public interface] input schema against the schema that got loaded with the model.
The fix is to bring ONNX model loading API in line with what we have for regular ML.NET models.
I assume an .onnx model file contains the expected input schema, correct? Is there a way we can programmatically create a DataViewSchema given an .onnx file? Inspect all the input types, and build a DataViewSchema from it.
I totally agree that we should have a higher-level ONNX API here that doesn't necessarily fit into the base Estimator-Transformer programming model. That programming model is necessary when you want the Onnx model to be just a single step in the pipeline. But if your whole pipeline is contained in the Onnx model, there is no reason to go through the Estimator to get a transformer. Instead, we could have:
OnnxTransformermlModel=mlContext.Model.LoadOnnx(path,outDataViewSchemainputSchema);// use `mlModel` (which is an `ITransformer`) as normal, including creating a PredictionEngine<TIn, TOut> around it
This would eliminate the need for going through an Estimator, and then Fiting it with an empty data view.
I actually get what I need by using reflection from the OnnxTransformer instance, it was pretty painful to do but it works, my hope is I won't need any of that hackery once this issue is addressed. I can't say you can get a DataViewSchema in general case with complete confidence, but from what I've seen yes it should be pretty straightforward.
Activity
eerhardt commentedon Oct 15, 2019
I assume an .onnx model file contains the expected input schema, correct? Is there a way we can programmatically create a
DataViewSchemagiven an.onnxfile? Inspect all the input types, and build aDataViewSchemafrom it.I totally agree that we should have a higher-level ONNX API here that doesn't necessarily fit into the base
Estimator-Transformerprogramming model. That programming model is necessary when you want the Onnx model to be just a single step in the pipeline. But if your whole pipeline is contained in the Onnx model, there is no reason to go through theEstimatorto get a transformer. Instead, we could have:This would eliminate the need for going through an
Estimator, and thenFiting it with an empty data view.Dmitry-A commentedon Oct 15, 2019
I actually get what I need by using reflection from the OnnxTransformer instance, it was pretty painful to do but it works, my hope is I won't need any of that hackery once this issue is addressed. I can't say you can get a DataViewSchema in general case with complete confidence, but from what I've seen yes it should be pretty straightforward.
matouskozak commentedon Sep 1, 2026
Triage: The feature request looks valuable but it is not a current priority for the team.