2

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;
        }

Model Prediction:

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

Paul Nell
  • 21
  • 1
  • 2
  • You seem to be using some bug report template, that is not used here, you need to explain the problem and put code in your question, not as external links. – Dr. Snoopy Jun 24 '22 at 09:20
  • 1
    @Dr.Snoopy Sorry, I added the important snippets – Paul Nell Jun 24 '22 at 09:52
  • Same thing, two lines from a backtrace is not useful, there is no contex to relate it to your code. And please never put code as images! only as text. – Dr. Snoopy Jun 24 '22 at 10:36

0 Answers0