-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
P1Priority of the issue for triage purpose: Needs to be fixed soon.Priority of the issue for triage purpose: Needs to be fixed soon.bugSomething isn't workingSomething isn't workingimageBugs related image datatype tasksBugs related image datatype tasksloadsaveBugs related loading and saving data or modelsBugs related loading and saving data or modelsonnxExporting ONNX models or loading ONNX modelsExporting ONNX models or loading ONNX models
Description
System information
- win 10:
- 1.3.1:
I was trying to create a PredictEngine using a saved model. I found out that if I directly use the ITransformer
retrieve from Pipeline.Fit
, the CreatePredictionEngine
works well. But after I save/reload it, then it will give the following error
The code for the pipeline is like this
public static IEstimator<ITransformer> BuildTrainingPipeline(MLContext mlContext)
{
// Data process configuration with pipeline data transformations
var dataProcessPipeline = mlContext.Transforms.Conversion.MapValueToKey("Label", "Label")
.Append(mlContext.Transforms.LoadImages("ImagePath_featurized", @"C:\Users\xiaoyuz\Desktop\machinelearning-samples\datasets\images", "ImagePath"))
.Append(mlContext.Transforms.ResizeImages("ImagePath_featurized", 224, 224, "ImagePath_featurized"))
.Append(mlContext.Transforms.ExtractPixels("ImagePath_featurized", "ImagePath_featurized"))
.Append(mlContext.Transforms.DnnFeaturizeImage("ImagePath_featurized", m => m.ModelSelector.ResNet18(mlContext, m.OutputColumn, m.InputColumn), "ImagePath_featurized"))
.Append(mlContext.Transforms.Concatenate("Features", new[] { "ImagePath_featurized" }))
.Append(mlContext.Transforms.NormalizeMinMax("Features", "Features"))
.AppendCacheCheckpoint(mlContext);
// Set the training algorithm
var trainer = mlContext.MulticlassClassification.Trainers.OneVersusAll(mlContext.BinaryClassification.Trainers.AveragedPerceptron(labelColumnName: "Label", numberOfIterations: 10, featureColumnName: "Features"), labelColumnName: "Label")
.Append(mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel", "PredictedLabel"));
var trainingPipeline = dataProcessPipeline.Append(trainer);
return trainingPipeline;
}
And ModelInput
and ModelOutput
class is like this
public class ModelInput
{
[ColumnName("Label"), LoadColumn(0)]
public string Label { get; set; }
[ColumnName("Title"), LoadColumn(1)]
public string Title { get; set; }
[ColumnName("Url"), LoadColumn(2)]
public string Url { get; set; }
[ColumnName("ImagePath"), LoadColumn(3)]
public string ImagePath { get; set; }
}
public class ModelOutput
{
// ColumnName attribute is used to change the column name from
// its default value, which is the name of the field.
[ColumnName("PredictedLabel")]
public String Prediction { get; set; }
public float[] Score { get; set; }
}
It's really wield though. And my description may not be that detailed. If you need further information, please let me know
Metadata
Metadata
Assignees
Labels
P1Priority of the issue for triage purpose: Needs to be fixed soon.Priority of the issue for triage purpose: Needs to be fixed soon.bugSomething isn't workingSomething isn't workingimageBugs related image datatype tasksBugs related image datatype tasksloadsaveBugs related loading and saving data or modelsBugs related loading and saving data or modelsonnxExporting ONNX models or loading ONNX modelsExporting ONNX models or loading ONNX models