Mars
Mars

Reputation: 2572

How does ML.NET detect the end of a method-chain in C#?

I ran into a bug using ML.NET Transforms.

The pipeline is set up by declaring a Transform and then appending more transforms to it, like so:

var pipeline = mlContext.Transforms.ResizeImages(outputColumnName: "image",
                    imageWidth: imageWidth, 
                    imageHeight: imageHeight, 
                    inputColumnName: nameof(ImageNetData.Image)) // Resizes the image
                .Append(mlContext.Transforms.ExtractPixels(outputColumnName: "image",
                    inputColumnName: "image")) //Transforms the image to floats
                .Append(mlContext.Transforms.ApplyOnnxModel(modelFile: modelLocation,
                    outputColumnNames: new[] { TinyYoloModelSettings.ModelOutput}, 
                    inputColumnNames: new[] { TinyYoloModelSettings.ModelInput }));// Runs the image through the network
//Output: An EstimatorChain that runs ALL THREE above steps

But running the same code without method-chaining produces a different output.

var pipeline = mlContext.Transforms.ResizeImages(outputColumnName: "image",
                    imageWidth: imageWidth, 
                    imageHeight: imageHeight, 
                    inputColumnName: nameof(ImageNetData.Image)); // Resizes the image
pipeline.Append(mlContext.Transforms.ExtractPixels(outputColumnName: "image",
                   inputColumnName: "image")); //Transforms the image to floats
pipeline.Append(mlContext.Transforms.ApplyOnnxModel(modelFile: modelLocation,
                    outputColumnNames: new[] { TinyYoloModelSettings.ModelOutput}, 
                    inputColumnNames: new[] { TinyYoloModelSettings.ModelInput }));// Runs the image through the network
//Output: An EstimatorChain that runs only the first step

What is it about method chaining that produces a different output?

Upvotes: 2

Views: 200

Answers (1)

Kazys
Kazys

Reputation: 477

I assume pipeline is immutable and Append returns copy of pipeline with transform appended, so original pipeline is not affected.

From the docs

"Create a new transformer chain, by appending another transformer to the end of this transformer chain."

Upvotes: 4

Related Questions