{"id":27845,"date":"2020-05-06T11:45:47","date_gmt":"2020-05-06T18:45:47","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet\/?p=27845"},"modified":"2020-05-06T11:45:47","modified_gmt":"2020-05-06T18:45:47","slug":"train-image-classification-model-azure-mlnet-model-builder","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/train-image-classification-model-azure-mlnet-model-builder\/","title":{"rendered":"Using ML.NET for deep learning on images in Azure"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>In March 2020, ML.NET added <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/ml-net-model-builder-updates\/\">support for training Image Classification models in Azure<\/a>. Although the image classification scenario was released in late 2019, users were limited by the resources on their local compute environments. Training in Azure enables users to scale image classification scenarios by using GPU optimized Linux virtual machines.<\/p>\n<p>This post will show how to train a custom image classification model in Azure to categorize flowers using ML.NET Model Builder. Then, you can leverage your existing .NET skills to consume the trained model inside a C# .NET Core console application. Best of all, little to no prior machine learning knowledge is required. Let&#8217;s get started!<\/p>\n<h2>ML.NET Model Builder<\/h2>\n<p><a href=\"https:\/\/github.com\/dotnet\/machinelearning\">ML.NET<\/a> is an open-source and cross-platform machine learning framework for .NET developers. Model Builder is a tool in Visual Studio that provides a graphical user interface that uses Automated Machine Learning (Auto ML) to train and consume custom ML.NET models for your .NET applications.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-27854 size-large\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/choose-scenario-1024x563.png\" alt=\"Model Builder choose a scenario screen\" width=\"640\" height=\"352\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/choose-scenario-1024x563.png 1024w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/choose-scenario-300x165.png 300w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/choose-scenario-768x422.png 768w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/choose-scenario.png 1280w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<h2>Prerequisites<\/h2>\n<p>To follow along, you&#8217;ll need the following prerequisites:<\/p>\n<ul>\n<li><a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\">Visual Studio 2019 16.6 preview 2 or later<\/a><\/li>\n<li>Azure account. If you don&#8217;t have one, you can <a href=\"http:\/\/aka.ms\/AMLFree\">sign up for a free Azure account<\/a>.<\/li>\n<li>.NET Core cross-platform development workload<\/li>\n<\/ul>\n<p>To use Model Builder, make sure to enable the preview feature. In the Visual Studio Menu Bar, select <strong>Tools &gt; Options &gt; Environment &gt; Preview Features<\/strong>. Then, check the <strong>Enable ML.NET Model Builder<\/strong> box.<\/p>\n<h2>Model training workflow<\/h2>\n<p>The process of training models usually consists of the steps outlined below:<\/p>\n<ol>\n<li>Get the data<\/li>\n<li>Create a .NET Core application. This can be a console, desktop, or web application.<\/li>\n<li>Choose a scenario<\/li>\n<li>Configure your training environment<\/li>\n<li>Load the data<\/li>\n<li>Train the model<\/li>\n<li>Evaluate the model<\/li>\n<li>Add the code to make predictions<\/li>\n<\/ol>\n<h2>Add the data<\/h2>\n<p>The dataset used in this guide is based on the <a href=\"https:\/\/storage.googleapis.com\/download.tensorflow.org\/example_images\/flower_photos.tgz\">TensorFlow flower photos dataset<\/a>. All images in this archive are licensed under the Creative Commons By-Attribution License, available at: <a href=\"https:\/\/creativecommons.org\/licenses\/by\/4.0\/\">https:\/\/creativecommons.org\/licenses\/by\/4.0\/<\/a><\/p>\n<p>The full license information is provided in the LICENSE.txt file which is included as part of the same image set.<\/p>\n<p>The dataset is divided into separate subfolders, one for each flower category:<\/p>\n<ul>\n<li>Daisy<\/li>\n<li>Dandelion<\/li>\n<li>Roses<\/li>\n<li>Sunflowers<\/li>\n<li>Tulips<\/li>\n<\/ul>\n<p>Download the data anywhere on your PC and unzip it.<\/p>\n<p>Model Builder requires data to be in a certain format. This dataset is already in the correct format. For more information, see Microsoft Docs to learn more about <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/machine-learning\/how-to-guides\/load-data-model-builder#set-up-image-data-files\">loading data with Model Builder<\/a>.<\/p>\n<h2>Create a .NET Core console application<\/h2>\n<p>The application that consumes the model is a C# .NET Core console application.<\/p>\n<p>Open Visual Studio and create a new C# .NET Core console application. In this case, I&#8217;ve called my application <em>MBImageClassificationApp<\/em>.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-27858 size-large\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/create-dotnet-console-app-1024x705.png\" alt=\"Create C# .NET Core console application\" width=\"640\" height=\"441\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/create-dotnet-console-app-1024x705.png 1024w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/create-dotnet-console-app-300x207.png 300w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/create-dotnet-console-app-768x529.png 768w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/create-dotnet-console-app.png 1046w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<h2>Choose a scenario<\/h2>\n<p>In Solution Explorer, right-click your newly created console application project and select <strong>Add &gt; Machine Learning<\/strong> to launch Model Builder.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-27863 size-large\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/launch-model-builder-1024x563.png\" alt=\"Add Machine Learning\" width=\"640\" height=\"352\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/launch-model-builder-1024x563.png 1024w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/launch-model-builder-300x165.png 300w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/launch-model-builder-768x422.png 768w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/launch-model-builder.png 1280w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>Once you&#8217;re presented with the scenario screen, select <strong>Image Classification<\/strong> and proceed to the next step.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-27854 size-large\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/choose-scenario-1024x563.png\" alt=\"Model Builder choose a scenario screen\" width=\"640\" height=\"352\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/choose-scenario-1024x563.png 1024w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/choose-scenario-300x165.png 300w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/choose-scenario-768x422.png 768w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/choose-scenario.png 1280w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<h2>Configure your training environment<\/h2>\n<p>For image classification scenarios, you can choose between training locally or in the cloud. For this sample we&#8217;ll train the model in Azure. For scenarios that train on thousands of images and require a large amount of resources, it is recommended to use Azure, which provides GPU optimized virtual machines for training.<\/p>\n<h3>Create Azure Machine Learning experiment<\/h3>\n<p>Choose <strong>Azure<\/strong> form the list of training environments. Then, select the <strong>Set up workspace<\/strong> button to configure your environment.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-27859 size-large\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/create-experiment-1024x563.png\" alt=\"Choose environment and create workspace\" width=\"640\" height=\"352\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/create-experiment-1024x563.png 1024w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/create-experiment-300x165.png 300w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/create-experiment-768x422.png 768w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/create-experiment.png 1280w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>An Azure Machine Learning experiment is a resource that needs to be created before running Model Builder training on Azure. The experiment encapsulates the configuration and results for one or more machine learning training runs.<\/p>\n<h3>Set up Azure environment<\/h3>\n<p>To create an Azure Machine Learning experiment, you first need to configure your environment on Azure. An experiment needs an Azure subscription, workspace, and compute to run on.<\/p>\n<p>In the Create New Experiment dialog, choose your Azure subscription. Then, select or create a new Azure Machine Learning workspace. A workspace is an Azure Machine Learning resource that provides a central place for all Azure Machine Learning resources and artifacts created as part of a training run.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-27855 size-full\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/choose-subscription.png\" alt=\"Choose Azure subscription\" width=\"636\" height=\"483\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/choose-subscription.png 636w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/choose-subscription-300x228.png 300w\" sizes=\"(max-width: 636px) 100vw, 636px\" \/><\/p>\n<p>When you create a new workspace, the following resources are provisioned:<\/p>\n<ul>\n<li>Azure Machine Learning Enterprise workspace<\/li>\n<li>Azure Storage<\/li>\n<li>Azure Application Insights<\/li>\n<li>Azure Container Registry<\/li>\n<li>Azure Key Vault<\/li>\n<\/ul>\n<p>As a result, this process may take a few minutes.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-27861 size-full\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/create-new-workspace.png\" alt=\"Create a new Azure Machine Learning workspace\" width=\"636\" height=\"393\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/create-new-workspace.png 636w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/create-new-workspace-300x185.png 300w\" sizes=\"(max-width: 636px) 100vw, 636px\" \/><\/p>\n<p>When you choose a region, it&#8217;s recommended that you select a location close to where you or your customers are.<\/p>\n<p>Once you&#8217;ve chosen or created your workspace, choose or create a new Azure Machine Learning compute. An Azure Machine Learning compute is a cloud-based Linux VM used for training. Learn more about <a href=\"https:\/\/docs.microsoft.com\/dotnet\/machine-learning\/resources\/azure-training-concepts-model-builder#what-is-an-azure-machine-learning-compute\">compute types supported by Model Builder<\/a>. This process may take a few minutes.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-27857 size-full\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/create-compute.png\" alt=\"Create a new Azure Machine Learning Compute\" width=\"486\" height=\"318\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/create-compute.png 486w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/create-compute-300x196.png 300w\" sizes=\"(max-width: 486px) 100vw, 486px\" \/><\/p>\n<p>In the Create New Experiment dialog, leave the default experiment name and select <strong>Create<\/strong>.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-27860 size-full\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/create-experiment-final.png\" alt=\"Create experiment final\" width=\"636\" height=\"483\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/create-experiment-final.png 636w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/create-experiment-final-300x228.png 300w\" sizes=\"(max-width: 636px) 100vw, 636px\" \/><\/p>\n<p>The first experiment is created and its name is registered in the workspace. Any subsequent runs &#8211; if the same experiment name is used &#8211; are logged as part of the same experiment. Otherwise, a new experiment is created.<\/p>\n<p>If you&#8217;re satisfied with your configuration, select the <strong>Data<\/strong> button to move to the next step.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-27865 size-large\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/submit-experiment-1024x563.png\" alt=\"Submit experiment\" width=\"640\" height=\"352\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/submit-experiment-1024x563.png 1024w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/submit-experiment-300x165.png 300w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/submit-experiment-768x422.png 768w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/submit-experiment.png 1280w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<h2>Load the data<\/h2>\n<p>In the Add data screen, load your data by selecting the button next to the Select a folder text box and use the file explorer to find the unzipped directory containing the subdirectories with images.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-27864 size-large\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/load-data-1024x563.png\" alt=\"Load the data\" width=\"640\" height=\"352\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/load-data-1024x563.png 1024w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/load-data-300x165.png 300w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/load-data-768x422.png 768w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/load-data.png 1280w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>Once the data is loaded, select the <strong>Train<\/strong> button to train your model.<\/p>\n<h2>Train the model<\/h2>\n<p>In the Model Builder train screen, select the <strong>Start training<\/strong> button to start training your model.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-27866 size-large\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/track-training-progress-1024x563.png\" alt=\"Track training progress\" width=\"640\" height=\"352\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/track-training-progress-1024x563.png 1024w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/track-training-progress-300x165.png 300w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/track-training-progress-768x422.png 768w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/track-training-progress.png 1280w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>At this point, your data is uploaded to Azure Storage and the training process begins. The algorithm used to train these models is a <a href=\"https:\/\/wikipedia.org\/wiki\/Deep_learning#Deep_neural_networks\">Deep Neural Network<\/a> based on the <a href=\"https:\/\/wikipedia.org\/wiki\/Residual_neural_network\">ResNet50 architecture<\/a>. The training process takes some time and the amount of time may vary depending on the size of compute selected as well as the amount of data.<\/p>\n<p>For this sample of 3670 images, training took about 30 minutes. The first time a model is trained in Azure, you can expect a slightly longer training time because resources have to be provisioned. You can track the progress of your runs in the Azure Machine Learning portal by selecting the &#8220;Monitor current run in Azure portal&#8221; link in Visual Studio.<\/p>\n<p>Once the model is trained, select the <strong>Evaluate<\/strong> button to move to the next step.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-27867 size-large\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/training-complete-1024x620.png\" alt=\"Training complete\" width=\"640\" height=\"388\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/training-complete-1024x620.png 1024w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/training-complete-300x182.png 300w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/training-complete-768x465.png 768w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/training-complete.png 1190w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<h2>Evaluate your model<\/h2>\n<p>In the evaluate screen, you are able to get an overview of the results from the training process such as how long the model took to train as well as the accuracy. Additionally, you can use the &#8220;Try your model&#8221; experience to quickly check whether your model is performing as expected. All you need to do is provide an image, preferably one that the model did not use as part of training. The model classifies the image and provides the list of categories along with their probabilities with the predicted value at the top of the list.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-27862 size-large\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/evaluate-model-1024x620.png\" alt=\"Evaluate Model\" width=\"640\" height=\"388\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/evaluate-model-1024x620.png 1024w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/evaluate-model-300x182.png 300w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/evaluate-model-768x465.png 768w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/evaluate-model.png 1190w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>If you&#8217;re satisfied with your model, select the <strong>Code<\/strong> button to add the code to make predictions.<\/p>\n<h2>Add the code to make predictions<\/h2>\n<p>In the code screen, select the <strong>Add Projects<\/strong> button to add the auto-generated projects to your solution.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-27853 size-large\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/add-projects-1024x620.png\" alt=\"Add auto-generated projects to solution\" width=\"640\" height=\"388\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/add-projects-1024x620.png 1024w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/add-projects-300x182.png 300w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/add-projects-768x465.png 768w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/add-projects.png 1190w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>Two projects are added to your solution with the following suffixes:<\/p>\n<ul>\n<li><em>ConsoleApp<\/em>: A C# .NET Core console application that provides starter code to build the prediction pipeline and make predictions.<\/li>\n<li><em>Model<\/em>: A C# .NET Standard application that contains the data models that define the data schema of input and output model data as well as the following assets:\n<ul>\n<li><em>bestModel.onnx<\/em>: A serialized version of the model in <a href=\"https:\/\/onnx.ai\/\">Open Neural Network Exchange (ONNX)<\/a> format. ONNX is an open-source format for AI models that supports interoperability between frameworks like ML.NET, PyTorch, and TensorFlow.<\/li>\n<li><em>bestModelMap.json<\/em>: A list of categories used when making predictions to map the model output to a text category.<\/li>\n<li><em>MLModel.zip<\/em>: A serialized version of the ML.NET prediction pipeline that uses the serialized version of the model <em>bestModel.onnx<\/em> to make predictions and maps outputs using the <em>bestModelMap.json<\/em> file.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>Use the machine learning model<\/h2>\n<p>Open the <em>Program.cs<\/em> file from your console application. In this case, my console application is <em>MBImageClassificationApp<\/em>.<\/p>\n<p>Then, replace the code with the following:<\/p>\n<pre class=\"prettyprint\">using System;\r\nusing MBImageClassificationAppML.Model;\r\n\r\nnamespace MBImageClassificationApp\r\n{\r\n    class Program\r\n    {\r\n        static void Main(string[] args)\r\n        {\r\n            ModelInput image = new ModelInput\r\n            {\r\n                ImageSource = \"Pink_Tulips.jpg\"\r\n            };\r\n\r\n            var prediction = ConsumeModel.Predict(image);\r\n\r\n            Console.WriteLine($\"Actual: tulips | Predicted: {prediction.Prediction}\");\r\n        }\r\n    }\r\n}<\/pre>\n<p>The first thing I&#8217;ve done is added a <em>using<\/em> statement to reference the <em>MBImageClassificationAppML.Model <\/em>project. To test my application, I&#8217;ve downloaded an image of tulips called <a href=\"https:\/\/upload.wikimedia.org\/wikipedia\/commons\/9\/92\/Pink_Tulips.JPG\">Pink_Tulips<\/a> from the internet and included it in my <em>MBImageClassificationApp<\/em> project. The model has not seen this image before. A new instance of <em>ModelInput\u00a0<\/em>is created and the path of the image is used as the value for the <em>ImageSource<\/em> property.<\/p>\n<p>Then, <em>ConsumeModel.Predict<\/em>, a helper method that loads the <em>MLModel.zip\u00a0<\/em>file and uses <em>PredictionEngine<\/em>, a convenience API to make predictions on a single instance of data, is called with the sample image as input. Finally, both the actual class the image belongs to, as well as the predicted flower category, are printed out to the console.<\/p>\n<p>When you run the application, you should see output similar to the following in the console:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-27856 size-full\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/console-output.png\" alt=\"Console Application Output\" width=\"979\" height=\"512\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/console-output.png 979w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/console-output-300x157.png 300w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/04\/console-output-768x402.png 768w\" sizes=\"(max-width: 979px) 100vw, 979px\" \/><\/p>\n<h2>Clean up resources<\/h2>\n<p>Azure Machine Learning Enterprises are currently in preview. Therefore, there is no additional surcharge at the moment. Training this model cost less than $0.50. Depending on your scenario, your costs may vary depending on the amount of data and size of your compute. For more information on pricing, see the <a href=\"https:\/\/azure.microsoft.com\/pricing\/details\/virtual-machine-scale-sets\/linux\/\">Linux Virtual Machine Scale Sets pricing page<\/a>.<\/p>\n<p>If you no longer plan to use the Azure resources you&#8217;ve created, delete them. This prevents you from being charged for unutilized resources that are still running.<\/p>\n<ol>\n<li>Navigate to the <a href=\"https:\/\/portal.azure.com\">Azure portal<\/a> and select <strong>Resource groups<\/strong> in the portal menu.<\/li>\n<li>From the list of resource groups, select the resource group you created.<\/li>\n<li>Select <strong>Delete resource group<\/strong> and follow the instructions in the prompt to delete your resource group.<\/li>\n<\/ol>\n<h2>Share your feedback<\/h2>\n<p>Since Model Builder is still in Preview, your feedback is super important in driving the direction of this tool and ML.NET in general. We would love to <a href=\"https:\/\/www.research.net\/r\/mlnet-ai-april\">hear your feedback<\/a>!<\/p>\n<p>If you run into any issues, please let us know by creating an issue in our <a href=\"https:\/\/github.com\/dotnet\/machinelearning-modelbuilder\">GitHub repo<\/a>.<\/p>\n<h2>Virtual ML.NET Conference<\/h2>\n<p>Join the community May 29-30 for a <a href=\"https:\/\/virtualml.net\/\">free online conference<\/a>.<\/p>\n<p>The conference will have a full-day hands-on workshop, followed by another day of sessions.<\/p>\n<p><a href=\"https:\/\/virtualmlnet.typeform.com\/to\/MT4ZDG\">Sign up to attend<\/a> or <a href=\"https:\/\/sessionize.com\/virtual-ml-net\/\">submit a talk<\/a>.<\/p>\n<p>See you there!<\/p>\n<h2>Additional resources<\/h2>\n<p>Watch this video to see how quick it is to <a href=\"https:\/\/www.youtube.com\/watch?v=G_ZJZdKLNMc\">train and consume an image classification model to recognize clothing garments and accessories in a Blazor web application<\/a>.<\/p>\n<p>Check out this <a href=\"https:\/\/docs.microsoft.com\/samples\/dotnet\/machinelearning-samples\/mlnet-image-classification-azure-model-builder\/\">end-to-end sample that uses satellite images to determine land use<\/a>.<\/p>\n<p>Learn more about Model Builder from <a href=\"http:\/\/aka.ms\/modelbuilder-docs\">Microsoft Docs<\/a>.<\/p>\n<p>Not currently using Visual Studio? Try out the <a href=\"http:\/\/aka.ms\/mlnet-cli\">ML.NET CLI<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post will show you how to train a custom image classification model in Azure to categorize flowers using ML.NET Model Builder. Then, you can leverage your existing .NET skills to consume the trained model inside a C# .NET Core console application. Best of all, little to no prior machine learning knowledge is required.<\/p>\n","protected":false},"author":26108,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[691],"tags":[9,568,37,6791,6790,93,96,6098],"class_list":["post-27845","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ml-dotnet","tag-net-core","tag-ai","tag-azure","tag-azure-machine-learning","tag-deep-learning","tag-machine-learning","tag-ml-net","tag-model-builder"],"acf":[],"blog_post_summary":"<p>This post will show you how to train a custom image classification model in Azure to categorize flowers using ML.NET Model Builder. Then, you can leverage your existing .NET skills to consume the trained model inside a C# .NET Core console application. Best of all, little to no prior machine learning knowledge is required.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/27845","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/26108"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=27845"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/27845\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=27845"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=27845"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=27845"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}