Classification application for Windows on Snapdragon® with MobileNet-V2 using ONNX runtime.
The app demonstrates how to use the QNN execution provider to accelerate the model using the Snapdragon® Neural Processing Unit (NPU).
- Snapdragon® Platform (e.g. X Elite)
- Windows 11+
- Visual Studio 22
- Download any variant of Visual Studio here
- Make sure Desktop development with C++ tools are selected during installation or installed separately later
Download the float/onnx variant of MobileNet-V2 from AI Hub. Rename it and place it into:
<project directory>/assets/models/classification.onnx
-
Open
Classification.sln -
Setting up dependencies
-
NuGet packages
- NuGet packages should automatically restore in Visual Studio during build
- If packages are not restored automatically, try the following:
- If prompted by Visual Studio to
restoreNuGet packages- Click on
restoreto restore allNuGetpackages
- Click on
- Otherwise,
- Go to
Project -> Manage NuGet packagesin Visual studio - Install ONNX-Runtime-QNN 1.19.0
- Go to
- If prompted by Visual Studio to
-
vcpkg packages
-
Project is configured to work with vcpkg in manifest mode
-
If opencv headers are missing, vcpkg is not setup correctly.
-
Integrate vcpkg with Visual Studio:
- Go to
View -> Terminalin Visual studio - Run the following command in terminal
vcpkg integrate install
- Go to
-
-
-
Build and run project in Visual Studio
Visual Studio project is configured with the following command arguments:
--model .\assets\models\classification.onnx --image .\assets\images\keyboard.jpgYou can simply run the app from Visual Studio to run classification on sample image.
.\ARM64\Debug\Classification.exe --model .\assets\models\classification.onnx --image .\assets\images\keyboard.jpgYou can additionally run --help to get more information about all available options:
.\ARM64\Debug\Classification.exe --helpPlease refer to QNN EP options that can be provided as --qnn_options to the app.
- Model input resolution: 224x224
- If input image is of different shape, it's resized to 224x224
- You can override model input dimensions if model uses different spatial image dimensions
- App is built to work with post-processed outputs
- App processes output logits and produces consumable output as Class Label.
- If you want to try out any other model than Yolo (with post-processing included in model), please update output handling accordingly.
- If you get a DLL error message upon launch (for instance that
opencv_core4d.dllwas not found). Try Build -> Clean Solution and re-build. If this still happens, please go over the NuGet and vcpkg instructions again carefully. - How do I use a model with different input shape than 224x224?
- Use
--model_input_ht/--model_input_wtto model input dimensions.
- Use
- I have a model that does have different post-processing. Can I still use the app?
- You will have to modify the app and add the necessary post-processing to accommodate that models.
Following section describes how to configure your own project with NuGet and vcpkg from scratch:
- Start empty Visual Studio project
- Set up NuGet to install ONNXRuntime QNN Execution provider
- Go to
Project->Manage NuGet Packages - Look up and install the following packages
- This NuGet package does not properly copy all necessary files to the build
folder, so we use a batch script
copy_missing_qnn_ep_files.bat to do this
for us. Copy this script into your project and make sure it runs by adding
this to your
.vcxprojfile:<Target Name="PostBuildCopyQnn" AfterTargets="Build"> <Exec Command=""$(ProjectDir)copy_missing_qnn_ep_files.bat" "$(OutDir)"" /> </Target>
- Go to
- Set up Visual Studio for vcpkg
-
Enable vcpkg manifest mode
- Go to Project Setting
- General -> vcpkg
- Enable Manifest mode
-
Add
OpenCVdependency in vcpkg- Run the following commands in Visual Studio powershell:
vcpkg —new application vcpkg add port opencv
-
Important: To get around a vcpkg bug affecting ARM64, please add the following to your
.vcxprojfile:<PropertyGroup> <VcpkgPlatformTarget Condition="'$(Platform)'=='ARM64'">arm64</VcpkgPlatformTarget> </PropertyGroup>If this is not added, you will see an error message like this:
error: Invalid triplet name. Triplet names are all lowercase alphanumeric+hyphens.
-
- Now project is setup to work with the vcpkg and NuGet package managers

