dotnet / machinelearning

ML.NET is an open source and cross-platform machine learning framework for .NET.
https://dot.net/ml
MIT License
9.05k stars 1.89k forks source link

Generated Model cannot be converted to ONNX #4601

Closed jcmontoya closed 4 years ago

jcmontoya commented 4 years ago

System Information (please complete the following information):

Describe the bug I used the Model Builder to Classify basketball balls and soccer balls. It works very well. then I tried to convert the generated model to ONNX using the code bellow: ` string modelPath = AppDomain.CurrentDomain.BaseDirectory + "MLModel.zip";

ITransformer mlModel = mLContext.Model.Load(modelPath, out var modelInputSchema);

IDataView dataView = mLContext.Data.LoadFromTextFile( path: DATA_FILEPATH, hasHeader: true, separatorChar: '\t', allowQuoting: true, allowSparse: false);

MemoryStream memoryStream = new MemoryStream();

mLContext.Model.ConvertToOnnx(mlModel, dataView, memoryStream);

byte[] data = memoryStream.ToArray();

using (FileStream fileStream = File.Create(@"C:\temp\SportsBall.onnx")) { fileStream.Write(data, 0, data.Length); } ` In the Bold line I get the following error:

System.InvalidOperationException: 'The targeted pipeline can not be fully converted into a well-defined ONNX model. Please check if all steps in that pipeline are convertible to ONNX and all necessary variables are not dropped (via command line arguments).'

To Reproduce Steps to reproduce the behavior:

  1. Create a simple model
  2. Convert to ONNX model with provided code
  3. See Error

Expected behavior The new ONNX model should be generated in the path: C:\temp\SportsBall.onnx

Screenshots NA

Additional context NA

najeeb-kazmi commented 4 years ago

@jcmontoya have you checked whether all steps in the pipeline are convertible to ONNX as the meesage says?

@wschin do you have any input here as to why this might be happening?

harishsk commented 4 years ago

@jcmontoya It is our goal to make all of ML.NET estimators convertible to Onnx but we are not there yet. Right now, only (approximately) half of the estimators can be exported to Onnx.

If you go to the documentation page of any estimator (e.g. ColumnConcatenatingEstimator )you should be able to see a line as follows in the Estimator characteristics table that will let let you know whether that estimator can be exported to onnx:

Exportable to ONNX | Yes

Also, the bulk of onnx related work didn't make it v1.4. Can you please try out your code v1.5 preview builds and reopen the bug if you still see this issue?

kevindc2310 commented 3 years ago

Hi, same problem here. Any news on making the ImageLoadingEstimator exportable to ONNX?