Train a model with CNTK
In this tutorial, we'll use Visual Studio Tools for AI, a development extension for building, testing, and deploying Deep Learning & AI solutions, to train a model.
We'll train the model with the Microsoft Cognitive Toolkit (CNTK) framework and the MNIST dataset, which has a training set of 60,000 examples and a test set of 10,000 examples of handwritten digits. We'll then save the model using the Open Neural Network Exchange (ONNX) format to use with Windows ML.
Install Visual Studio Tools for AI
To get started, you'll need to download and install Visual Studio. Once you have Visual Studio open, activate the Visual Studio Tools for AI extension:
- Click on the menu bar in Visual Studio and select "Extensions and Updates..."
- Click on "Online" tab and select "Search Visual Studio Marketplace."
- Search for "Visual Studio Tools for AI."
- Click on the Download button.
- After installation, restart Visual Studio.
The extension will be active once Visual Studio restarts. If you're having trouble, check out Finding Visual Studio extensions.
Download sample code
Download the Samples for AI repo on GitHub. The samples cover getting started with deep learning across TensorFlow, CNTK, Theano and more.
Install CNTK for Python on Windows. Note that you'll also have to install Python if you haven't already.
Alternatively, to prepare your machine for deep learning model development, see Preparing your development environment for a simplified installer for installing Python, CNTK, TensorFlow, NVIDIA GPU drivers (optional) and more.
1. Open project
Launch Visual Studio and select File > Open > Project/Solution. From the Samples for AI repository, select the examples\cntk\python folder, and open the CNTKPythonExamples.sln file.
2. Train the model
To set the MNIST project as the startup project, right-click on the python project and select Set as Startup Project.
Next, open the train_mnist_onnx.py file and Run the project by pressing F5 or the green Run button.
3. View the model and add it to your app
Now, the trained mnist.onnx model file should be in the samples-for-ai/examples/cntk/python/MNIST folder.
4. Learn more