good day!
i have a situation while trying to process several images in a batch using c#, NumSharp and an onnx model
See an extract code below:
var modelPath = @"Resources/model_20221026.onnx";
var outputColumnNames = new[] { "dense_4" };
var inputColumnNames = new[] { "input_5" };
var mlContext = new MLContext();
var pipeline = mlContext.Transforms.ApplyOnnxModel(outputColumnNames, inputColumnNames, modelPath);
var img0 = Bitmap.FromFile(path, true);
var content = ResizeImage(img0, 512, 512);
img0.Dispose();
var data0 = content.ToNDArray(flat: false, copy: false);
var dataNP = np.array(data0).astype(NPTypeCode.Single).flatten().ToArray<float>();
content.Dispose();
var input = new Input { Data = dataNP };
var dataView = mlContext.Data.LoadFromEnumerable(new[] { input });
var transformedValues = pipeline.Fit(dataView).Transform(dataView);
var output = mlContext.Data.CreateEnumerable<Output>(transformedValues, reuseRowObject: false);
float[] probabilities = output.Single().Data;
float defect = (float)Math.Round(100 * probabilities[0], 2);
float nodefect = (float)Math.Round(100 * probabilities[1], 2);
string[] NameImg = path.Split('\\');
Logger.Info("------------ID: "
+ " " + NameImg[NameImg.Length - 1]
+ " - Defect: " + defect + "%"
+ " - NoDefect: " + nodefect + "%");
It will do it once, sometimes twice, but then, it will crash. The application will crash suddently, and won't write in logs anything if i try to catch any argument error.
If i try in debug mode i get this error:
Any idea is very welcome, thanks!
I tried in: Debug mode Disposing contents Instead of opening a file with Bitmap.FromFile, i tried to stream the content I try catching arguments exceptions and exceptions in general