Registry Mirror
Skip to content

Object Detection - YoloV3 - Corrupted PredictionResult #5810

Open

Description

@Pirner

System information

  • OS Windows 10:
  • .NET 5.0:

Issue

  • Trained a yolov3 object detector
  • The prediction output is wrong and also does not change by changing the input image

Source code / logs

`
var context = new MLContext();

        var emptyData = new List<CountInput>();

        var data = context.Data.LoadFromEnumerable(emptyData);

        var pipeline = context.Transforms.ResizeImages(
                resizing: ImageResizingEstimator.ResizingKind.Fill, 
                outputColumnName: "feed_resized", 
                imageWidth: ImageSettings.imageWidth, 
                imageHeight: ImageSettings.imageHeight, 
                inputColumnName: nameof(CountInput.Image)
            )
            .Append(context.Transforms.ConvertToGrayscale(outputColumnName: "grayscale", inputColumnName: "feed_resized"))
            .Append(context.Transforms.ExtractPixels(
                outputColumnName: "input_1:0", inputColumnName: "grayscale",
                interleavePixelColors: false,
                colorsToExtract: Microsoft.ML.Transforms.Image.ImagePixelExtractingEstimator.ColorBits.Alpha,
                outputAsFloatArray: true,
                scaleImage: .00390625f))
            .Append(context.Transforms.ApplyOnnxModel(
                modelFile: _model_path, 
                outputColumnNames: new[] { "tf.concat_3", "tf.concat_5", "tf.concat_7" }, 
                inputColumnNames: new[] { "input_1:0" })
            );

        var model = pipeline.Fit(data);

        _predictionEngine = context.Model.CreatePredictionEngine<CountInput, CountPrediction>(model);

        string image_path = @"D:\ml_dotnet\tests\test.png";
        var image = (Bitmap)Image.FromFile(image_path);

        var prediction = _predictionEngine.Predict(new CountInput { Image = image });

my assumption is that the data is somehow not correctly transported from the ExtractPixels transformation to the ApplyOnnXModel transformation, that would at least explain why the result always stays the same.

The model has been converted from tensorflow2.

Link to my model: https://drive.google.com/drive/folders/10n6J7Z0NzNTcTCV6dJbzGKoaRZDmWfbo?usp=sharing

I already had a look in it with netron, but looks good to me.
image

I am fairly new to this so bear with me in case anything is missing or I did some obvious mistakes.
I also went through the tutorials (especially regarding object detection), the tutorials itself ran fine but I am still missing something.

Activity

  1. added
    question
    on Jun 3, 2021
  2. michaelgsharp commented on Jun 3, 2021

    @michaelgsharp
    Contributor

    Hi @Pirner. Briefly looking over your code it looks like this line is probably the problem.

                    colorsToExtract: Microsoft.ML.Transforms.Image.ImagePixelExtractingEstimator.ColorBits.Alpha,
    

    You are telling it to only extract the alpha color. Most pictures (that I see anyways) don't really have an alpha color or it is the same value for every pixel. I would try changing that line and see what happens.

    Let me know if this helps/if you have more questions.

  3. Pirner commented on Jun 9, 2021

    @Pirner
    Author

    Hi @michaelgsharp ye I already tried it with blue pixels as well, I just read somewhere that grayscale images are read through alpha channel and gave it a try.

    I also tried converting the images to rgb before feeding them to the pipeline without a result change.

    I checked my input data and everything looked fine.

    I will check again against my python implementation which seems to work and will comeback, I am currently on a vacation and don't have access to the code.

    Thanks for picking up on this, I really appreciate it!

  4. added
    Priority:3
    area-ONNX
    and removed on Sep 8, 2026
  5. added
    yellow
    on Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority:3area-ONNXquestionyellow

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions