Skip to content

Fault convert to ONNX object detection model #6810

Open
@ogoun

Description

@ogoun

System Information:

  • OS & Version: Windows 10
  • ML.NET Version: ML.NET v3.0.0-preview.23266.6
  • .NET Version: .NET 7.0

Describe the bug
Fault conversion to ONNX

To Reproduce
Steps to reproduce the behavior:

  1. Train object detection model by tutorial (https://devblogs.microsoft.com/dotnet/object-detection-ml-dotnet-model-builder/)
  2. Try convert model
public class ModelInput
        {
            [LoadColumn(0)]
            [ColumnName(@"Labels")]
            public string[] Labels { get; set; }

            [LoadColumn(1)]
            [ColumnName(@"Image")]
            [Microsoft.ML.Transforms.Image.ImageType(640, 640)]
            public MLImage Image { get; set; }

            [LoadColumn(2)]
            [ColumnName(@"Box")]
            public float[] Box { get; set; }

        }

public static void Export()
        {
            var onnxPath = "test.onnx";
            var mlContext = new MLContext();
            ITransformer mlModel = mlContext.Model.Load(MLNetModelPath, out var _);

            var input = new ModelInput[30];
            for (int i = 0; i < input.Length; i++)
            {
                input[i] = new ModelInput
                {
                    Image = MLImage.CreateFromFile(@"demo.jpg")
                };
            }
            IDataView trainingData = mlContext.Data.LoadFromEnumerable(input);
            using (var onnx = File.Open(onnxPath, FileMode.OpenOrCreate))
            {
                mlContext.Model.ConvertToOnnx(mlModel, trainingData, onnx);
            }
        }
  1. Got error
    System.InvalidOperationException: 'Unsupported type: Microsoft.ML.Data.MLImage'

Expected behavior
Got onnx model

Additional context
If I try to represent the input as an array [B,3,W,H], it says that it expects an image, when I pass the image, it says that it does not support it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    untriagedNew issue has not been triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions