Microsoft.ML.Net "Can't bind the IDataView column to field or property"

Microsoft.ML.Net "Can't bind the IDataView column to field or property"

希望你一切顺利。我有以下问题。我正在使用 onnx 训练模型在 C# 中使用 ML.NET 进行推理。这是代码。

static void Main(string[] args)
    {
        MLContext mlContext = new MLContext();
        var onnxPredictionPipeline = GetPredictionPipeline(mlContext);
        var onnxPredictionEngine = mlContext.Model.CreatePredictionEngine<OnnxInput, OnnxOutput>(onnxPredictionPipeline);
        OnnxInput input_data = new OnnxInput();
        float[] data = new float[ 70];
        float[] action_mask = new float[ 8];
        input_data.Input = data;
        input_data.ActionMasks = action_mask;
        var prediction = onnxPredictionEngine.Predict(input_data);
        Console.WriteLine($"Predicted Actions: {prediction.Actions.First()}");
    }
public class OnnxInput
    {
        [ColumnName("obs_0")]
        [VectorType(1, 70 )]
        public float[] Input { get; set; }

        [ColumnName("action_masks")]
        [VectorType(1, 8)]
        public float[] ActionMasks { get; set; }

    }

    public class OnnxOutput
    {
        [ColumnName("discrete_actions")]
        [VectorType(1, 1)]
        public int[] Actions { get; set; }
        public float [] Score { get;set; }
    }

    static ITransformer GetPredictionPipeline(MLContext mlContext)
    {
        var inputColumns = new string[]
        {
        "obs_0", "action_masks",
       };

        var outputColumns = new string[] { "discrete_actions" };

        var onnxPredictionPipeline =
        mlContext
        .Transforms
        .ApplyOnnxModel(
            outputColumnNames: outputColumns,
            inputColumnNames: inputColumns,
            ONNX_MODEL_PATH);



        var emptyDv = mlContext.Data.LoadFromEnumerable(new OnnxInput[] {});
        
        return onnxPredictionPipeline.Fit(emptyDv);
    }`

当我 运行 它给了我以下错误: System.InvalidOperationException: 'Can't bind IDataView column 'discrete_actions' of type 'Vector<Int64, 1, 1>' to field or 属性 'Actions' 类型 'System.Int32[]'。' 我的 onnx 网络 [https://drive.google.com/file/d/14cvBskPLTbNTSG-hxusRrbrEE8QNgf6c/view?usp=sharing]

有什么建议吗?

考虑使用 OnnxMapType 属性。下面是一个示例,说明如何在定义架构时使用它。

https://docs.microsoft.com/azure/machine-learning/how-to-use-automl-onnx-model-dotnet#define-model-input-schema

https://docs.microsoft.com/dotnet/api/microsoft.ml.transforms.onnx.onnxmaptype.-ctor?view=ml-dotnet#Microsoft_ML_Transforms_Onnx_OnnxMapType__ctor_System_Type_System_Type_