Use an ONNX model from Custom Vision with Windows ML (preview)
Learn how to use an ONNX model exported from the Custom Vision service with Windows ML (preview).
In this guide, you'll learn how to use an ONNX file exported from the Custom Vision Service with Windows ML. You'll use the example UWP application with your own trained image classifier.
- Windows 10 version 1809 or higher
- Windows SDK for build 17763 or higher
- Visual Studio 2017 version 15.7 or later with the Universal Windows Platform development workload enabled.
- Developer mode enabled on your PC. For more information, see Enable your device for development.
About the example app
The included application is a generic Windows UWP app. It allows you to select an image from your computer, which is then processed by a locally stored classification model. The tags and scores returned by the model are displayed next to the image.
Get the example code
The example application is available at the Cognitive Services ONNX Custom Vision Sample repo on GitHub. Clone it to your local machine and open SampleOnnxEvaluationApp.sln in Visual Studio.
Test the application
- Use the
F5key to start the application from Visual Studio. You may be prompted to enable Developer mode.
- When the application starts, use the button to select an image for scoring. The default ONNX model is trained to classify different types of plankton.
Use your own model
To use your own image classifier model, follow these steps:
- Create and train a classifier with the Custom Vision Service. For instructions on how to do this, see Create and train a classifier. Use one of the compact domains such as General (compact).
- If you have an existing classifier that uses a different domain, you can convert it to compact in the project settings. Then, re-train your project before continuing.
- Export your model. Switch to the Performance tab and select an iteration that was trained with a compact domain. Select the Export button that appears. Then select ONNX, and then Export. Once the file is ready, select the Download button. For more information on export options, see Export your model.
- Open the downloaded .zip file and extract the model.onnx file from it. This file contains your classifier model.
- In the Solution Explorer in Visual Studio, right-click the Assets Folder and select Add Existing Item. Select your ONNX file.
- In Solution Explorer, right-click the ONNX file and select Properties. Change the following properties for the file:
- Build Action -> Content
- Copy to Output Directory -> Copy if newer
- Then open MainPage.xaml.cs and change the value of
_ourOnnxFileNameto the name of your ONNX file.
- Use the
F5to build and run the project.
- Click button to select image to evaluate.
To discover other ways to export and use a Custom Vision model, see the following documents:
- Export your model
- Use exported Tensorflow model in an Android application
- Use exported CoreML model in a Swift iOS application
- Use exported CoreML model in an iOS application with Xamarin
For more information on using ONNX models with Windows ML, see Integrate a model into your app with Windows ML.
Submit and view feedback for