Tutorial: 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).
The information in this document demonstrates how to use an ONNX file exported from the Custom Vision Service with Windows ML. An example Windows UWP application is provided. A trained model that can recognize is included with the example. Steps are also provided on how you can use your own model with this example.
- About the example app
- Get the example code
- Run the example
- Use your own model
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. For more information, see the Enable your device for development document.
About the example app
The application is a generic Windows UWP application. It allows you to select an image from your computer, which is then sent to the 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 https://github.com/Azure-Samples/cognitive-services-onnx-customvision-sample.
Run the example
F5key to start the application from Visual Studio. You may be prompted to enable Developer mode. For more information, see the Enable your device for development document.
When the application starts, use the button to select an image for scoring.
Use your own model
To use your own model, use the following steps:
Create and train a classifier with the Custom Vision Service. To export the model, select a compact domain such as General (compact). To export an existing classifier, convert the domain to compact by selecting the gear icon at the top right. In Settings, choose a compact model, save, and train your project.
Export your model by going to the Performance tab. Select an iteration trained with a compact domain, an "Export" button will appear. Select Export, ONNX, and then Export. Once the file is ready, select the Download button.
Drop the ONNX file into your project's Assets folder.
In Solutions Explorer, right-click the Assets Folder and select Add Existing Item. Select the ONNX file.
In Solutions Explorer, select the ONNX file from the Assets folder. Change the following properties for the file:
- Build Action -> Content
- Copy to Output Directory -> Copy if newer
_onnxFileNamesvariable to the name of the ONNX file. Also modify
ClassLabelto the number of labels the model contains.
Build and run.
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 the Integrate a model into your app with Windows ML document.