
Hi !
I haven’t write a lot about ML.NET Command-Line Interface (CLI) (see references), and that’s a shame. It’s very powerful and also it supports most of the ML.Net features, like in example: Model Builder Image Classification scenario.
The ML.NET CLI automates model generation for .NET developers.
ML.Net CLI Documentation
To use the ML.NET API by itself, (without the ML.NET AutoML CLI) you need to choose a trainer (implementation of a machine learning algorithm for a particular task), and the set of data transformations (feature engineering) to apply to your data. The optimal pipeline will vary for each dataset and selecting the optimal algorithm from all the choices adds to the complexity. Even further, each algorithm has a set of hyperparameters to be tuned. Hence, you can spend weeks and sometimes months on machine learning model optimization trying to find the best combinations of feature engineering, learning algorithms, and hyperparameters.
The ML.NET CLI simplifies this process using automated machine learning (AutoML).
So, let’s take a look at the basic sample for an Image Recognition scenario with ML.Net CLI. It starts with a set of images, organized in folders. Each folder will represent the label for the image.

The only required parameter is [–dataset], with the location if the folder with images.

I’ll use the following command to also define the output project name and the log file location
mlnet image-classification --dataset "SimpleDrawings" --log-file-path "d:\src\Labs\mlnet\logs" --name "SimpleDrawingsBlog"
The process takes sometime, and when it is finished, it generates 2 projects, to consume the model and to generate a new model.

Note: somehow the parameter -name, didn’t generate the specified name for my output project. Time to refactor later.

Testing the generated model with a custom image, give us the following ouput.
2020-10-19 14:09:47.512322: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Using model to make single prediction -- Comparing actual Label with predicted Label from sample data...
ImageSource: D:\src\Labs\mlnet\SimpleDrawings\fish\i-1238b28c03144be496b7f54d82667fc6.jpg
Predicted Label value fish
Predicted Label scores: [0.98024565,0.015911957,0.0038424365]
=============== End of process, hit any key to finish ===============
Which comes, from the predicted label (top scorer), and also the scores for each one of the labels.
// Create single instance of sample data from first line of dataset for model input
ModelInput sampleData = new ModelInput()
{
ImageSource = @"D:\src\Labs\mlnet\SimpleDrawings\fish\i-1238b28c03144be496b7f54d82667fc6.jpg",
};
// Make a single prediction on the sample data and print results
var predictionResult = ConsumeModel.Predict(sampleData);
Console.WriteLine("Using model to make single prediction -- Comparing actual Label with predicted Label from sample data...\n\n");
Console.WriteLine($"ImageSource: {sampleData.ImageSource}");
Console.WriteLine($"\n\nPredicted Label value {predictionResult.Prediction} \nPredicted Label scores: [{String.Join(",", predictionResult.Score)}]\n\n");
Console.WriteLine("=============== End of process, hit any key to finish ===============");
Super easy !
Happy coding!
Greetings
El Bruno
More posts in my blog ElBruno.com.
More info in https://beacons.ai/elbruno
Resources
- VoTT
- VoTT Releases
- ML.NET Model Builder GPU vs CPU test: 4 times faster !
- MLNet β AutoML for ranking scenarios
- ML.NET Model Builder GPU Support (Preview)
- ML.NET Model Builder training using GPU, CPU and β¦ Azure !
- ML.NET Model Builder for Object Detection using Azure Compute
- ML.NET Command Line Interface (CLI)
- How to install GPU support in Model Builder
- August ML.NET API and Tooling Updates
- State Farm Distracted Driver Detection
- How to Train TensorFlow Models Using GPUs
What happens when I select an input other than fish, flower, human? How does it know that it is not on training data?
LikeLike