0

I have this code:

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)

When I compile it I get the following error:

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

Because the input node of the model I am using is Uinteger and the default vector Image generated by ImageEstimatorsCatalog.ExtractPixels is a float.

I tried to do the conversion using:

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

But it does not work.

Any ideas on how to convert from float to Uinteger in the pipeline?

Thanks

  • Wow, I didn't realize that VB.NET doesn't have extension methods, so your pipeline composition is rather ugly. – Zruty Dec 09 '18 at 05:04
  • @Zruty VB does have extension methods, and they work roughly identically to extension methods in C#, the only significant difference is that you use the `` attribute to create them and the first parameter is implicitly the `this` parameter from a C# extension method. – Craig Dec 10 '18 at 15:05

1 Answers1

0

If the standard conversion from float to byte (via ConvertType) doesn't work, the only thing I can recommend is to use a custom mapping.

Here is a snippet of code that demonstrates custom mapping in ML.NET.

Zruty
  • 8,377
  • 1
  • 25
  • 31