dotnet / dotnet/machinelearning
Using Variables as parameters instead of constant in ML.NET
- Dominant language
- C#
- Stars
- 9.4k
- Forks
- 2k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 11
Description
**System Information (please complete the following information):**
- OS & Version: [e.g. Windows 10] - Windows 10
- ML.NET Version: [e.g. ML.NET v1.5.5] - ML.Net 1.4
- .NET Version: [e.g. .NET 5.0] - .Net 6.0
**Describe the bug**
A clear and concise description of what the bug is.
I have some attribute value in code which is being used in ML.Net code. Ml.Net is accepting constants for these attributes. I need to use variables so that I can supply it at runtime.
**To Reproduce**
Steps to reproduce the behavior:
Have attached source code. Below class is used in ML.Net - public class ImageInput, public class ImagePredictions
Above class is used to initialize ML.Net as below :
//Initialize MLContext
MLContext mlContext = new MLContext();
//Load Data
List emptyData = new List();
var data = mlContext.Data.LoadFromEnumerable(emptyData);
**Expected behavior**
A clear and concise description of what you expected to happen.
I should be able to use variables when initializing ML.Net
**Screenshots, Code, Sample Projects**
If applicable, add screenshots, code snippets, or sample projects to help explain your problem.
Code sample attached.
public struct ImageSettings
{
public const int imageHeight = 416;
public const int imageWidth = 416;
}
public class ImageInput
{
[ImageType(ImageSettings.imageHeight, ImageSettings.imageWidth)]
public Bitmap Image { get; set; }
}
public class ImagePredictions
{
[ColumnName("model_outputs0")]
public float[] PredictedLabels { get; set; }
}
//Initialize MLContext
MLContext mlContext = new MLContext();
//Load Data
List emptyData = new List();
var data = mlContext.Data.LoadFromEnumerable(emptyData);
var pipeline = mlContext.Transforms.ResizeImages(resizing: ImageResizingEstimator.ResizingKind.Fill, outputColumnName: "data", imageWidth: ImageSettings.imageWidth, imageHeight: ImageSettings.imageHeight, inputColumnName: nameof(ImageInput.Image))
.Append(mlContext.Transforms.ExtractPixels(outputColumnName: "data", orderOfExtraction: ImagePixelExtractingEstimator.ColorsOrder.ARGB))
.Append(mlContext.Transforms.ApplyOnnxModel(modelFile: modeltoInfer.ModelPath, outputColumnName: "model_outputs0", inputColumnName: "data"));
var model = pipeline.Fit(data);
predictionEngine = mlContext.Model.CreatePredictionEngine(model);
**Additional context**
Add any other context about the problem here.
Contributor guide
Assessment
This issue has not been assessed yet.