machinelearning icon indicating copy to clipboard operation
machinelearning copied to clipboard

System.Runtime.InteropServices.SEHException when loading ONNX models

Open AarthyKS opened this issue 8 years ago • 7 comments

Can someone help me with ONNX estimator.

System information

  • OS version/distro: Windows 10 Version 1709 Build 16299.726
  • .NET Version (eg., dotnet --info): .NET core 2.1

Issue

  • What did you do? Followed the tests and tried to load an existing Onnx model(squeezenet)using estimator (tried both static and dynamic)
  • **What happened? System.Runtime.InteropServices.SEHException: 'External component has thrown an exception
  • What did you expect? To load the onnx model and predict using it

Source code / logs

Please paste or attach the code or logs or traces that would be helpful to diagnose the issue you are reporting. OnnxApp.zip

AarthyKS avatar Nov 02 '18 03:11 AarthyKS

@AarthyKS Your model is not placed in the correct location. You need to either place it where the executable is run from (inside bin\x64\Debug\netcoreapp2.1), modify your model path to reflect this, or use an absolute path.

@jignparm @shmoradims It seems like the ONNX estimator not finding the model should really give a better/more descriptive error message? Also for some reason, the checks inside the estimator itself don't seem to always catch this, and it propagates down to the ModelManager inside the Sonoma code.

vaeksare avatar Nov 02 '18 21:11 vaeksare

@AarthyKS , try a fully qualified path to the model file, instead of a relative path below. Also, make sure there's only 1 onnx model file in the directory (this restriction will go away shortly after we transition to the new runtime librrary).

        if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            return;

        var modelFile = "sq_model.onnx";

        using (var env = new ConsoleEnvironment(null, false, 0, 1, null, null))
        {
            var imageHeight = 224;
            var imageWidth = 224;

@vaeksare - this upcoming release of the library will return back better error messages. The current SEH exception is too generic to debug anything with..

jignparm avatar Nov 03 '18 01:11 jignparm

@vaeksare @jignparm : Still hitting the same exception " System.Runtime.InteropServices.SEHException when loading ONNX models"

As suggested I've made the following changes

  • I've placed the model file is where the executable is run from (inside bin\x64\Debug\netcoreapp2.1)

  • using absolute path for model location

  • Also there is only one model file in the bin folder.

OnnxApp_modified.zip

if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     return;

 string path = System.Reflection.Assembly.GetExecutingAssembly().Location;

 var modelFile = Path.GetDirectoryName(path) + "\\sq_model.onnx";

AarthyKS avatar Nov 05 '18 16:11 AarthyKS

The underlying Microsoft.ML.Scoring library doesn't propagate messages from the native layer (to be fixed soon).

This is the error message using an updated version of the library (to be released soon)-- it looks like there's no suitable kernel definition for the RELU op. What is the source of your model? Did you convert using MLTools, or some other method?

aarthy_error

jignparm avatar Nov 09 '18 05:11 jignparm

The model was not created using MLtools. The model is from ONNX model zoo . It is mentioned that it was created in Caffe2.

AarthyKS avatar Nov 09 '18 16:11 AarthyKS

Onnx is not backwards compatible to 1.1 as far as I understand. The version of Onnx models supported by the transform is 1.2.

The squeezenet model from the model zoo below works without any problems.

https://s3.amazonaws.com/download.onnx/models/opset_7/squeezenet.tar.gz

jignparm avatar Nov 09 '18 18:11 jignparm

Marking this as resolved. Reopen if necessary.

jignparm avatar Dec 12 '18 17:12 jignparm