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

  1. Use the F5 key 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.

  2. 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:

  1. 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.

  2. 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.

  3. Drop the ONNX file into your project's Assets folder.

  4. In Solutions Explorer, right-click the Assets Folder and select Add Existing Item. Select the ONNX file.

  5. 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
  6. Change the _onnxFileNames variable to the name of the ONNX file. Also modify ClassLabel to the number of labels the model contains.

  7. Build and run.

  8. Click button to select image to evaluate.

Next steps

To discover other ways to export and use a Custom Vision model, see the following documents:

For more information on using ONNX models with Windows ML, see the Integrate a model into your app with Windows ML document.