I am using the NuGet packages Microsoft.ML (1.4.0) and SciSharp.TensorFlow.Redist (1.15.0)
Initial training and saving the model works fine
var options = new Microsoft.ML.Vision.ImageClassificationTrainer.Options()
{
FeatureColumnName = "Image",
LabelColumnName = "LabelAsKey",
Arch = Microsoft.ML.Vision.ImageClassificationTrainer.Architecture.InceptionV3,
Epoch = 50,
BatchSize = 10,
LearningRate = 0.01f,
MetricsCallback = (metrics) => Console.WriteLine(metrics),
ValidationSet = testDataView
};
var pipeline = mlContext.MulticlassClassification.Trainers.ImageClassification(options)
.Append(mlContext.Transforms.Conversion.MapKeyToValue(
outputColumnName: "PredictedLabel",
inputColumnName: "PredictedLabel"));
ITransformer trainedModel = pipeline.Fit(trainDataView);
mlContext.Model.Save(trainedModel, trainDataView.Schema, "C:/Temp/model.zip")
And using the model to make predictions works fine
var loadModel = mlContext.Model.Load("C/Temp/Model.zip", out var modelInputSchema)
var PredictionEngine = mlContext.Model.CreatePredictionEngine<InMemoryImageData, ImagePrediction>(loadModel);
prediction = PredictionEngine.Predict(image);
But if I want to continue training the model.zip file with more images without retraining from the baseline model from scratch, how do I do that?
Is there I way I can call .Fit()
again that uses the loaded model?
ML.NET doesn't support resuming training for image classification trainers. Currently, the only trainers that support it are the following: https://learn.microsoft.com/en-us/dotnet/machine-learning/how-to-guides/retrain-model-ml-net