如何在ML.Net管道中将R4转换为U1?

时间:2018-12-07 18:14:09

标签: vb.net tensorflow ml.net

我有此代码:

Dim pipeline = ImageEstimatorsCatalog.LoadImages(mlContext.Transforms, 
imagesFolder, ("ImagePath", "ImageReal")).
        Append(ImageEstimatorsCatalog.Resize(mlContext.Transforms, "ImageReal", "ImageReal", ImageNetSettings.imageHeight, ImageNetSettings.imageWidth, resizing:=ImageResizerTransform.ResizingKind.IsoPad)).
        Append(ImageEstimatorsCatalog.ExtractPixels(mlContext.Transforms, {New ImagePixelExtractorTransform.ColumnInfo("ImageReal", "image_tensor",
                                 colors:=ImagePixelExtractorTransform.ColorBits.Rgb, interleave:=ImageNetSettings.channelsLast,
                                 offset:=ImageNetSettings.mean, scale:=ImageNetSettings.scale)})).
        Append(New TensorFlowEstimator(mlContext, modelLocation, {"image_tensor"}, {"detection_scores", "detection_boxes", "detection_classes", "num_detections"}))

Dim modeld = pipeline.Fit(data)

编译时出现以下错误:

Schema mismatch for input column 'image_tensor': expected U1, got R4
Parameter name: inputSchema

因为我使用的模型的输入节点是Uinteger,并且由ImageEstimatorsCatalog.ExtractPixels生成的默认矢量Image是浮点数。

我尝试使用以下方法进行转换:

Append(ConversionsExtensionsCatalog.ConvertType(mlContext.Transforms.Conversion,
"image_tensor", "image_tensor", DataKind.U1))

但这不起作用。

关于如何在管道中从float转换为Uinteger的任何想法?

谢谢

1 个答案:

答案 0 :(得分:0)

如果从浮点数到字节的标准转换(通过ConvertType)不起作用,那么我唯一推荐的就是使用自定义映射。

Here是演示ML.NET中自定义映射的代码段。