Closed Phoenix-313 closed 4 years ago
Hi @Phoenix-313 ,
When you train using the image classification API, 2 models are created. In the workspace directory that's provided in the sample, the TensorFlow .pb version of the model is saved. However, I'm guessing you want to use the ML.NET version of the model. That model in this case is the trainedModel
ITransformer
object. This model you can use just like you would any other model in ML.NET.
See this example for how to save the model.
// Save the trained model.
mlContext.Model.Save(trainedModel, shuffledFullImagesDataset.Schema,"model.zip");
// Load the trained and saved model for prediction.
ITransformer loadedModel;
DataViewSchema schema;
using (var file = File.OpenRead("model.zip"))
loadedModel = mlContext.Model.Load(file, out schema);
In terms of providing a new image, you would create an IDataView that contains the path of the image you want to predict and using the model you'd create a PredictionEngine
for a single prediction or use the Transform
operation for multiple predictions.
Here's some more general guidance:
Save/Load Model: https://docs.microsoft.com/en-us/dotnet/machine-learning/how-to-guides/save-load-machine-learning-models-ml-net
Use the model to make predictions: https://docs.microsoft.com/en-us/dotnet/machine-learning/how-to-guides/machine-learning-model-predictions-ml-net
Hope this helps.
Hi,
In the tutorial "Tutorial: Automated visual inspection using transfer learning with the ML.NET Image Classification API", how can the trained model be saved and consumed for later? and how to choose the input image that the trained model will classify?
Many thanks!