【问题标题】:Microsoft.ML.Net "Can't bind the IDataView column to field or property"Microsoft.ML.Net“无法将 IDataView 列绑定到字段或属性”
【发布时间】:2021-08-24 10:48:18
【问题描述】:

希望你做得很好。我有以下问题。我正在使用 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 the IDataView column 'discrete_actions' of type 'Vector' to field or property 'Actions' of type 'System.Int32[]'。 我的 onnx 网络 [https://drive.google.com/file/d/14cvBskPLTbNTSG-hxusRrbrEE8QNgf6c/view?usp=sharing]

有什么建议吗?

【问题讨论】:

    标签: c# ml.net


    【解决方案1】:
    猜你喜欢
    • 2022-06-11
    • 2012-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-23
    • 1970-01-01
    相关资源
    最近更新 更多