System Information:
- Windows 10
- ML.NET Version: ML.NET v1.7.1
- .NET Version: .NET 6.0
Bug description When I tried to get a prediction from a new trained model, the error
System.ArgumentOutOfRangeException: 'Could not find input column 'ImagePath'
Parameter name: inputSchema'
Expected behavior The final model should be saved & used for prediction.
Code Snippets Model Creation:
public static void Run()
{
MLContext mlContext = new MLContext();
var model = GenerateModel(mlContext);
}
private static ITransformer GenerateModel(MLContext mlContext)
{
IEstimator<ITransformer> pipeline = mlContext.Transforms.LoadImages(outputColumnName: "input", imageFolder: _imagesFolder, inputColumnName: nameof(ImageData.ImagePath))
// The image transforms transform the images into the model's expected format.
.Append(mlContext.Transforms.ResizeImages(outputColumnName: "input", imageWidth: InceptionSettings.ImageWidth, imageHeight: InceptionSettings.ImageHeight, inputColumnName: "input"))
.Append(mlContext.Transforms.ExtractPixels(outputColumnName: "input", interleavePixelColors: InceptionSettings.ChannelsLast, offsetImage: InceptionSettings.Mean))
.Append(mlContext.Model.LoadTensorFlowModel(_inceptionTensorFlowModel).
ScoreTensorFlowModel(outputColumnNames: new[] { "softmax2_pre_activation" }, inputColumnNames: new[] { "input" }, addBatchDimensionInput: true))
.Append(mlContext.Transforms.Conversion.MapValueToKey(outputColumnName: "LabelKey", inputColumnName: "Label"))
.Append(mlContext.MulticlassClassification.Trainers.LbfgsMaximumEntropy(labelColumnName: "LabelKey", featureColumnName: "softmax2_pre_activation"))
.Append(mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabelValue", "PredictedLabel"))
.AppendCacheCheckpoint(mlContext);
IEnumerable<ImageData> temp = LoadImagesFromDirectory(folder: _imagesFolder, useFolderNameAsLabel: true);
IDataView trainingData = mlContext.Data.LoadFromEnumerable(temp);
ITransformer createdModel = pipeline.Fit(trainingData);
mlContext.Model.Save(createdModel, trainingData.Schema, "FaceModel.zip");
return createdModel;
}
private static PredictionEngine<ModelInput, ModelOutput> CreatePredictEngine()
{
var mlContext = new MLContext();
ITransformer mlModel = mlContext.Model.Load(MLNetModelPath, out var _);
return mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(mlModel);
}
The two methods get called after each other, the existing FaceModel.zip will be replaced at the end of the first method. 2nd is working with a "non code trained" model, made with the vs model creator.
Additional context GitHub Repository: https://github.com/paul1610/csharp-faceid