ML. NET: 'Длина памяти (691200) должна соответствовать произведению размеров (3).' - PullRequest
0 голосов
/ 10 июля 2020

У меня проблема с построением конвейера в ML. NET. Когда я пытаюсь предсказать, он выдает следующую ошибку:

System.ArgumentException: 'Length of memory (691200) must match product of dimensions (3).'

Конвейер следующий:

            var pipeline = _mlContext.Transforms
                .ResizeImages(
                    outputColumnName: "resized_image",
                    imageWidth: 640,
                    imageHeight: 360,
                    inputColumnName: "image")
                .Append(_mlContext.Transforms
                    .ExtractPixels(
                        outputColumnName: ModelConfigParameters.InputColumns.First(),
                        outputAsFloatArray: false,
                        colorsToExtract: ImagePixelExtractingEstimator.ColorBits.Rgb,
                        orderOfExtraction: ImagePixelExtractingEstimator.ColorsOrder.ARGB,
                        interleavePixelColors: false,
                        inputColumnName: "resized_image"))
                .Append(_mlContext.Transforms
                    .ApplyOnnxModel(
                        modelFile: onnxModelPath,
                        outputColumnNames: ModelConfigParameters.OutputColumns,
                        inputColumnNames: ModelConfigParameters.InputColumns));

Входной объект:

    public class InputImage
{
    //ToDo:Load image size from some config file
    [ImageType(width: 640, height: 360)]
    [ColumnName("image")]
    public Bitmap Image { get; set; }

}

Прогноз объект:

    public class OutputPredictions
{
    [ColumnName("detection_scores:0")]
    public float[] DetectionScores;

    [ColumnName("detection_boxes:0")]
    public float[] DetectionBoxes;

    [ColumnName("detection_classes:0")]
    public float[] DetectionClasses;

    [ColumnName("num_detections:0")]
    public float[] NumDetections;
}

И я делаю прогноз, используя:

        var imgPath = @"some/path/to/image.png";
        var img = (Bitmap)Image.FromFile(imgPath);
        var inputData = new InputImage() { Image = img };

        var emptyData = _mlContext.Data.LoadFromEnumerable(new List<InputImage>());
        var model = pipeline.Fit(emptyData);

        var prediction = _mlContext.Model.CreatePredictionEngine<InputImage, OutputPredictions>(model).Predict(inputData);
 

Запустив его, я получаю ранее упомянутую ошибку. Когда я проверяю трубопровод с помощью var preview = pipeline.Preview(emptyData);, я получаю следующую схему: enter image description here

and the input and output of the ONNX model is following: введите описание изображения здесь

Не вижу проблемы. Что это могло быть?

...