使用ml.net和TensorFlow模型的位图输入的标量而非向量类型

问题描述

我开始熟悉ml.Net,尤其是在使用预训练的TensorFlow模型进行图像分类的情况下。

该任务的现有示例(https://github.com/dotnet/machinelearning-samples/tree/master/samples/csharp/getting-started/DeepLearning_ImageClassification_TensorFlow)运行正常。我还设法使其适应使用内存中的图像,而不是将其加载到管道中。

下一步是使用内部TensorFlow模型,这就是问题所在。

该模型可以有几张图像作为输入,而不是一张,而且我没有让输入数据结构运行。

模型请求作为输入类型:

Vector<Single,275,384,3>

输入的描述是: 。

在我的数据结构中,我尝试使用位图数组(而不是像上面提到的修改示例中那样使用单个位图)。具有输入列的映射和图像尺寸的定义。

public class ImageData
{

    [ColumnName("serving_default_input_4"),ImageType(275,384)]
    public Bitmap[] Input { get; set; }
}

public class ImagePrediction : ImageData
{
    [ColumnName("StatefulPartitionedCall")]
    public float[] scores { get; set; }
}

因此,当我尝试创建空数据以进行拟合时(在行中:var data = mlContext.Data.LoadFromEnumerable(new List());),我得到了一个例外,期望标量为数据类型。

//Pipeline
IEstimator<ITransformer> pipeline = mlContext.Transforms.ResizeImages(outputColumnName: "serving_default_input_4",imageWidth: 384,imageHeight: 275,inputColumnName: "serving_default_input_4")
                    .Append(mlContext.Transforms.ExtractPixels("serving_default_input_4","serving_default_input_4"))
                    .Append(mlContext.Model.LoadTensorFlowModel(_testTensorFlowModel)
                    .scoreTensorFlowModel(outputColumnNames: new[] { "StatefulPartitionedCall" },inputColumnNames: new[] { "serving_default_input_4" },addBatchDimensionInput: true));

//Fitting
var data = mlContext.Data.LoadFromEnumerable(new List<ImagePrediction>()); // This line crashes
ITransformer model = pipeline.Fit(data);

我收到的异常是:

System.ArgumentOutOfRangeException
  HResult=0x80131502
  Message = Column 'serving_default_input_4' is supposed to be scalar,but type of associated field 'Input' is vector 
  Source= microsoft.ml.Data
  

我想我的问题与ImageData中的图像列表的定义有关,但我看不到...到目前为止,我对如何声明标量数据类型的研究并没有真正的帮助。

也许有人有想法或提示

谢谢。

一些系统信息:

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)