dotnet / dotnet/machinelearning

Alternate Fit() with no IDataView parameter for cases where data is not needed (i.e. Scoring a Tensorflow model)

Open
#3,795 0 comments 0 reactions 0 assignees View on GitHub
area-Core Priority:2
Dominant language
C#
Stars
9.4k
Forks
2k
Avg merge
2d 20h
Merged PRs (30d)
11

Description

The following is a typical case when you prepare a pipeline only for scoring with a TensorFlow model:

```
private ITransformer SetupMlnetModel(string imagesFolderPath, string tensorFlowModelFilePath)
{
var pipeline = _mlContext.Transforms.LoadImages(outputColumnName: TensorFlowModelSettings.inputTensorName, imageFolder: imagesFolderPath, inputColumnName: nameof(ImageInputData.ImagePath))
.Append(_mlContext.Transforms.ResizeImages(outputColumnName: TensorFlowModelSettings.inputTensorName, imageWidth: ImageSettings.imageWidth, imageHeight: ImageSettings.imageHeight, inputColumnName: TensorFlowModelSettings.inputTensorName))
.Append(_mlContext.Transforms.ExtractPixels(outputColumnName: TensorFlowModelSettings.inputTensorName, interleavePixelColors: ImageSettings.channelsLast, offsetImage: ImageSettings.mean))
.Append(_mlContext.Model.LoadTensorFlowModel(tensorFlowModelFilePath).
ScoreTensorFlowModel(outputColumnNames: new[] { "loss" },
inputColumnNames: new[] { "Placeholder" }, addBatchDimensionInput: false));

ITransformer mlModel = pipeline.Fit(CreateEmptyDataView());
return mlModel;
}
private IDataView CreateEmptyDataView()
{
//Create empty DataView. We just need the schema to call fit()
List list = new List();
list.Add(new ImageInputData() { ImagePath = "" });
IEnumerable enumerableData = list;

var dv = _mlContext.Data.LoadFromEnumerable(list);
return dv;
}
```

The issue with that API is that Fit(IDataView idv) always requires an IDataView as parameter, but in this case, data is not needed, it just needs the IDataView schema.

Currently you just create an "Empty DataView" and from there, the schema will be taken.
This seems like a workaround but it doesn't make sense for the user to create an empty structure/DataView:

Possible proposal:

Allow a parameter-less for the "Fit()" method and by simply providing as a generic what's the data type to use as the base to generate the IDataView schema, such as:

` .Fit();`

Basically, internally it would run the code I have in the `CreateEmptyDataView()` method.

Additional solutions or thoughts to improve this API?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.