dotnet / machinelearning-samples

Samples for ML.NET, an open source and cross-platform machine learning framework for .NET.
https://dot.net/ml
MIT License
4.5k stars 2.69k forks source link

Help in Pre-processing image when tiny yolo converted to ONNX #806

Closed VinuthaRaghavendra closed 4 years ago

VinuthaRaghavendra commented 4 years ago

Hi, I have trained tinyyolo in tensorflow and converted to .onnx using tf2onnx.

I have trained grayscaled 3 channeled image having offset 32, normalization (0-1). Tried the onnxruntime inference in python and predictions are exact. But predictions using winmltools in ml.net results condifence score always equal to 99 (pixels are incorrect)

using var pipeline = mlContext.Transforms.ResizeImages(outputColumnName: onnxModel.ModelInput,imageWidth: ImageSettings.imageWidth, imageHeight: ImageSettings.imageHeight,inputColumnName: nameof(ImageInputData.Image)) .Append(mlContext.Transforms.ExtractPixels(outputColumnName: onnxModel.ModelInput, offsetImage: 32f,scaleImage: 1/255f)) .Append(mlContext.Transforms.ApplyOnnxModel(modelFile: onnxModel.ModelPath, outputColumnName: onnxModel.ModelOutput, inputColumnName: onnxModel.ModelInput))

Can you please suggest the solution to preprocess image using onnx to have correct predictions

luisquintanilla commented 4 years ago

Hi @VinuthaRaghavendra ,

Thank you for your question. I think this is more of a product question and would suggest raising an issue on the dotnet/machinelearning.

In general, you can take a look at this sample which scores using an ONNX model and normalizes the images beforehand.

Sample

https://github.com/dotnet/machinelearning-samples/blob/master/samples/modelbuilder/ImageClassification_Azure_LandUse

ML.NET Pipeline

https://github.com/dotnet/machinelearning-samples/blob/8697bec3e9c78beb2c3c4d3f915551c85bcdcb39/samples/modelbuilder/ImageClassification_Azure_LandUse/LandUseML.ConsoleApp/ModelBuilder.cs#L37

Normalization Custom Transform: https://github.com/dotnet/machinelearning-samples/blob/master/samples/modelbuilder/ImageClassification_Azure_LandUse/LandUseML.Model/NormalizeMapping.cs