diff --git a/Samples/WindowsML/Directory.Packages.props b/Samples/WindowsML/Directory.Packages.props index eb10c1c43..eacb0dd4e 100644 --- a/Samples/WindowsML/Directory.Packages.props +++ b/Samples/WindowsML/Directory.Packages.props @@ -4,17 +4,18 @@ - - - - - - - - - - - + + + + + + + + + + + + diff --git a/Samples/WindowsML/README.md b/Samples/WindowsML/README.md index d230708e0..5ad939dba 100644 --- a/Samples/WindowsML/README.md +++ b/Samples/WindowsML/README.md @@ -13,8 +13,12 @@ Windows ML enables high-performance, reliable inferencing of machine learning mo ## Prerequisites - **Windows 11 PC** running version 24H2 (build 26100) or greater -- **Visual Studio 2022** with C++ and .NET workloads -- **Windows App SDK 1.8.1** or later +- **Visual Studio 2022** with the following workloads: + - **Desktop development with C++** (required for C++ samples) + - **.NET desktop development** (required for C# samples) +- **Windows App SDK 2.1.3** or later +- **CMake** 3.21 or later (required for CMake samples) +- **NuGet** CLI (`nuget.exe` on PATH, required for CMake samples) - **Python 3.10-3.13** for Python samples on x64 and ARM64 devices ## Sample Categories @@ -26,8 +30,12 @@ Windows ML enables high-performance, reliable inferencing of machine learning mo | [CppConsoleDesktop](cpp/CppConsoleDesktop/) | Basic C++ console application | EP discovery, command-line options, model compilation | | [CppConsoleDesktop.FrameworkDependent](cpp/CppConsoleDesktop.FrameworkDependent/) | Framework-dependent deployment variant | Shared runtime, smaller deployment footprint | | [CppConsoleDesktop.SelfContained](cpp/CppConsoleDesktop.SelfContained/) | Self-contained deployment variant | Standalone deployment, no runtime dependencies | -| [CppConsoleDll](cpp/CppConsoleDll/) | DLL usage pattern | WindowsML in shared library, memory management | -| [CppResnetBuildDemo](cpp/CppResnetBuildDemo/) | ResNet model demo from the [Windows ML session](https://www.youtube.com/watch?v=AQjOq8qSsbE) at Build 2025 | Model conversion, EP compilation, detailed tutorial | + +### C++ CMake Samples + +| Sample | Description | Key Features | +|--------|-------------|--------------| +| [WinMLEpCatalog](cpp-cmake/WinMLEpCatalog/) | CMake-based EP catalog sample using the WinML C API | CMake build system, automatic NuGet restore, EP discovery and registration | ### C++ ABI Samples @@ -41,7 +49,6 @@ Windows ML enables high-performance, reliable inferencing of machine learning mo | Sample | Description | Key Features | |--------|-------------|--------------| | [CSharpConsoleDesktop](cs/CSharpConsoleDesktop/) | Basic C# console application | Shared helper usage, command-line interface | -| [ResnetBuildDemoCS](cs/ResnetBuildDemoCS/) | ResNet model demo from the [Windows ML session](https://www.youtube.com/watch?v=AQjOq8qSsbE) at Build 2025 | Model conversion, EP compilation, detailed tutorial | #### GUI Applications | Sample | UI Framework | Description | diff --git a/Samples/WindowsML/Shared/cpp/ExecutionProviderManager.cpp b/Samples/WindowsML/Shared/cpp/ExecutionProviderManager.cpp index 17cf608d9..a248c3176 100644 --- a/Samples/WindowsML/Shared/cpp/ExecutionProviderManager.cpp +++ b/Samples/WindowsML/Shared/cpp/ExecutionProviderManager.cpp @@ -40,6 +40,9 @@ namespace Shared if (allowDownload || readyState != winrt::Microsoft::Windows::AI::MachineLearning::ExecutionProviderReadyState::NotPresent) { provider.EnsureReadyAsync().get(); + readyState = provider.ReadyState(); + std::wcout << L" Updated Ready state: " << static_cast(readyState) << std::endl; + } provider.TryRegister(); diff --git a/Samples/WindowsML/WindowsML-Samples.sln b/Samples/WindowsML/WindowsML-Samples.sln index 860d11fa7..7d70f6ba7 100644 --- a/Samples/WindowsML/WindowsML-Samples.sln +++ b/Samples/WindowsML/WindowsML-Samples.sln @@ -14,16 +14,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "cs-winforms", "cs-winforms" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "cs-wpf", "cs-wpf", "{D8F3A6C1-7E2B-4A9F-8C5D-2E6A9B3F5C8A}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CppConsoleDll", "CppConsoleDll", "{C5A8E1F4-3B7D-4F6A-8E2C-9A5B3E7F1C4A}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSharpConsoleDesktop", "cs\CSharpConsoleDesktop\CSharpConsoleDesktop\CSharpConsoleDesktop.csproj", "{A2658DB3-E9DE-4E76-8AD4-C726EFEA6969}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CppConsoleDesktop", "cpp\CppConsoleDesktop\CppConsoleDesktop.vcxproj", "{1341505B-863B-4DF5-9A43-B84A635D1AE9}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WindowsMLWrapper", "cpp\CppConsoleDll\WindowsMLWrapper\WindowsMLWrapper.vcxproj", "{B8F65F4C-1234-4567-8901-123456789ABC}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ConsoleClient", "cpp\CppConsoleDll\ConsoleClient\ConsoleClient.vcxproj", "{A1B2C3D4-5678-9012-3456-789012345678}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WindowsMLSample", "cs-winui\WindowsMLSample.csproj", "{C9BD7502-33EE-4826-A6D5-2F6B4AC90346}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WindowsMLWinFormsSample", "cs-winforms\WindowsMLWinFormsSample.csproj", "{F5381E31-4C91-422C-8E60-0F63265BF4B5}" @@ -40,10 +34,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloPhi", "cs\HelloPhi\Hel EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CppConsoleDesktop.GenAI", "cpp\CppConsoleDesktop.GenAI\CppConsoleDesktop.GenAI.vcxproj", "{7394B294-DE36-4E7B-B737-D3607D36E662}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ResnetBuildDemoCS", "cs\ResnetBuildDemoCS\ResnetBuildDemoCS\ResnetBuildDemoCS.csproj", "{AA9B249B-216B-94F8-D026-6D6F5B62A818}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CppResnetBuildDemo", "cpp\CppResnetBuildDemo\CppResnetBuildDemo\CppResnetBuildDemo.vcxproj", "{70987125-E3F7-43C0-8385-4A090EF9EF54}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM64 = Debug|ARM64 @@ -68,22 +58,6 @@ Global {1341505B-863B-4DF5-9A43-B84A635D1AE9}.Release|ARM64.Build.0 = Release|ARM64 {1341505B-863B-4DF5-9A43-B84A635D1AE9}.Release|x64.ActiveCfg = Release|x64 {1341505B-863B-4DF5-9A43-B84A635D1AE9}.Release|x64.Build.0 = Release|x64 - {B8F65F4C-1234-4567-8901-123456789ABC}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {B8F65F4C-1234-4567-8901-123456789ABC}.Debug|ARM64.Build.0 = Debug|ARM64 - {B8F65F4C-1234-4567-8901-123456789ABC}.Debug|x64.ActiveCfg = Debug|x64 - {B8F65F4C-1234-4567-8901-123456789ABC}.Debug|x64.Build.0 = Debug|x64 - {B8F65F4C-1234-4567-8901-123456789ABC}.Release|ARM64.ActiveCfg = Release|ARM64 - {B8F65F4C-1234-4567-8901-123456789ABC}.Release|ARM64.Build.0 = Release|ARM64 - {B8F65F4C-1234-4567-8901-123456789ABC}.Release|x64.ActiveCfg = Release|x64 - {B8F65F4C-1234-4567-8901-123456789ABC}.Release|x64.Build.0 = Release|x64 - {A1B2C3D4-5678-9012-3456-789012345678}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {A1B2C3D4-5678-9012-3456-789012345678}.Debug|ARM64.Build.0 = Debug|ARM64 - {A1B2C3D4-5678-9012-3456-789012345678}.Debug|x64.ActiveCfg = Debug|x64 - {A1B2C3D4-5678-9012-3456-789012345678}.Debug|x64.Build.0 = Debug|x64 - {A1B2C3D4-5678-9012-3456-789012345678}.Release|ARM64.ActiveCfg = Release|ARM64 - {A1B2C3D4-5678-9012-3456-789012345678}.Release|ARM64.Build.0 = Release|ARM64 - {A1B2C3D4-5678-9012-3456-789012345678}.Release|x64.ActiveCfg = Release|x64 - {A1B2C3D4-5678-9012-3456-789012345678}.Release|x64.Build.0 = Release|x64 {C9BD7502-33EE-4826-A6D5-2F6B4AC90346}.Debug|ARM64.ActiveCfg = Debug|ARM64 {C9BD7502-33EE-4826-A6D5-2F6B4AC90346}.Debug|ARM64.Build.0 = Debug|ARM64 {C9BD7502-33EE-4826-A6D5-2F6B4AC90346}.Debug|ARM64.Deploy.0 = Debug|ARM64 @@ -152,32 +126,13 @@ Global {7394B294-DE36-4E7B-B737-D3607D36E662}.Release|ARM64.Build.0 = Release|ARM64 {7394B294-DE36-4E7B-B737-D3607D36E662}.Release|x64.ActiveCfg = Release|x64 {7394B294-DE36-4E7B-B737-D3607D36E662}.Release|x64.Build.0 = Release|x64 - {AA9B249B-216B-94F8-D026-6D6F5B62A818}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {AA9B249B-216B-94F8-D026-6D6F5B62A818}.Debug|ARM64.Build.0 = Debug|ARM64 - {AA9B249B-216B-94F8-D026-6D6F5B62A818}.Debug|x64.ActiveCfg = Debug|x64 - {AA9B249B-216B-94F8-D026-6D6F5B62A818}.Debug|x64.Build.0 = Debug|x64 - {AA9B249B-216B-94F8-D026-6D6F5B62A818}.Release|ARM64.ActiveCfg = Release|ARM64 - {AA9B249B-216B-94F8-D026-6D6F5B62A818}.Release|ARM64.Build.0 = Release|ARM64 - {AA9B249B-216B-94F8-D026-6D6F5B62A818}.Release|x64.ActiveCfg = Release|x64 - {AA9B249B-216B-94F8-D026-6D6F5B62A818}.Release|x64.Build.0 = Release|x64 - {70987125-E3F7-43C0-8385-4A090EF9EF54}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {70987125-E3F7-43C0-8385-4A090EF9EF54}.Debug|ARM64.Build.0 = Debug|ARM64 - {70987125-E3F7-43C0-8385-4A090EF9EF54}.Debug|x64.ActiveCfg = Debug|x64 - {70987125-E3F7-43C0-8385-4A090EF9EF54}.Debug|x64.Build.0 = Debug|x64 - {70987125-E3F7-43C0-8385-4A090EF9EF54}.Release|ARM64.ActiveCfg = Release|ARM64 - {70987125-E3F7-43C0-8385-4A090EF9EF54}.Release|ARM64.Build.0 = Release|ARM64 - {70987125-E3F7-43C0-8385-4A090EF9EF54}.Release|x64.ActiveCfg = Release|x64 - {70987125-E3F7-43C0-8385-4A090EF9EF54}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {C5A8E1F4-3B7D-4F6A-8E2C-9A5B3E7F1C4A} = {A3B7D9E1-5C2F-4A8B-9E6D-3F7A1B8C5E9F} {A2658DB3-E9DE-4E76-8AD4-C726EFEA6969} = {E8F2C4D6-9A7B-4E5C-8D3A-1F6B9E2A7C5D} {1341505B-863B-4DF5-9A43-B84A635D1AE9} = {A3B7D9E1-5C2F-4A8B-9E6D-3F7A1B8C5E9F} - {B8F65F4C-1234-4567-8901-123456789ABC} = {C5A8E1F4-3B7D-4F6A-8E2C-9A5B3E7F1C4A} - {A1B2C3D4-5678-9012-3456-789012345678} = {C5A8E1F4-3B7D-4F6A-8E2C-9A5B3E7F1C4A} {C9BD7502-33EE-4826-A6D5-2F6B4AC90346} = {F9A4C7E2-8D5B-4F3A-A1E6-7B9C2D5F8A3E} {F5381E31-4C91-422C-8E60-0F63265BF4B5} = {B6E9A2D5-4C8F-4B7A-9F3E-5A8C1E4B7D9A} {3341505B-863B-4DF5-9A43-B84A635D1AE9} = {A3B7D9E1-5C2F-4A8B-9E6D-3F7A1B8C5E9F} @@ -186,8 +141,6 @@ Global {E6A9B3F5-C8D1-4E7F-9A2E-5C8F1B4D7A9E} = {D8F3A6C1-7E2B-4A9F-8C5D-2E6A9B3F5C8A} {C4495933-0EFE-D24C-64FB-E581EA4E9909} = {E8F2C4D6-9A7B-4E5C-8D3A-1F6B9E2A7C5D} {7394B294-DE36-4E7B-B737-D3607D36E662} = {A3B7D9E1-5C2F-4A8B-9E6D-3F7A1B8C5E9F} - {AA9B249B-216B-94F8-D026-6D6F5B62A818} = {E8F2C4D6-9A7B-4E5C-8D3A-1F6B9E2A7C5D} - {70987125-E3F7-43C0-8385-4A090EF9EF54} = {A3B7D9E1-5C2F-4A8B-9E6D-3F7A1B8C5E9F} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {12345678-1234-5678-9ABC-123456789012} diff --git a/Samples/WindowsML/cpp-abi/CppAbiEPEnumerationSample.vcxproj b/Samples/WindowsML/cpp-abi/CppAbiEPEnumerationSample.vcxproj index 3734f9f3b..6c85330e8 100644 --- a/Samples/WindowsML/cpp-abi/CppAbiEPEnumerationSample.vcxproj +++ b/Samples/WindowsML/cpp-abi/CppAbiEPEnumerationSample.vcxproj @@ -14,12 +14,13 @@ 10.0.26100.0 - - - + + + - + + @@ -64,6 +65,12 @@ true true + + + $(NugetPackageDirectory)\Microsoft.Windows.AI.MachineLearning.2.1.1\metadata\Microsoft.Windows.AI.MachineLearning.winmd + false + true + @@ -91,12 +98,13 @@ - + + - - - + + + @@ -104,17 +112,19 @@ - - + + + + - - - - - - + + + + + + \ No newline at end of file diff --git a/Samples/WindowsML/cpp-abi/packages.config b/Samples/WindowsML/cpp-abi/packages.config index a0f454f49..1feea6af4 100644 --- a/Samples/WindowsML/cpp-abi/packages.config +++ b/Samples/WindowsML/cpp-abi/packages.config @@ -1,10 +1,11 @@ - + - - - - + + + + + \ No newline at end of file diff --git a/Samples/WindowsML/cpp-cmake/.clangd b/Samples/WindowsML/cpp-cmake/.clangd deleted file mode 100644 index 02e00469e..000000000 --- a/Samples/WindowsML/cpp-cmake/.clangd +++ /dev/null @@ -1,11 +0,0 @@ -CompileFlags: - Add: ['-std:c++latest', '/EHsc'] -Diagnostics: - ClangTidy: - Add: - - modernize-* - - bugprone-* - - cppcoreguidelines-* - - readability-* - Remove: - - modernize-use-trailing-return-type diff --git a/Samples/WindowsML/cpp-cmake/.editorconfig b/Samples/WindowsML/cpp-cmake/.editorconfig deleted file mode 100644 index 24c628547..000000000 --- a/Samples/WindowsML/cpp-cmake/.editorconfig +++ /dev/null @@ -1,11 +0,0 @@ -root = true - -[*] -charset = utf-8 -indent_size = 4 -indent_style = space -insert_final_newline = true -trim_trailing_whitespace = true - -[*.json] -indent_size = 2 diff --git a/Samples/WindowsML/cpp-cmake/.gitignore b/Samples/WindowsML/cpp-cmake/.gitignore deleted file mode 100644 index 77ebff9b5..000000000 --- a/Samples/WindowsML/cpp-cmake/.gitignore +++ /dev/null @@ -1 +0,0 @@ -__* diff --git a/Samples/WindowsML/cpp-cmake/CMakeLists.txt b/Samples/WindowsML/cpp-cmake/CMakeLists.txt deleted file mode 100644 index f86413e39..000000000 --- a/Samples/WindowsML/cpp-cmake/CMakeLists.txt +++ /dev/null @@ -1,87 +0,0 @@ -#---------------------------------------------------------------------------------------------------------------------- -# -#---------------------------------------------------------------------------------------------------------------------- -cmake_minimum_required(VERSION 3.31) - -cmake_policy(SET CMP0141 NEW) # MSVC debug information format flags are selected by an abstraction. -cmake_policy(SET CMP0117 NEW) # MSVC RTTI flag /GR is not added to CMAKE_CXX_FLAGS by default. - -if(CMAKE_GENERATOR MATCHES "^Visual Studio") - # To prevent builds (including try_compile) from picking up top-level 'Directory.Build.*' files, - # write versions specific to the CMake builds at the root of the CMake build. - file(WRITE "${CMAKE_BINARY_DIR}/Directory.Build.rsp" "-m -graphBuild:true -p:UseMultiToolTask=true -nodeReuse:false -terminalLogger:auto") - file(WRITE "${CMAKE_BINARY_DIR}/Directory.Build.props" "") - file(WRITE "${CMAKE_BINARY_DIR}/Directory.Build.targets" "") -elseif(CMAKE_GENERATOR MATCHES "^Ninja") - if(NOT (DEFINED ENV{Platform})) - message(FATAL_ERROR "When using the Ninja generator, you must build from a platform-specific Developer Command Prompt.") - endif() -endif() - -project(WinMLSamples LANGUAGES CXX) - -include(FetchContent) - -FetchContent_Declare( - NuGetCMakePackage - GIT_REPOSITORY https://github.com/mschofie/NuGetCMakePackage - GIT_TAG b13e013481605d134f498fd9fc3a123c416da197 -) - -FetchContent_MakeAvailable(NuGetCMakePackage) - -add_nuget_packages( - PACKAGES - Microsoft.Windows.CppWinRT 2.0.240405.15 - Microsoft.Windows.ImplementationLibrary 1.0.240803.1 - Microsoft.WindowsAppSDK.Foundation 1.8.251104000 - Microsoft.WindowsAppSDK.InteractiveExperiences 1.8.251104001 - Microsoft.WindowsAppSDK.ML 1.8.2109 - Microsoft.WindowsAppSDK.Runtime 1.8.251106002 -) - -find_package(Microsoft.Windows.ImplementationLibrary CONFIG REQUIRED) -find_package(Microsoft.WindowsAppSDK.ML CONFIG REQUIRED) - -set(RESNET_MODEL_FILES - ${CMAKE_SOURCE_DIR}/../Resources/ResNet50/model.Labels.txt - ${CMAKE_SOURCE_DIR}/../Resources/ResNet50/model.LICENSE.txt - ${CMAKE_SOURCE_DIR}/../Resources/ResNet50/model.onnx - ${CMAKE_SOURCE_DIR}/../Resources/ResNet50/model.onnx.data -) - -set(RESOURCE_FILES - ${CMAKE_SOURCE_DIR}/Resources/dog.jpg -) - -macro(post_build_runtime_dll_copy target_name) - if(WIN32) - add_custom_command(TARGET ${target_name} POST_BUILD - COMMAND "${CMAKE_COMMAND};-E;$>,copy;$;$,true>" - COMMAND_EXPAND_LISTS - ) - endif() -endmacro() - -# Common configuration -# - -# Enable CMake support for Generators to include folders in their generated build output. -set_property(GLOBAL PROPERTY USE_FOLDERS ON) -set_property(DIRECTORY APPEND PROPERTY VS_SOLUTION_ITEMS - .clangd - .editorconfig - .gitignore - CMakePresets.json - readme.md -) - -include(./Configuration.cmake) - -link_libraries(Configuration) - -# Subdirectories -# -add_subdirectory(ResNetCommon) -add_subdirectory(ResNetConsoleDesktop) -add_subdirectory(ResNetConsoleDesktop.SelfContained) diff --git a/Samples/WindowsML/cpp-cmake/CMakePresets.json b/Samples/WindowsML/cpp-cmake/CMakePresets.json deleted file mode 100644 index d86d26c24..000000000 --- a/Samples/WindowsML/cpp-cmake/CMakePresets.json +++ /dev/null @@ -1,66 +0,0 @@ -{ - "version": 3, - "cmakeMinimumRequired": { - "major": 3, - "minor": 31, - "patch": 0 - }, - "configurePresets": [ - { - "name": "windows", - "binaryDir": "${sourceDir}/__output/${presetName}", - "hidden": true, - "cacheVariables": { - "CMAKE_MSVC_DEBUG_INFORMATION_FORMAT": "Embedded", - "CMAKE_SYSTEM_VERSION": "10.0.26100.0", - "CPPWINRT_PROJECTION_ROOT_PATH": "${sourceDir}/__cppwinrt", - "CPPWINRT_VERSION": "2.0.250303.1", - "NUGET_PACKAGE_ROOT_PATH": "${sourceDir}/__packages" - } - }, - { - "name": "windows-vs", - "inherits": "windows", - "hidden": true, - "displayName": "Windows Visual Studio Generator presets", - "generator": "Visual Studio 17 2022" - }, - { - "name": "windows-vs-x64", - "inherits": "windows-vs", - "displayName": "Windows, Visual Studio Generator, x64", - "architecture": "x64" - }, - { - "name": "windows-vs-arm64", - "inherits": "windows-vs", - "displayName": "Windows, Visual Studio Generator, arm64", - "architecture": "arm64" - }, - { - "name": "windows-msvc", - "binaryDir": "${sourceDir}/__output/${presetName}-$env{Platform}", - "inherits": "windows", - "displayName": "Windows MSVC/Ninja Generator presets", - "description": "Windows MSVC Ninja Multi-Config Generator", - "generator": "Ninja Multi-Config", - "cacheVariables": { - "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" - } - } - ], - "buildPresets": [ - { - "name": "windows-vs-x64", - "configurePreset": "windows-vs-x64" - }, - { - "name": "windows-vs-arm64", - "configurePreset": "windows-vs-arm64" - }, - { - "name": "windows-msvc", - "configurePreset": "windows-msvc" - } - ] -} diff --git a/Samples/WindowsML/cpp-cmake/Configuration.cmake b/Samples/WindowsML/cpp-cmake/Configuration.cmake deleted file mode 100644 index 6994f34c7..000000000 --- a/Samples/WindowsML/cpp-cmake/Configuration.cmake +++ /dev/null @@ -1,34 +0,0 @@ -#---------------------------------------------------------------------------------------------------------------------- -# -#---------------------------------------------------------------------------------------------------------------------- -add_library(Configuration INTERFACE) - -target_compile_definitions(Configuration - INTERFACE - UNICODE - _UNICODE - NOMINMAX - WIN32_LEAN_AND_MEAN -) - -target_compile_features(Configuration - INTERFACE - cxx_std_23 -) - -target_compile_options(Configuration - INTERFACE - $<$:/d1nodatetime> - $<$:/EHsc> - $<$:/W3> - $<$:/Zc:__cplusplus> - $<$:/Zc:preprocessor> - $<$:$<$>:/GL>> - $<$:$<$>:/O2>> -) - -target_link_options(Configuration - INTERFACE - $<$:$<$>:/LTCG>> - $<$:$<$>:/INCREMENTAL:NO>> -) diff --git a/Samples/WindowsML/cpp-cmake/ResNetCommon/CMakeLists.txt b/Samples/WindowsML/cpp-cmake/ResNetCommon/CMakeLists.txt deleted file mode 100644 index 613a832f3..000000000 --- a/Samples/WindowsML/cpp-cmake/ResNetCommon/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -#---------------------------------------------------------------------------------------------------------------------- -# -#---------------------------------------------------------------------------------------------------------------------- -project(ResNetCommon LANGUAGES CXX) - -add_library(ResNetCommon STATIC - ResNetModelHelper.cpp -) - -target_precompile_headers(ResNetCommon - PRIVATE - pch.h -) - -target_include_directories(ResNetCommon - PUBLIC - ./include -) - -target_link_libraries(ResNetCommon - PRIVATE - Microsoft.Windows.CppWinRT - Microsoft.Windows.ImplementationLibrary - Microsoft.WindowsAppSDK.ML -) diff --git a/Samples/WindowsML/cpp-cmake/ResNetCommon/ResNetModelHelper.cpp b/Samples/WindowsML/cpp-cmake/ResNetCommon/ResNetModelHelper.cpp deleted file mode 100644 index 4d278c320..000000000 --- a/Samples/WindowsML/cpp-cmake/ResNetCommon/ResNetModelHelper.cpp +++ /dev/null @@ -1,264 +0,0 @@ -#include "ResNetModelHelper.hpp" - -// clang-format off -#include -#include -// clang-format on - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace winrt::Windows::Foundation::Collections; -using namespace winrt::Windows::Graphics::Imaging; -using namespace winrt::Windows::Media; -using namespace winrt::Windows::Storage::Streams; -using namespace winrt::Windows::Storage; -using winrt::Windows::Foundation::IAsyncOperation; -using winrt::Windows::Foundation::IMemoryBufferReference; - -namespace ResNetModelHelper -{ -std::wostream& operator<<(std::wostream& outputStream, const winrt::Microsoft::Windows::AI::MachineLearning::ExecutionProviderReadyResultState& readyResultState) -{ - if (readyResultState == winrt::Microsoft::Windows::AI::MachineLearning::ExecutionProviderReadyResultState::InProgress) - { - return outputStream << L"InProgress"; - } - - if (readyResultState == winrt::Microsoft::Windows::AI::MachineLearning::ExecutionProviderReadyResultState::Success) - { - return outputStream << L"Success"; - } - - if (readyResultState == winrt::Microsoft::Windows::AI::MachineLearning::ExecutionProviderReadyResultState::Failure) - { - return outputStream << L"Failure"; - } - - return outputStream << L"<>"; -} - -std::wostream& operator<<(std::wostream& outputStream, const winrt::Microsoft::Windows::AI::MachineLearning::ExecutionProviderReadyState& readyState) -{ - if (readyState == winrt::Microsoft::Windows::AI::MachineLearning::ExecutionProviderReadyState::Ready) - { - return outputStream << L"Ready"; - } - - if (readyState == winrt::Microsoft::Windows::AI::MachineLearning::ExecutionProviderReadyState::NotReady) - { - return outputStream << L"NotReady"; - } - - if (readyState == winrt::Microsoft::Windows::AI::MachineLearning::ExecutionProviderReadyState::NotPresent) - { - return outputStream << L"NotPresent"; - } - - return outputStream << L"<>"; -} - -std::filesystem::path GetExecutablePath() -{ - auto filePath = wil::GetModuleFileNameW(); - std::filesystem::path fil{filePath.get()}; - return fil; -} - -IAsyncOperation LoadImageFileAsync(winrt::hstring filePath) -{ - StorageFile file = co_await StorageFile::GetFileFromPathAsync(filePath); - auto stream = co_await file.OpenAsync(FileAccessMode::Read); - BitmapDecoder decoder = co_await BitmapDecoder::CreateAsync(stream); - SoftwareBitmap softwareBitmap = co_await decoder.GetSoftwareBitmapAsync(); - - co_return softwareBitmap; -} - -std::vector BindSoftwareBitmapAsTensor(SoftwareBitmap const& bitmap) -{ - SoftwareBitmap bitmapBgra8 = SoftwareBitmap::Convert(bitmap, BitmapPixelFormat::Bgra8, BitmapAlphaMode::Ignore); - - winrt::Windows::Storage::Streams::InMemoryRandomAccessStream stream = InMemoryRandomAccessStream(); - - BitmapEncoder encoder = BitmapEncoder::CreateAsync(BitmapEncoder::BmpEncoderId(), stream).get(); - encoder.SetSoftwareBitmap(bitmapBgra8); - encoder.BitmapTransform().ScaledWidth(224); - encoder.BitmapTransform().ScaledHeight(224); - encoder.BitmapTransform().InterpolationMode(BitmapInterpolationMode::Fant); - encoder.FlushAsync().get(); - - stream.Seek(0); - BitmapDecoder decoder = BitmapDecoder::CreateAsync(stream).get(); - SoftwareBitmap resizedBitmap = decoder.GetSoftwareBitmapAsync(BitmapPixelFormat::Bgra8, BitmapAlphaMode::Ignore).get(); - - BitmapBuffer bitmapBuffer = resizedBitmap.LockBuffer(BitmapBufferAccessMode::Read); - - IMemoryBufferReference reference = bitmapBuffer.CreateReference(); - - auto spByteAccess = reference.as<::Windows::Foundation::IMemoryBufferByteAccess>(); - uint8_t* pixelData = nullptr; - uint32_t pixelDataCapacity = 0; - - spByteAccess->GetBuffer(&pixelData, &pixelDataCapacity); - - const int64_t channels = 3; // RGB - const int64_t height = 224; - const int64_t width = 224; - - std::vector tensorShape = {1, channels, height, width}; - std::vector tensorData(channels * height * width); - - for (int y = 0; y < height; ++y) - { - for (int x = 0; x < width; ++x) - { - int idx = (y * width + x) * 4; // BGRA stride - int offset = y * width + x; - - // Normalize using mean=[0.485, 0.456, 0.406] and std=[0.229, 0.224, 0.225] - float r = static_cast(pixelData[idx + 2]) / 255.0f; - float g = static_cast(pixelData[idx + 1]) / 255.0f; - float b = static_cast(pixelData[idx + 0]) / 255.0f; - - tensorData[0 * height * width + offset] = (r - 0.485f) / 0.229f; - tensorData[1 * height * width + offset] = (g - 0.456f) / 0.224f; - tensorData[2 * height * width + offset] = (b - 0.406f) / 0.225f; - } - } - return tensorData; -} - -std::vector LoadLabels(const std::filesystem::path& labelsPath) -{ - std::ifstream labelFile{labelsPath, std::ifstream::in}; - if (labelFile.fail()) - { - throw std::runtime_error("Unable to load file."); - } - - std::vector labels; - for (std::string line; std::getline(labelFile, line);) - { - labels.push_back(line); - } - - return labels; -} - -std::vector Softmax(std::span logits) -{ - std::vector exps(logits.size()); - const float maxLogit = *std::ranges::max_element(logits); - - float sum = 0.0f; - for (size_t i = 0; i < logits.size(); ++i) - { - exps[i] = std::exp(logits[i] - maxLogit); // stability trick - sum += exps[i]; - } - - for (float& val : exps) - { - val /= sum; - } - - return exps; -} -/* Simple IEEE 754 half-precision (float16) conversion utility in C/C++. Can be replaced with half.hpp or other FP16 - * libraries if available. */ -uint16_t Float32ToFloat16(float value) -{ - const auto asInt = std::bit_cast(value); - const uint32_t sign = (asInt >> 16) & 0x8000; - const uint32_t exponent = ((asInt >> 23) & 0xFF) - 127 + 15; - const uint32_t mantissa = asInt & 0x007FFFFF; - - if (exponent <= 0) - { - return static_cast(sign); - } - - if (exponent >= 31) - { - return static_cast(sign | 0x7C00); // INF - } - - const auto half = static_cast(sign | (exponent << 10) | (mantissa >> 13)); - return half; -} - -std::vector ConvertFloat32ToFloat16(std::span float32Data) -{ - std::vector float16Data(float32Data.size()); - for (size_t i = 0; i < float32Data.size(); ++i) - { - float16Data[i] = Float32ToFloat16(float32Data[i]); - } - return float16Data; -} - -float Float16ToFloat32(uint16_t value) -{ - uint32_t sign = (value >> 15) & 0x1; - uint32_t exponent = (value >> 10) & 0x1F; - uint32_t mantissa = value & 0x3FF; - - if (exponent == 0) - { - return static_cast((sign ? -1 : 1) * 0.0f); - } - else if (exponent == 31) - { - return (sign ? -1 : 1) * (mantissa == 0 ? std::numeric_limits::infinity() : std::nanf("")); - } - - exponent = exponent + (127 - 15); // Bias correction - mantissa = mantissa << 13; // Shift mantissa to float position - - uint32_t result = (sign << 31) | (exponent << 23) | mantissa; - return std::bit_cast(result); -} - -std::vector ConvertFloat16ToFloat32(std::span float16Data) -{ - std::vector float32Data(float16Data.size()); - for (size_t i = 0; i < float16Data.size(); ++i) - { - float32Data[i] = Float16ToFloat32(float16Data[i]); - } - return float32Data; -} - -void PrintResults(const std::vector& labels, const std::vector& results) -{ - // Use softmax to convert logits to probabilities - std::vector probabilities = Softmax(results); - - // Sort the results - std::vector> topResults; - for (size_t i = 0; i < probabilities.size(); ++i) - { - topResults.emplace_back(probabilities[i], static_cast(i)); - } - std::sort(topResults.begin(), topResults.end(), std::greater<>()); - - // Print the top 5 results - for (size_t i = 0; i < std::min(5, topResults.size()); ++i) - { - const auto& [probability, index] = topResults[i]; - std::cout << labels[index] << " with confidence of " << probability << "\n"; - } -} -} // namespace ResNetModelHelper diff --git a/Samples/WindowsML/cpp-cmake/ResNetCommon/include/ResNetModelHelper.hpp b/Samples/WindowsML/cpp-cmake/ResNetCommon/include/ResNetModelHelper.hpp deleted file mode 100644 index d7c40f2b4..000000000 --- a/Samples/WindowsML/cpp-cmake/ResNetCommon/include/ResNetModelHelper.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace ResNetModelHelper -{ -std::wostream& operator<<(std::wostream& outputStream, const winrt::Microsoft::Windows::AI::MachineLearning::ExecutionProviderReadyResultState& readyResultState); - -std::wostream& operator<<(std::wostream& outputStream, const winrt::Microsoft::Windows::AI::MachineLearning::ExecutionProviderReadyState& readyState); - -std::filesystem::path GetExecutablePath(); - -winrt::Windows::Foundation::IAsyncOperation LoadImageFileAsync(winrt::hstring filePath); - -std::vector BindSoftwareBitmapAsTensor(const winrt::Windows::Graphics::Imaging::SoftwareBitmap& bitmap); - -std::vector LoadLabels(const std::filesystem::path& labelsPath); - -std::vector Softmax(std::span logits); - -std::vector ConvertFloat32ToFloat16(std::span float32Data); - -std::vector ConvertFloat16ToFloat32(std::span float16Data); - -void PrintResults(const std::vector& labels, const std::vector& results); -} // namespace ResNetModelHelper diff --git a/Samples/WindowsML/cpp-cmake/ResNetCommon/pch.h b/Samples/WindowsML/cpp-cmake/ResNetCommon/pch.h deleted file mode 100644 index 499f83520..000000000 --- a/Samples/WindowsML/cpp-cmake/ResNetCommon/pch.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -// clang-format off -#include -#include -#include -#include -#include -// clang-format on - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include diff --git a/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop.SelfContained/CMakeLists.txt b/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop.SelfContained/CMakeLists.txt deleted file mode 100644 index 7ecdea51b..000000000 --- a/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop.SelfContained/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -#---------------------------------------------------------------------------------------------------------------------- -# -#---------------------------------------------------------------------------------------------------------------------- -project(ResNetConsoleDesktop.SelfContained LANGUAGES CXX) - -add_executable(ResNetConsoleDesktop.SelfContained - app.manifest - main.cpp -) - -target_precompile_headers(ResNetConsoleDesktop.SelfContained - PRIVATE - pch.h -) - -target_link_libraries(ResNetConsoleDesktop.SelfContained - PRIVATE - ResNetCommon - Microsoft.WindowsAppSDK.ML_SelfContained # Use 'self-contained' mode. - Microsoft.Windows.ImplementationLibrary -) - -post_build_runtime_dll_copy(ResNetConsoleDesktop.SelfContained) - -add_custom_command(TARGET ResNetConsoleDesktop.SelfContained POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy -t $ ${RESNET_MODEL_FILES} ${RESOURCE_FILES} -) diff --git a/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop.SelfContained/app.manifest b/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop.SelfContained/app.manifest deleted file mode 100644 index 42684b7f2..000000000 --- a/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop.SelfContained/app.manifest +++ /dev/null @@ -1,16 +0,0 @@ - - - - - true/pm - permonitorv2,permonitor,unaware - - - - - - - - - - diff --git a/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop.SelfContained/main.cpp b/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop.SelfContained/main.cpp deleted file mode 100644 index f2e2b1b96..000000000 --- a/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop.SelfContained/main.cpp +++ /dev/null @@ -1,174 +0,0 @@ -#include "ResNetModelHelper.hpp" -#include "winml/onnxruntime_c_api.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -using namespace ResNetModelHelper; - -int wmain(int argc, wchar_t* argv[]) noexcept -{ - std::ignore = argc; - std::ignore = argv; - - try - { - winrt::init_apartment(); - Ort::Env env(ORT_LOGGING_LEVEL_ERROR, "CppConsoleDesktop"); - - // Use WinML to download and register Execution Providers - winrt::Microsoft::Windows::AI::MachineLearning::ExecutionProviderCatalog catalog = - winrt::Microsoft::Windows::AI::MachineLearning::ExecutionProviderCatalog::GetDefault(); - auto providers = catalog.FindAllProviders(); - for (const auto& provider : providers) - { - std::wcout << L"Provider : " << std::wstring_view{provider.Name()} << L'\n'; - std::wcout << L" ReadyState : " << provider.ReadyState() << L'\n'; - winrt::Windows::Foundation::IAsyncOperationWithProgress action = provider.EnsureReadyAsync(); - - action.Progress([](const auto& sender, double progress) { - std::wcout << L" Progress : " << progress << L"%\n"; - }); - - winrt::Microsoft::Windows::AI::MachineLearning::ExecutionProviderReadyResult result = action.get(); - std::wcout << L" ReadyResultState : " << result.Status() << L'\n'; - std::wcout << L" ExtendedError : 0x" << std::hex << result.ExtendedError() << L'\n'; - std::wcout << L" DiagnosticText : " << result.DiagnosticText() << L'\n'; - - winrt::hresult errorCode = action.ErrorCode(); - std::wcout << L" ErrorCode : " << errorCode << L'\n'; - - const bool registerResult = provider.TryRegister(); - std::wcout << L" registerResult : " << registerResult << L'\n'; - } - - std::vector devices = env.GetEpDevices(); - std::wcout << L"ONNX providers registered: \n"; - for (const Ort::ConstEpDevice& device : devices) - { - std::cout << device.EpName() << "\n"; - } - - // Set the auto EP selection policy - Ort::SessionOptions sessionOptions; - sessionOptions.SetEpSelectionPolicy(OrtExecutionProviderDevicePolicy_PREFER_CPU); - - // Prepare paths for model and labels - const std::filesystem::path executableFolder = ResNetModelHelper::GetExecutablePath().parent_path(); - const std::filesystem::path modelPath = executableFolder / L"model.onnx"; - const std::filesystem::path labelsPath = executableFolder / L"model.Labels.txt"; - const std::filesystem::path inputImagePath = executableFolder / L"dog.jpg"; - const std::filesystem::path compiledModelPath = executableFolder / L"model_ctx.onnx"; - - bool isCompiledModelAvailable = std::filesystem::exists(compiledModelPath); - if (isCompiledModelAvailable) - { - std::wcout << L"Using compiled model: " << compiledModelPath.wstring() << L'\n'; - } - else - { - std::wcout << L"No compiled model found, attempting to create compiled model at " << compiledModelPath.wstring() << L'\n'; - - Ort::ModelCompilationOptions compile_options(env, sessionOptions); - compile_options.SetInputModelPath(modelPath.c_str()); - compile_options.SetOutputModelPath(compiledModelPath.c_str()); - - std::wcout << L"Starting compile, this may take a few moments...\n"; - Ort::Status compileStatus = Ort::CompileModel(env, compile_options); - if (compileStatus.IsOK()) - { - // Calculate the duration in minutes / seconds / milliseconds - std::wcout << L"Model compiled successfully!\n"; - isCompiledModelAvailable = std::filesystem::exists(compiledModelPath); - } - else - { - std::cerr << "Failed to compile model: " << compileStatus.GetErrorCode() << ", " - << compileStatus.GetErrorMessage() << std::endl; - std::wcerr << "Falling back to uncompiled model\n"; - } - } - std::filesystem::path modelPathToUse = isCompiledModelAvailable ? compiledModelPath : modelPath; - - // Create the session and load the model - Ort::Session session(env, modelPathToUse.c_str(), sessionOptions); - - // Load and Preprocess image - winrt::hstring imagePath{inputImagePath.c_str()}; - - auto inputInfo = session.GetInputTypeInfo(0).GetTensorTypeAndShapeInfo(); - auto inputType = inputInfo.GetElementType(); - - auto imageFrameResult = ResNetModelHelper::LoadImageFileAsync(imagePath); - auto inputTensorData = ResNetModelHelper::BindSoftwareBitmapAsTensor(imageFrameResult.get()); - - auto inputShape = std::array{1, 3, 224, 224}; - auto memoryInfo = Ort::MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault); - std::vector rawInputBytes; - - if (inputType == ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16) - { - auto converted = ResNetModelHelper::ConvertFloat32ToFloat16(inputTensorData); - rawInputBytes.assign( - reinterpret_cast(converted.data()), - reinterpret_cast(converted.data()) + converted.size() * sizeof(uint16_t)); - } - else - { - rawInputBytes.assign( - reinterpret_cast(inputTensorData.data()), - reinterpret_cast(inputTensorData.data()) + inputTensorData.size() * sizeof(float)); - } - - OrtValue* ortValue = nullptr; - - Ort::ThrowOnError( - Ort::GetApi().CreateTensorWithDataAsOrtValue( - memoryInfo, rawInputBytes.data(), rawInputBytes.size(), inputShape.data(), inputShape.size(), inputType, &ortValue)); - Ort::Value inputTensor{ortValue}; - - // Get input/output names - Ort::AllocatorWithDefaultOptions allocator; - auto inputName = session.GetInputNameAllocated(0, allocator); - auto outputName = session.GetOutputNameAllocated(0, allocator); - std::array inputNames = {inputName.get()}; - std::array outputNames = {outputName.get()}; - - // Run inference - auto outputTensors = session.Run(Ort::RunOptions{nullptr}, inputNames.data(), &inputTensor, 1, outputNames.data(), 1); - - // Extract results - std::vector results; - if (inputType == ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16) - { - const auto* outputData = outputTensors[0].GetTensorData(); - size_t outputSize = outputTensors[0].GetTensorTypeAndShapeInfo().GetElementCount(); - std::vector outputFloat16(std::from_range, std::span{outputData, outputSize}); - results = ResNetModelHelper::ConvertFloat16ToFloat32(outputFloat16); - } - else - { - const auto* outputData = outputTensors[0].GetTensorData(); - size_t outputSize = outputTensors[0].GetTensorTypeAndShapeInfo().GetElementCount(); - results = std::vector{std::from_range, std::span{outputData, outputSize}}; - } - - // Load labels and print result - auto labels = ResNetModelHelper::LoadLabels(labelsPath); - ResNetModelHelper::PrintResults(labels, results); - } - catch (const std::exception& ex) - { - std::cerr << "Error: " << ex.what() << "\n"; - return -1; - } - - return 0; -} diff --git a/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop.SelfContained/pch.h b/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop.SelfContained/pch.h deleted file mode 100644 index 2eff3c4f0..000000000 --- a/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop.SelfContained/pch.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -// clang-format off -#include -#include -#include -#include -// clang-format on - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include diff --git a/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop/CMakeLists.txt b/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop/CMakeLists.txt deleted file mode 100644 index 0ec02612f..000000000 --- a/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -#---------------------------------------------------------------------------------------------------------------------- -# -#---------------------------------------------------------------------------------------------------------------------- -project(ResNetConsoleDesktop LANGUAGES CXX) - -add_executable(ResNetConsoleDesktop - app.manifest - main.cpp -) - -target_precompile_headers(ResNetConsoleDesktop - PRIVATE - pch.h -) - -target_link_libraries(ResNetConsoleDesktop - PRIVATE - ResNetCommon - Microsoft.WindowsAppSDK.ML_Framework # Use 'framework' mode. - Microsoft.Windows.ImplementationLibrary -) - -post_build_runtime_dll_copy(ResNetConsoleDesktop) - -add_custom_command(TARGET ResNetConsoleDesktop POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy -t $ ${RESNET_MODEL_FILES} ${RESOURCE_FILES} -) diff --git a/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop/app.manifest b/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop/app.manifest deleted file mode 100644 index 42684b7f2..000000000 --- a/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop/app.manifest +++ /dev/null @@ -1,16 +0,0 @@ - - - - - true/pm - permonitorv2,permonitor,unaware - - - - - - - - - - diff --git a/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop/main.cpp b/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop/main.cpp deleted file mode 100644 index e2daf1040..000000000 --- a/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop/main.cpp +++ /dev/null @@ -1,183 +0,0 @@ -#include "ResNetModelHelper.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace ResNetModelHelper; - -int wmain(int argc, wchar_t* argv[]) noexcept -{ - std::ignore = argc; - std::ignore = argv; - - try - { - // Initialize WinML runtime first. This will add the necessary package dependencies to the process, and initialize the OnnxRuntime. - Microsoft::Windows::AI::MachineLearning::WinMLRuntime winmlRuntime; - if (FAILED(winmlRuntime.GetHResult())) - { - std::cerr << "Failed to initialize WinML runtime: " << std::hex << winmlRuntime.GetHResult() << std::endl; - return -1; - } - - winrt::init_apartment(); - Ort::Env env(ORT_LOGGING_LEVEL_ERROR, "CppConsoleDesktop"); - - // Use WinML to download and register Execution Providers - winrt::Microsoft::Windows::AI::MachineLearning::ExecutionProviderCatalog catalog = - winrt::Microsoft::Windows::AI::MachineLearning::ExecutionProviderCatalog::GetDefault(); - auto providers = catalog.FindAllProviders(); - for (const auto& provider : providers) - { - std::wcout << L"Provider : " << std::wstring_view{provider.Name()} << L'\n'; - std::wcout << L" ReadyState : " << provider.ReadyState() << L'\n'; - winrt::Windows::Foundation::IAsyncOperationWithProgress action = provider.EnsureReadyAsync(); - - action.Progress([](const auto& sender, double progress) { - std::wcout << L" Progress : " << progress << L"%\n"; - }); - - winrt::Microsoft::Windows::AI::MachineLearning::ExecutionProviderReadyResult result = action.get(); - std::wcout << L" ReadyResultState : " << result.Status() << L'\n'; - std::wcout << L" ExtendedError : 0x" << std::hex << result.ExtendedError() << L'\n'; - std::wcout << L" DiagnosticText : " << result.DiagnosticText() << L'\n'; - - winrt::hresult errorCode = action.ErrorCode(); - std::wcout << L" ErrorCode : " << errorCode << L'\n'; - - const bool registerResult = provider.TryRegister(); - std::wcout << L" registerResult : " << registerResult << L'\n'; - } - - std::vector devices = env.GetEpDevices(); - std::wcout << L"ONNX providers registered: \n"; - for (const Ort::ConstEpDevice& device : devices) - { - std::cout << device.EpName() << "\n"; - } - - // Set the auto EP selection policy - Ort::SessionOptions sessionOptions; - sessionOptions.SetEpSelectionPolicy(OrtExecutionProviderDevicePolicy_PREFER_CPU); - - // Prepare paths for model and labels - const std::filesystem::path executableFolder = ResNetModelHelper::GetExecutablePath().parent_path(); - const std::filesystem::path modelPath = executableFolder / L"model.onnx"; - const std::filesystem::path labelsPath = executableFolder / L"model.Labels.txt"; - const std::filesystem::path inputImagePath = executableFolder / L"dog.jpg"; - const std::filesystem::path compiledModelPath = executableFolder / L"model_ctx.onnx"; - - bool isCompiledModelAvailable = std::filesystem::exists(compiledModelPath); - if (isCompiledModelAvailable) - { - std::wcout << L"Using compiled model: " << compiledModelPath.wstring() << L'\n'; - } - else - { - std::wcout << L"No compiled model found, attempting to create compiled model at " << compiledModelPath.wstring() << L'\n'; - - Ort::ModelCompilationOptions compile_options(env, sessionOptions); - compile_options.SetInputModelPath(modelPath.c_str()); - compile_options.SetOutputModelPath(compiledModelPath.c_str()); - - std::wcout << L"Starting compile, this may take a few moments...\n"; - Ort::Status compileStatus = Ort::CompileModel(env, compile_options); - if (compileStatus.IsOK()) - { - // Calculate the duration in minutes / seconds / milliseconds - std::wcout << L"Model compiled successfully!\n"; - isCompiledModelAvailable = std::filesystem::exists(compiledModelPath); - } - else - { - std::cerr << "Failed to compile model: " << compileStatus.GetErrorCode() << ", " - << compileStatus.GetErrorMessage() << std::endl; - std::wcerr << "Falling back to uncompiled model\n"; - } - } - std::filesystem::path modelPathToUse = isCompiledModelAvailable ? compiledModelPath : modelPath; - - // Create the session and load the model - Ort::Session session(env, modelPathToUse.c_str(), sessionOptions); - - // Load and Preprocess image - winrt::hstring imagePath{inputImagePath.c_str()}; - - auto inputInfo = session.GetInputTypeInfo(0).GetTensorTypeAndShapeInfo(); - auto inputType = inputInfo.GetElementType(); - - auto imageFrameResult = ResNetModelHelper::LoadImageFileAsync(imagePath); - auto inputTensorData = ResNetModelHelper::BindSoftwareBitmapAsTensor(imageFrameResult.get()); - - auto inputShape = std::array{1, 3, 224, 224}; - auto memoryInfo = Ort::MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault); - std::vector rawInputBytes; - - if (inputType == ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16) - { - auto converted = ResNetModelHelper::ConvertFloat32ToFloat16(inputTensorData); - rawInputBytes.assign( - reinterpret_cast(converted.data()), - reinterpret_cast(converted.data()) + converted.size() * sizeof(uint16_t)); - } - else - { - rawInputBytes.assign( - reinterpret_cast(inputTensorData.data()), - reinterpret_cast(inputTensorData.data()) + inputTensorData.size() * sizeof(float)); - } - - OrtValue* ortValue = nullptr; - - Ort::ThrowOnError( - Ort::GetApi().CreateTensorWithDataAsOrtValue( - memoryInfo, rawInputBytes.data(), rawInputBytes.size(), inputShape.data(), inputShape.size(), inputType, &ortValue)); - Ort::Value inputTensor{ortValue}; - - // Get input/output names - Ort::AllocatorWithDefaultOptions allocator; - auto inputName = session.GetInputNameAllocated(0, allocator); - auto outputName = session.GetOutputNameAllocated(0, allocator); - std::array inputNames = {inputName.get()}; - std::array outputNames = {outputName.get()}; - - // Run inference - auto outputTensors = session.Run(Ort::RunOptions{nullptr}, inputNames.data(), &inputTensor, 1, outputNames.data(), 1); - - // Extract results - std::vector results; - if (inputType == ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16) - { - const auto* outputData = outputTensors[0].GetTensorData(); - size_t outputSize = outputTensors[0].GetTensorTypeAndShapeInfo().GetElementCount(); - std::vector outputFloat16(std::from_range, std::span{outputData, outputSize}); - results = ResNetModelHelper::ConvertFloat16ToFloat32(outputFloat16); - } - else - { - const auto* outputData = outputTensors[0].GetTensorData(); - size_t outputSize = outputTensors[0].GetTensorTypeAndShapeInfo().GetElementCount(); - results = std::vector{std::from_range, std::span{outputData, outputSize}}; - } - - // Load labels and print result - auto labels = ResNetModelHelper::LoadLabels(labelsPath); - ResNetModelHelper::PrintResults(labels, results); - } - catch (const std::exception& ex) - { - std::cerr << "Error: " << ex.what() << "\n"; - return -1; - } - - return 0; -} diff --git a/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop/pch.h b/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop/pch.h deleted file mode 100644 index 2eff3c4f0..000000000 --- a/Samples/WindowsML/cpp-cmake/ResNetConsoleDesktop/pch.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -// clang-format off -#include -#include -#include -#include -// clang-format on - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include diff --git a/Samples/WindowsML/cpp-cmake/Resources/dog.jpg b/Samples/WindowsML/cpp-cmake/Resources/dog.jpg deleted file mode 100644 index 3a20c37d3..000000000 Binary files a/Samples/WindowsML/cpp-cmake/Resources/dog.jpg and /dev/null differ diff --git a/Samples/WindowsML/cmake/WinMLEpCatalog/.gitignore b/Samples/WindowsML/cpp-cmake/WinMLEpCatalog/.gitignore similarity index 100% rename from Samples/WindowsML/cmake/WinMLEpCatalog/.gitignore rename to Samples/WindowsML/cpp-cmake/WinMLEpCatalog/.gitignore diff --git a/Samples/WindowsML/cmake/WinMLEpCatalog/CMakeLists.txt b/Samples/WindowsML/cpp-cmake/WinMLEpCatalog/CMakeLists.txt similarity index 91% rename from Samples/WindowsML/cmake/WinMLEpCatalog/CMakeLists.txt rename to Samples/WindowsML/cpp-cmake/WinMLEpCatalog/CMakeLists.txt index 7c6d72edf..e66af0128 100644 --- a/Samples/WindowsML/cmake/WinMLEpCatalog/CMakeLists.txt +++ b/Samples/WindowsML/cpp-cmake/WinMLEpCatalog/CMakeLists.txt @@ -8,8 +8,8 @@ project(WinMLEpCatalogSample ) # NuGet package version -set(WINML_NUGET_ID "Microsoft.WindowsAppSDK.ML" CACHE STRING "NuGet package ID") -set(WINML_NUGET_VERSION "1.8.2141" CACHE STRING "NuGet package version") +set(WINML_NUGET_ID "Microsoft.Windows.AI.MachineLearning" CACHE STRING "NuGet package ID") +set(WINML_NUGET_VERSION "2.1.1" CACHE STRING "NuGet package version") # Packages are restored / extracted under the build directory. cmake_path(APPEND CMAKE_CURRENT_BINARY_DIR "packages" OUTPUT_VARIABLE WINML_PACKAGES_DIR) @@ -97,14 +97,13 @@ add_custom_command(TARGET WinMLEpCatalogSample POST_BUILD VERBATIM ) -# DirectML.dll and onnxruntime_providers_shared.dll have no import libraries, -# so they are not included in TARGET_RUNTIME_DLLS. Copy them explicitly so -# execution provider registration works when the sample runs in-place. +# DirectML.dll has no import library, so it is not included in TARGET_RUNTIME_DLLS. +# Copy it explicitly so execution provider registration works when the sample runs in-place. +# Note: onnxruntime_providers_shared.dll was removed — it is no longer part of the +# Microsoft.Windows.AI.MachineLearning 2.x package. add_custom_command(TARGET WinMLEpCatalogSample POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${WINML_DIRECTML_DLL}" $ - COMMAND ${CMAKE_COMMAND} -E copy_if_different - "${WINML_ONNXRUNTIME_PROVIDERS_SHARED_DLL}" $ COMMAND_EXPAND_LISTS VERBATIM ) diff --git a/Samples/WindowsML/cmake/WinMLEpCatalog/CMakePresets.json b/Samples/WindowsML/cpp-cmake/WinMLEpCatalog/CMakePresets.json similarity index 100% rename from Samples/WindowsML/cmake/WinMLEpCatalog/CMakePresets.json rename to Samples/WindowsML/cpp-cmake/WinMLEpCatalog/CMakePresets.json diff --git a/Samples/WindowsML/cmake/WinMLEpCatalog/README.md b/Samples/WindowsML/cpp-cmake/WinMLEpCatalog/README.md similarity index 98% rename from Samples/WindowsML/cmake/WinMLEpCatalog/README.md rename to Samples/WindowsML/cpp-cmake/WinMLEpCatalog/README.md index d64cd3754..85da00327 100644 --- a/Samples/WindowsML/cmake/WinMLEpCatalog/README.md +++ b/Samples/WindowsML/cpp-cmake/WinMLEpCatalog/README.md @@ -71,7 +71,7 @@ cmake --build out/build/nuget --config RelWithDebInfo To use a different version: ```powershell -cmake --preset nuget -DWINML_NUGET_VERSION=1.8.2124 +cmake --preset nuget -DWINML_NUGET_VERSION=2.1.1 ``` To use a local `.nupkg` instead of NuGet restore, place it in this directory diff --git a/Samples/WindowsML/cmake/WinMLEpCatalog/build.ps1 b/Samples/WindowsML/cpp-cmake/WinMLEpCatalog/build.ps1 similarity index 100% rename from Samples/WindowsML/cmake/WinMLEpCatalog/build.ps1 rename to Samples/WindowsML/cpp-cmake/WinMLEpCatalog/build.ps1 diff --git a/Samples/WindowsML/cmake/WinMLEpCatalog/main.cpp b/Samples/WindowsML/cpp-cmake/WinMLEpCatalog/main.cpp similarity index 100% rename from Samples/WindowsML/cmake/WinMLEpCatalog/main.cpp rename to Samples/WindowsML/cpp-cmake/WinMLEpCatalog/main.cpp diff --git a/Samples/WindowsML/cpp-cmake/readme.md b/Samples/WindowsML/cpp-cmake/readme.md deleted file mode 100644 index cc4819dfc..000000000 --- a/Samples/WindowsML/cpp-cmake/readme.md +++ /dev/null @@ -1,51 +0,0 @@ -# Windows ML C++ CMake Samples - -## Overview - -This folder contains samples showing how to consume WindowsML from C++ using a CMake-based build. - -> [!IMPORTANT] -> These CMake samples are exploring WindowsAppSDK consumption through CMake using the experimental project: . -> Please try out the samples, and provide feedback on the approach in the repository. - -## Getting Started - -In addition to the requirements called out in [the repository README.md](../../../README.md), the CMake builds require CMake 3.31 or higher. You can install CMake on Windows using WinGet with: - -```powershell -winget install --id Kitware.CMake --source winget -``` - -To build the samples using Ninja, then Ninja needs to be installed. See for more details. You can install Ninja on Windows using WinGet with: - -```powershell -winget install --id Ninja-build.Ninja --source winget -``` - -## Building - -The samples use `CMakePresets.json` to describe the build and configuration presets that can be used. There are two types of presets, those that use the 'Visual Studio 17 2022' generator and those that use the 'Ninja Multi-Config' generator. Visual Studio generator presets can be built from any environment. The Ninja Multi-Config generator presets have to be built from a platform-specific Visual Studio command prompt. Create a platform-specific build prompt by running - for example: - -```cmd -C:\Program Files\Microsoft Visual Studio\2022\Enterprise\vc\Auxiliary\Build\vcvars64.bat -``` - -for an x64 build, or: - -```cmd -C:\Program Files\Microsoft Visual Studio\2022\Enterprise\vc\Auxiliary\Build\vcvarsamd64_arm64.bat -``` - -for an arm64 cross-compiling prompt on an x64 OS. - -In order to build a given preset, simply run the CMake 'configuration' step: - -```powershell -cmake --preset -``` - -Followed by the CMake 'build' step: - -```powershell -cmake --build --preset -``` diff --git a/Samples/WindowsML/cpp/CppConsoleDesktop.FrameworkDependent/CppConsoleDesktop.FrameworkDependent.vcxproj b/Samples/WindowsML/cpp/CppConsoleDesktop.FrameworkDependent/CppConsoleDesktop.FrameworkDependent.vcxproj index 404a1e884..93ad10b03 100644 --- a/Samples/WindowsML/cpp/CppConsoleDesktop.FrameworkDependent/CppConsoleDesktop.FrameworkDependent.vcxproj +++ b/Samples/WindowsML/cpp/CppConsoleDesktop.FrameworkDependent/CppConsoleDesktop.FrameworkDependent.vcxproj @@ -11,11 +11,12 @@ - - - - - + + + + + + @@ -83,11 +84,12 @@ - - - - - + + + + + + @@ -99,15 +101,17 @@ - - - - - - - - - - + + + + + + + + + + + + diff --git a/Samples/WindowsML/cpp/CppConsoleDesktop.FrameworkDependent/packages.config b/Samples/WindowsML/cpp/CppConsoleDesktop.FrameworkDependent/packages.config index 27d08c6c9..ffec8071f 100644 --- a/Samples/WindowsML/cpp/CppConsoleDesktop.FrameworkDependent/packages.config +++ b/Samples/WindowsML/cpp/CppConsoleDesktop.FrameworkDependent/packages.config @@ -3,9 +3,10 @@ - - - - - + + + + + + \ No newline at end of file diff --git a/Samples/WindowsML/cpp/CppConsoleDesktop.GenAI/CppConsoleDesktop.GenAI.vcxproj b/Samples/WindowsML/cpp/CppConsoleDesktop.GenAI/CppConsoleDesktop.GenAI.vcxproj index 2ff5e500c..714d1d33c 100644 --- a/Samples/WindowsML/cpp/CppConsoleDesktop.GenAI/CppConsoleDesktop.GenAI.vcxproj +++ b/Samples/WindowsML/cpp/CppConsoleDesktop.GenAI/CppConsoleDesktop.GenAI.vcxproj @@ -8,17 +8,18 @@ true - - - - - - - - - - - + + + + + + + + + + + + @@ -81,17 +82,18 @@ - - - - - - - - - - - + + + + + + + + + + + + @@ -105,27 +107,27 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Samples/WindowsML/cpp/CppConsoleDesktop.GenAI/packages.config b/Samples/WindowsML/cpp/CppConsoleDesktop.GenAI/packages.config index 9614bb8ef..33fe74106 100644 --- a/Samples/WindowsML/cpp/CppConsoleDesktop.GenAI/packages.config +++ b/Samples/WindowsML/cpp/CppConsoleDesktop.GenAI/packages.config @@ -1,19 +1,20 @@ - + - - - - - - - - - - - + + + + + + + + + + + + \ No newline at end of file diff --git a/Samples/WindowsML/cpp/CppConsoleDesktop.SelfContained/CppConsoleDesktop.SelfContained.vcxproj b/Samples/WindowsML/cpp/CppConsoleDesktop.SelfContained/CppConsoleDesktop.SelfContained.vcxproj index 9da2c799f..06ad5200e 100644 --- a/Samples/WindowsML/cpp/CppConsoleDesktop.SelfContained/CppConsoleDesktop.SelfContained.vcxproj +++ b/Samples/WindowsML/cpp/CppConsoleDesktop.SelfContained/CppConsoleDesktop.SelfContained.vcxproj @@ -8,10 +8,11 @@ true - - - - + + + + + @@ -81,10 +82,11 @@ - - - - + + + + + @@ -96,13 +98,15 @@ - - - - - - - - + + + + + + + + + + diff --git a/Samples/WindowsML/cpp/CppConsoleDesktop.SelfContained/packages.config b/Samples/WindowsML/cpp/CppConsoleDesktop.SelfContained/packages.config index 8cb36afee..6e908bd91 100644 --- a/Samples/WindowsML/cpp/CppConsoleDesktop.SelfContained/packages.config +++ b/Samples/WindowsML/cpp/CppConsoleDesktop.SelfContained/packages.config @@ -3,8 +3,9 @@ - - - - + + + + + \ No newline at end of file diff --git a/Samples/WindowsML/cpp/CppConsoleDesktop/CppConsoleDesktop.vcxproj b/Samples/WindowsML/cpp/CppConsoleDesktop/CppConsoleDesktop.vcxproj index 7cfdf03ef..57858b1b4 100644 --- a/Samples/WindowsML/cpp/CppConsoleDesktop/CppConsoleDesktop.vcxproj +++ b/Samples/WindowsML/cpp/CppConsoleDesktop/CppConsoleDesktop.vcxproj @@ -8,15 +8,16 @@ ..\..\packages - - - - - - - - - + + + + + + + + + + @@ -89,15 +90,16 @@ - - - - - - - - - + + + + + + + + + + @@ -110,23 +112,23 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + diff --git a/Samples/WindowsML/cpp/CppConsoleDesktop/README.md b/Samples/WindowsML/cpp/CppConsoleDesktop/README.md index ced719bc4..287b3af87 100644 --- a/Samples/WindowsML/cpp/CppConsoleDesktop/README.md +++ b/Samples/WindowsML/cpp/CppConsoleDesktop/README.md @@ -11,12 +11,16 @@ This sample demonstrates how to use ONNX Runtime in a C++ desktop application, f ``` CppConsoleDesktop.exe [options] Options: - --ep_policy Set execution provider policy (NPU, CPU, GPU, DEFAULT). Default: DEFAULT - --compile Compile the model - --download Download required packages - --model Path to input ONNX model (default: SqueezeNet.onnx in executable directory) - --compiled_output Path for compiled output model (default: auto-generated with device info) - --image_path Path to the input image (default: sample kitten image) + --ep_policy (Required*) Set execution provider selection policy (NPU, CPU, GPU, DEFAULT) + --ep_name (Required*) Explicit execution provider name (mutually exclusive with --ep_policy) + --compile Compile the model + --download Download required packages + --model Path to input ONNX model (default: SqueezeNet.onnx in executable directory) + --compiled_output Path for compiled output model (default: auto-generated with device info) + --image_path Path to the input image (default: sample kitten image) + +Exactly one of --ep_policy or --ep_name must be specified. +--use_model_catalog and --model are mutually exclusive. ``` ## Key Features diff --git a/Samples/WindowsML/cpp/CppConsoleDesktop/packages.config b/Samples/WindowsML/cpp/CppConsoleDesktop/packages.config index 7838522de..367472c60 100644 --- a/Samples/WindowsML/cpp/CppConsoleDesktop/packages.config +++ b/Samples/WindowsML/cpp/CppConsoleDesktop/packages.config @@ -1,18 +1,19 @@ - + - - - - - - - - - - + + + + + + + + + + + diff --git a/Samples/WindowsML/cpp/CppConsoleDll/ConsoleClient/ConsoleClient.cpp b/Samples/WindowsML/cpp/CppConsoleDll/ConsoleClient/ConsoleClient.cpp deleted file mode 100644 index 7299b8ce1..000000000 --- a/Samples/WindowsML/cpp/CppConsoleDll/ConsoleClient/ConsoleClient.cpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE.md in the repo root for license information. - -#include -#include - -// Function pointer type for the DLL exports -typedef char*(__stdcall* GetOrtVersionStringFunc)(); - -int main() -{ - HMODULE hDll = LoadLibraryW(L"WindowsMLWrapper.dll"); - if (hDll == nullptr) - { - std::wcout << L"Failed to load WindowsMLWrapper.dll" << std::endl; - return 1; - } - - // Get function pointers - GetOrtVersionStringFunc getOrtVersionString = (GetOrtVersionStringFunc)GetProcAddress(hDll, "GetOrtVersionString"); - if (getOrtVersionString == nullptr) - { - std::wcout << L"Failed to get GetOrtVersionString function from DLL" << std::endl; - FreeLibrary(hDll); - return 1; - } - - try - { - // Call ONNX Runtime version function - std::wcout << L"Calling GetOrtVersionString from DLL..." << std::endl; - char* versionString = getOrtVersionString(); - if (versionString != nullptr) - { - std::wcout << L"ONNX Runtime version: " << versionString << std::endl; - CoTaskMemFree(versionString); // Clean up string allocated by DLL - } - else - { - std::wcout << L"GetOrtVersionString returned null" << std::endl; - } - } - catch (...) - { - std::wcout << L"Exception occurred while calling DLL function" << std::endl; - FreeLibrary(hDll); - return 1; - } - - FreeLibrary(hDll); - return 0; -} diff --git a/Samples/WindowsML/cpp/CppConsoleDll/ConsoleClient/ConsoleClient.vcxproj b/Samples/WindowsML/cpp/CppConsoleDll/ConsoleClient/ConsoleClient.vcxproj deleted file mode 100644 index 1eec70652..000000000 --- a/Samples/WindowsML/cpp/CppConsoleDll/ConsoleClient/ConsoleClient.vcxproj +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - 17.0 - Win32Proj - {A1B2C3D4-5678-9012-3456-789012345678} - ConsoleClient - 10.0 - - - - Application - v143 - Unicode - - - - - stdcpp20 - WIN32;_CONSOLE;%(PreprocessorDefinitions) - true - Level4 - - - Console - true - - - - - - - - {B8F65F4C-1234-4567-8901-123456789ABC} - false - false - true - - - - diff --git a/Samples/WindowsML/cpp/CppConsoleDll/README.md b/Samples/WindowsML/cpp/CppConsoleDll/README.md deleted file mode 100644 index 50a4973e8..000000000 --- a/Samples/WindowsML/cpp/CppConsoleDll/README.md +++ /dev/null @@ -1,59 +0,0 @@ -# CppConsoleDll Sample - -This sample demonstrates how to use WindowsML APIs from within a DLL that is consumed by a separate executable. This pattern is particularly useful when you need to share WindowsML functionality across multiple applications or isolate ML functionality in a separate module. - -## Overview - -The sample consists of two projects: - -1. **WindowsMLWrapper.dll** - A Dynamic Link Library that: - - Uses the WindowsAppSDK with ML support - - Exports C-style functions that can be easily consumed by other applications - - Demonstrates proper string memory management using CoTaskMemAlloc - - Shows how to use ONNX Runtime APIs from WindowsAppSDK - -2. **ConsoleClient.exe** - A minimal console application that: - - Dynamically loads the WindowsMLWrapper.dll - - Calls the exported functions - - Properly manages memory allocated by the DLL - - Demonstrates error handling for DLL loading and function calls - -## Key Features - -- **WindowsAppSdkBootstrapInitialize**: The DLL project uses `WindowsAppSdkBootstrapInitialize=true` to ensure proper initialization of the WindowsAppSDK runtime when loaded -- **Memory Management**: Exported functions use CoTaskMemAlloc to allocate strings, which are freed by the client using CoTaskMemFree -- **Error Handling**: Both the DLL and client demonstrate proper error handling patterns -- **Minimal Dependencies**: The client application has minimal dependencies and only links to what it needs - -## Building - -Both projects are included in the main WindowsML-Samples.sln solution. When you build the solution: - -1. WindowsMLWrapper.dll is built first -2. ConsoleClient.exe is built with a dependency on the DLL project -3. The DLL is automatically copied to the client's output directory - -## Running - -After building, you can run ConsoleClient.exe directly. It will: - -1. Load WindowsMLWrapper.dll from the same directory -2. Call the exported functions -3. Display the results in the console -4. Clean up and exit - -Expected output: -``` -Calling GetOrtVersionString from DLL... -ONNX Runtime version: [ONNX Runtime version string] -``` - -## Architecture Notes - -This pattern is useful in scenarios such as: -- Creating reusable ML components across multiple applications -- Isolating ML functionality in a separate process space -- Building plugin architectures where ML capabilities are loaded dynamically -- Separating concerns between UI and ML processing components - -The DLL handles all WindowsAppSDK initialization and cleanup, while the client application can be kept lightweight and focused on its primary functionality. diff --git a/Samples/WindowsML/cpp/CppConsoleDll/WindowsMLWrapper/WindowsMLWrapper.cpp b/Samples/WindowsML/cpp/CppConsoleDll/WindowsMLWrapper/WindowsMLWrapper.cpp deleted file mode 100644 index 23decb5a1..000000000 --- a/Samples/WindowsML/cpp/CppConsoleDll/WindowsMLWrapper/WindowsMLWrapper.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE.md in the repo root for license information. - -#include "WindowsMLWrapper.h" -#include -#include -#include - -// Include ONNX Runtime headers from WindowsAppSDK.ML package -#include - -extern "C" __declspec(dllexport) char* GetOrtVersionString() -{ - try - { - // Get ONNX Runtime version from the actual ONNX Runtime API - const char* version = OrtGetApiBase()->GetVersionString(); - - size_t len = strlen(version) + 1; - char* result = static_cast(CoTaskMemAlloc(len)); - if (result) - { - strcpy_s(result, len, version); - } - return result; - } - catch (...) - { - // Fallback in case of error - const char* fallback = "ONNX Runtime (Error getting version)"; - size_t len = strlen(fallback) + 1; - char* result = static_cast(CoTaskMemAlloc(len)); - if (result) - { - strcpy_s(result, len, fallback); - } - return result; - } -} - -extern "C" __declspec(dllexport) void FreeString(char* str) -{ - if (str) - { - CoTaskMemFree(str); - } -} diff --git a/Samples/WindowsML/cpp/CppConsoleDll/WindowsMLWrapper/WindowsMLWrapper.h b/Samples/WindowsML/cpp/CppConsoleDll/WindowsMLWrapper/WindowsMLWrapper.h deleted file mode 100644 index cc6992a38..000000000 --- a/Samples/WindowsML/cpp/CppConsoleDll/WindowsMLWrapper/WindowsMLWrapper.h +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE.md in the repo root for license information. - -#pragma once - -#include - -#ifdef WINDOWSMLWRAPPER_EXPORTS -#define WINDOWSMLWRAPPER_API __declspec(dllexport) -#else -#define WINDOWSMLWRAPPER_API __declspec(dllimport) -#endif - -extern "C" -{ - // Returns the ONNX Runtime version string - // Caller is responsible for freeing the returned string using CoTaskMemFree - WINDOWSMLWRAPPER_API char* GetOrtVersionString(); -} diff --git a/Samples/WindowsML/cpp/CppConsoleDll/WindowsMLWrapper/WindowsMLWrapper.vcxproj b/Samples/WindowsML/cpp/CppConsoleDll/WindowsMLWrapper/WindowsMLWrapper.vcxproj deleted file mode 100644 index bc7ff569c..000000000 --- a/Samples/WindowsML/cpp/CppConsoleDll/WindowsMLWrapper/WindowsMLWrapper.vcxproj +++ /dev/null @@ -1,116 +0,0 @@ - - - - - ..\..\..\packages - - - - false - true - - - - - - - - - - - - - - - - - - - - - - 17.0 - Win32Proj - {B8F65F4C-1234-4567-8901-123456789ABC} - WindowsMLWrapper - 10.0 - None - true - en-US - - - - DynamicLibrary - v143 - Unicode - - - - - stdcpp20 - WIN32;_WINDOWS;_USRDLL;WINDOWSMLWRAPPER_EXPORTS;%(PreprocessorDefinitions) - true - Level4 - - - Windows - true - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Samples/WindowsML/cpp/CppConsoleDll/WindowsMLWrapper/packages.config b/Samples/WindowsML/cpp/CppConsoleDll/WindowsMLWrapper/packages.config deleted file mode 100644 index c1d47d402..000000000 --- a/Samples/WindowsML/cpp/CppConsoleDll/WindowsMLWrapper/packages.config +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/CppResnetBuildDemo.cpp b/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/CppResnetBuildDemo.cpp deleted file mode 100644 index a1b7ecfc2..000000000 --- a/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/CppResnetBuildDemo.cpp +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE.md in the repo root for license information. -#include "ResnetModelHelper.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include - -int wmain(int argc, wchar_t* argv[]) noexcept -{ - std::ignore = argc; - std::ignore = argv; - - auto env = Ort::Env(); - std::cout << "ONNX Version string: " << Ort::GetVersionString() << std::endl; - std::cout << "Getting available providers..." << std::endl; - auto catalog = winrt::Microsoft::Windows::AI::MachineLearning::ExecutionProviderCatalog::GetDefault(); - auto providers = catalog.FindAllProviders(); - for (const auto& provider : providers) - { - std::wcout << "Provider: " << provider.Name().c_str() << std::endl; - provider.EnsureReadyAsync().get(); - provider.TryRegister(); - } - - auto devices = env.GetEpDevices(); - std::cout << "ONNX providers registered: " << std::endl; - for (const auto& device : devices) - { - std::cout << device.EpName() << " " << std::endl; - } - - // Set the auto EP selection policy - Ort::SessionOptions sessionOptions; - sessionOptions.SetEpSelectionPolicy(OrtExecutionProviderDevicePolicy_MIN_OVERALL_POWER); - - // Prepare paths for model and labels - std::filesystem::path executableFolder = ResnetModelHelper::GetExecutablePath().parent_path(); - std::filesystem::path labelsPath = executableFolder / "ResNet50Labels.txt"; - std::filesystem::path dogImagePath = executableFolder / "dog.jpg"; - - // TODO: use AITK Model Conversion tool to get resnet and paste the path here - std::filesystem::path modelPath = L""; - std::filesystem::path compiledModelPath = L""; - bool isCompiledModelAvailable = std::filesystem::exists(compiledModelPath); - - if (modelPath.empty()) - { - std::cerr << "Please specify the path to the ResNet model in the program source code." << std::endl; - std::cerr << "Exiting..." << std::endl; - return 1; - } - - if (isCompiledModelAvailable) - { - std::cout << "Using compiled model: " << compiledModelPath << std::endl; - } - else - { - std::cout << "No compiled model found, attempting to create compiled model at " << compiledModelPath << std::endl; - - Ort::ModelCompilationOptions compile_options(env, sessionOptions); - compile_options.SetInputModelPath(modelPath.c_str()); - compile_options.SetOutputModelPath(compiledModelPath.c_str()); - - std::cout << "Starting compile, this may take a few moments..." << std::endl; - Ort::Status compileStatus = Ort::CompileModel(env, compile_options); - if (compileStatus.IsOK()) - { - // Calculate the duration in minutes / seconds / milliseconds - std::cout << "Model compiled successfully!" << std::endl; - isCompiledModelAvailable = std::filesystem::exists(compiledModelPath); - } - else - { - std::cerr << "Failed to compile model: " << compileStatus.GetErrorCode() << ", " << compileStatus.GetErrorMessage() - << std::endl; - std::cerr << "Falling back to uncompiled model" << std::endl; - } - } - std::filesystem::path modelPathToUse = isCompiledModelAvailable ? compiledModelPath : modelPath; - - // Create the session and load the model - Ort::Session session(env, modelPathToUse.c_str(), sessionOptions); - std::cout << "ResNet model loaded" << std::endl; - - // Load and Preprocess image - winrt::hstring imagePath{dogImagePath.c_str()}; - auto imageFrameResult = ResnetModelHelper::LoadImageFileAsync(imagePath); - auto inputTensorData = ResnetModelHelper::BindSoftwareBitmapAsTensor(imageFrameResult.get()); - - // Prepare input tensor - auto inputInfo = session.GetInputTypeInfo(0).GetTensorTypeAndShapeInfo(); - auto inputType = inputInfo.GetElementType(); - - auto inputShape = std::array{1, 3, 224, 224}; - auto memoryInfo = Ort::MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault); - std::vector rawInputBytes; - - if (inputType == ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16) - { - auto converted = ResnetModelHelper::ConvertFloat32ToFloat16(inputTensorData); - rawInputBytes.assign( - reinterpret_cast(converted.data()), - reinterpret_cast(converted.data()) + converted.size() * sizeof(uint16_t)); - } - else - { - rawInputBytes.assign( - reinterpret_cast(inputTensorData.data()), - reinterpret_cast(inputTensorData.data()) + inputTensorData.size() * sizeof(float)); - } - - OrtValue* ortValue = nullptr; - - Ort::ThrowOnError(Ort::GetApi().CreateTensorWithDataAsOrtValue( - memoryInfo, rawInputBytes.data(), rawInputBytes.size(), inputShape.data(), inputShape.size(), inputType, &ortValue)); - Ort::Value inputTensor{ortValue}; - - const int iterations = 20; - std::cout << "Running inference for " << iterations << " iterations" << std::endl; - auto before = std::chrono::high_resolution_clock::now(); - for (int i = 0; i < iterations; i++) - { - // std::cout << "---------------------------------------------" << std::endl; - // std::cout << "Running inference for " << i + 1 << "th time" << std::endl; - // std::cout << "---------------------------------------------"<< std::endl; - std::cout << "."; - - // Get input/output names - Ort::AllocatorWithDefaultOptions allocator; - auto inputName = session.GetInputNameAllocated(0, allocator); - auto outputName = session.GetOutputNameAllocated(0, allocator); - std::vector inputNames = {inputName.get()}; - std::vector outputNames = {outputName.get()}; - - // Run inference - auto outputTensors = session.Run(Ort::RunOptions{nullptr}, inputNames.data(), &inputTensor, 1, outputNames.data(), 1); - - // Extract results - std::vector results; - if (inputType == ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16) - { - auto outputData = outputTensors[0].GetTensorMutableData(); - size_t outputSize = outputTensors[0].GetTensorTypeAndShapeInfo().GetElementCount(); - std::vector outputFloat16(outputData, outputData + outputSize); - results = ResnetModelHelper::ConvertFloat16ToFloat32(outputFloat16); - } - else - { - auto outputData = outputTensors[0].GetTensorMutableData(); - size_t outputSize = outputTensors[0].GetTensorTypeAndShapeInfo().GetElementCount(); - results.assign(outputData, outputData + outputSize); - } - - if (i == iterations - 1) - { - // Load labels and print result - std::cout << "\nOutput for the last iteration" << std::endl; - auto labels = ResnetModelHelper::LoadLabels(labelsPath); - ResnetModelHelper::PrintResults(labels, results); - } - inputName.release(); - outputName.release(); - } - std::cout << "---------------------------------------------" << std::endl; - auto after = std::chrono::high_resolution_clock::now(); - auto duration = std::chrono::duration_cast(after - before); - std::cout << "Time taken for " << iterations << " iterations: " << duration.count() / 1000ull << " seconds" << std::endl; - std::cout << "Avg time per iteration : " << duration.count() / static_cast(iterations) << " milliseconds" << std::endl; - - return 0; -} diff --git a/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/CppResnetBuildDemo.filters b/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/CppResnetBuildDemo.filters deleted file mode 100644 index ab7017609..000000000 --- a/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/CppResnetBuildDemo.filters +++ /dev/null @@ -1,34 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - {e28318d9-db85-4820-86b9-a93a24a1d434} - - - - - Source Files - - - Source Files - - - - - - - - - \ No newline at end of file diff --git a/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/CppResnetBuildDemo.vcxproj b/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/CppResnetBuildDemo.vcxproj deleted file mode 100644 index b744795e1..000000000 --- a/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/CppResnetBuildDemo.vcxproj +++ /dev/null @@ -1,112 +0,0 @@ - - - - - ..\..\..\packages - - - - - - - - - - - - - - - - - - - - - - 17.0 - Win32Proj - {70987125-e3f7-43c0-8385-4a090ef9ef54} - CppResnetBuildDemo - 10.0 - None - - - - Application - v143 - Unicode - - - - - stdcpp20 - _CONSOLE%(PreprocessorDefinitions) - true - Level4 - - - Console - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/ResNet50Labels.txt b/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/ResNet50Labels.txt deleted file mode 100644 index 60d6558a9..000000000 --- a/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/ResNet50Labels.txt +++ /dev/null @@ -1,1000 +0,0 @@ -0,tench -1,goldfish -2,great white shark -3,tiger shark -4,hammerhead -5,electric ray -6,stingray -7,cock -8,hen -9,ostrich -10,brambling -11,goldfinch -12,house finch -13,junco -14,indigo bunting -15,robin -16,bulbul -17,jay -18,magpie -19,chickadee -20,water ouzel -21,kite -22,bald eagle -23,vulture -24,great grey owl -25,European fire salamander -26,common newt -27,eft -28,spotted salamander -29,axolotl -30,bullfrog -31,tree frog -32,tailed frog -33,loggerhead -34,leatherback turtle -35,mud turtle -36,terrapin -37,box turtle -38,banded gecko -39,common iguana -40,American chameleon -41,whiptail -42,agama -43,frilled lizard -44,alligator lizard -45,Gila monster -46,green lizard -47,African chameleon -48,Komodo dragon -49,African crocodile -50,American alligator -51,triceratops -52,thunder snake -53,ringneck snake -54,hognose snake -55,green snake -56,king snake -57,garter snake -58,water snake -59,vine snake -60,night snake -61,boa constrictor -62,rock python -63,Indian cobra -64,green mamba -65,sea snake -66,horned viper -67,diamondback -68,sidewinder -69,trilobite -70,harvestman -71,scorpion -72,black and gold garden spider -73,barn spider -74,garden spider -75,black widow -76,tarantula -77,wolf spider -78,tick -79,centipede -80,black grouse -81,ptarmigan -82,ruffed grouse -83,prairie chicken -84,peacock -85,quail -86,partridge -87,African grey -88,macaw -89,sulphur-crested cockatoo -90,lorikeet -91,coucal -92,bee eater -93,hornbill -94,hummingbird -95,jacamar -96,toucan -97,drake -98,red-breasted merganser -99,goose -100,black swan -101,tusker -102,echidna -103,platypus -104,wallaby -105,koala -106,wombat -107,jellyfish -108,sea anemone -109,brain coral -110,flatworm -111,nematode -112,conch -113,snail -114,slug -115,sea slug -116,chiton -117,chambered nautilus -118,Dungeness crab -119,rock crab -120,fiddler crab -121,king crab -122,American lobster -123,spiny lobster -124,crayfish -125,hermit crab -126,isopod -127,white stork -128,black stork -129,spoonbill -130,flamingo -131,little blue heron -132,American egret -133,bittern -134,crane -135,limpkin -136,European gallinule -137,American coot -138,bustard -139,ruddy turnstone -140,red-backed sandpiper -141,redshank -142,dowitcher -143,oystercatcher -144,pelican -145,king penguin -146,albatross -147,grey whale -148,killer whale -149,dugong -150,sea lion -151,Chihuahua -152,Japanese spaniel -153,Maltese dog -154,Pekinese -155,Shih-Tzu -156,Blenheim spaniel -157,papillon -158,toy terrier -159,Rhodesian ridgeback -160,Afghan hound -161,basset -162,beagle -163,bloodhound -164,bluetick -165,black-and-tan coonhound -166,Walker hound -167,English foxhound -168,redbone -169,borzoi -170,Irish wolfhound -171,Italian greyhound -172,whippet -173,Ibizan hound -174,Norwegian elkhound -175,otterhound -176,Saluki -177,Scottish deerhound -178,Weimaraner -179,Staffordshire bullterrier -180,American Staffordshire terrier -181,Bedlington terrier -182,Border terrier -183,Kerry blue terrier -184,Irish terrier -185,Norfolk terrier -186,Norwich terrier -187,Yorkshire terrier -188,wire-haired fox terrier -189,Lakeland terrier -190,Sealyham terrier -191,Airedale -192,cairn -193,Australian terrier -194,Dandie Dinmont -195,Boston bull -196,miniature schnauzer -197,giant schnauzer -198,standard schnauzer -199,Scotch terrier -200,Tibetan terrier -201,silky terrier -202,soft-coated wheaten terrier -203,West Highland white terrier -204,Lhasa -205,flat-coated retriever -206,curly-coated retriever -207,golden retriever -208,Labrador retriever -209,Chesapeake Bay retriever -210,German short-haired pointer -211,vizsla -212,English setter -213,Irish setter -214,Gordon setter -215,Brittany spaniel -216,clumber -217,English springer -218,Welsh springer spaniel -219,cocker spaniel -220,Sussex spaniel -221,Irish water spaniel -222,kuvasz -223,schipperke -224,groenendael -225,malinois -226,briard -227,kelpie -228,komondor -229,Old English sheepdog -230,Shetland sheepdog -231,collie -232,Border collie -233,Bouvier des Flandres -234,Rottweiler -235,German shepherd -236,Doberman -237,miniature pinscher -238,Greater Swiss Mountain dog -239,Bernese mountain dog -240,Appenzeller -241,EntleBucher -242,boxer -243,bull mastiff -244,Tibetan mastiff -245,French bulldog -246,Great Dane -247,Saint Bernard -248,Eskimo dog -249,malamute -250,Siberian husky -251,dalmatian -252,affenpinscher -253,basenji -254,pug -255,Leonberg -256,Newfoundland -257,Great Pyrenees -258,Samoyed -259,Pomeranian -260,chow -261,keeshond -262,Brabancon griffon -263,Pembroke -264,Cardigan -265,toy poodle -266,miniature poodle -267,standard poodle -268,Mexican hairless -269,timber wolf -270,white wolf -271,red wolf -272,coyote -273,dingo -274,dhole -275,African hunting dog -276,hyena -277,red fox -278,kit fox -279,Arctic fox -280,grey fox -281,tabby -282,tiger cat -283,Persian cat -284,Siamese cat -285,Egyptian cat -286,cougar -287,lynx -288,leopard -289,snow leopard -290,jaguar -291,lion -292,tiger -293,cheetah -294,brown bear -295,American black bear -296,ice bear -297,sloth bear -298,mongoose -299,meerkat -300,tiger beetle -301,ladybug -302,ground beetle -303,long-horned beetle -304,leaf beetle -305,dung beetle -306,rhinoceros beetle -307,weevil -308,fly -309,bee -310,ant -311,grasshopper -312,cricket -313,walking stick -314,cockroach -315,mantis -316,cicada -317,leafhopper -318,lacewing -319,dragonfly -320,damselfly -321,admiral -322,ringlet -323,monarch -324,cabbage butterfly -325,sulphur butterfly -326,lycaenid -327,starfish -328,sea urchin -329,sea cucumber -330,wood rabbit -331,hare -332,Angora -333,hamster -334,porcupine -335,fox squirrel -336,marmot -337,beaver -338,guinea pig -339,sorrel -340,zebra -341,hog -342,wild boar -343,warthog -344,hippopotamus -345,ox -346,water buffalo -347,bison -348,ram -349,bighorn -350,ibex -351,hartebeest -352,impala -353,gazelle -354,Arabian camel -355,llama -356,weasel -357,mink -358,polecat -359,black-footed ferret -360,otter -361,skunk -362,badger -363,armadillo -364,three-toed sloth -365,orangutan -366,gorilla -367,chimpanzee -368,gibbon -369,siamang -370,guenon -371,patas -372,baboon -373,macaque -374,langur -375,colobus -376,proboscis monkey -377,marmoset -378,capuchin -379,howler monkey -380,titi -381,spider monkey -382,squirrel monkey -383,Madagascar cat -384,indri -385,Indian elephant -386,African elephant -387,lesser panda -388,giant panda -389,barracouta -390,eel -391,coho -392,rock beauty -393,anemone fish -394,sturgeon -395,gar -396,lionfish -397,puffer -398,abacus -399,abaya -400,academic gown -401,accordion -402,acoustic guitar -403,aircraft carrier -404,airliner -405,airship -406,altar -407,ambulance -408,amphibian -409,analog clock -410,apiary -411,apron -412,ashcan -413,assault rifle -414,backpack -415,bakery -416,balance beam -417,balloon -418,ballpoint -419,Band Aid -420,banjo -421,bannister -422,barbell -423,barber chair -424,barbershop -425,barn -426,barometer -427,barrel -428,barrow -429,baseball -430,basketball -431,bassinet -432,bassoon -433,bathing cap -434,bath towel -435,bathtub -436,beach wagon -437,beacon -438,beaker -439,bearskin -440,beer bottle -441,beer glass -442,bell cote -443,bib -444,bicycle-built-for-two -445,bikini -446,binder -447,binoculars -448,birdhouse -449,boathouse -450,bobsled -451,bolo tie -452,bonnet -453,bookcase -454,bookshop -455,bottlecap -456,bow -457,bow tie -458,brass -459,brassiere -460,breakwater -461,breastplate -462,broom -463,bucket -464,buckle -465,bulletproof vest -466,bullet train -467,butcher shop -468,cab -469,caldron -470,candle -471,cannon -472,canoe -473,can opener -474,cardigan -475,car mirror -476,carousel -477,carpenter's kit -478,carton -479,car wheel -480,cash machine -481,cassette -482,cassette player -483,castle -484,catamaran -485,CD player -486,cello -487,cellular telephone -488,chain -489,chainlink fence -490,chain mail -491,chain saw -492,chest -493,chiffonier -494,chime -495,china cabinet -496,Christmas stocking -497,church -498,cinema -499,cleaver -500,cliff dwelling -501,cloak -502,clog -503,cocktail shaker -504,coffee mug -505,coffeepot -506,coil -507,combination lock -508,computer keyboard -509,confectionery -510,container ship -511,convertible -512,corkscrew -513,cornet -514,cowboy boot -515,cowboy hat -516,cradle -517,crane -518,crash helmet -519,crate -520,crib -521,Crock Pot -522,croquet ball -523,crutch -524,cuirass -525,dam -526,desk -527,desktop computer -528,dial telephone -529,diaper -530,digital clock -531,digital watch -532,dining table -533,dishrag -534,dishwasher -535,disk brake -536,dock -537,dogsled -538,dome -539,doormat -540,drilling platform -541,drum -542,drumstick -543,dumbbell -544,Dutch oven -545,electric fan -546,electric guitar -547,electric locomotive -548,entertainment center -549,envelope -550,espresso maker -551,face powder -552,feather boa -553,file -554,fireboat -555,fire engine -556,fire screen -557,flagpole -558,flute -559,folding chair -560,football helmet -561,forklift -562,fountain -563,fountain pen -564,four-poster -565,freight car -566,French horn -567,frying pan -568,fur coat -569,garbage truck -570,gasmask -571,gas pump -572,goblet -573,go-kart -574,golf ball -575,golfcart -576,gondola -577,gong -578,gown -579,grand piano -580,greenhouse -581,grille -582,grocery store -583,guillotine -584,hair slide -585,hair spray -586,half track -587,hammer -588,hamper -589,hand blower -590,hand-held computer -591,handkerchief -592,hard disc -593,harmonica -594,harp -595,harvester -596,hatchet -597,holster -598,home theater -599,honeycomb -600,hook -601,hoopskirt -602,horizontal bar -603,horse cart -604,hourglass -605,iPod -606,iron -607,jack-o'-lantern -608,jean -609,jeep -610,jersey -611,jigsaw puzzle -612,jinrikisha -613,joystick -614,kimono -615,knee pad -616,knot -617,lab coat -618,ladle -619,lampshade -620,laptop -621,lawn mower -622,lens cap -623,letter opener -624,library -625,lifeboat -626,lighter -627,limousine -628,liner -629,lipstick -630,Loafer -631,lotion -632,loudspeaker -633,loupe -634,lumbermill -635,magnetic compass -636,mailbag -637,mailbox -638,maillot -639,maillot -640,manhole cover -641,maraca -642,marimba -643,mask -644,matchstick -645,maypole -646,maze -647,measuring cup -648,medicine chest -649,megalith -650,microphone -651,microwave -652,military uniform -653,milk can -654,minibus -655,miniskirt -656,minivan -657,missile -658,mitten -659,mixing bowl -660,mobile home -661,Model T -662,modem -663,monastery -664,monitor -665,moped -666,mortar -667,mortarboard -668,mosque -669,mosquito net -670,motor scooter -671,mountain bike -672,mountain tent -673,mouse -674,mousetrap -675,moving van -676,muzzle -677,nail -678,neck brace -679,necklace -680,nipple -681,notebook -682,obelisk -683,oboe -684,ocarina -685,odometer -686,oil filter -687,organ -688,oscilloscope -689,overskirt -690,oxcart -691,oxygen mask -692,packet -693,paddle -694,paddlewheel -695,padlock -696,paintbrush -697,pajama -698,palace -699,panpipe -700,paper towel -701,parachute -702,parallel bars -703,park bench -704,parking meter -705,passenger car -706,patio -707,pay-phone -708,pedestal -709,pencil box -710,pencil sharpener -711,perfume -712,Petri dish -713,photocopier -714,pick -715,pickelhaube -716,picket fence -717,pickup -718,pier -719,piggy bank -720,pill bottle -721,pillow -722,ping-pong ball -723,pinwheel -724,pirate -725,pitcher -726,plane -727,planetarium -728,plastic bag -729,plate rack -730,plow -731,plunger -732,Polaroid camera -733,pole -734,police van -735,poncho -736,pool table -737,pop bottle -738,pot -739,potter's wheel -740,power drill -741,prayer rug -742,printer -743,prison -744,projectile -745,projector -746,puck -747,punching bag -748,purse -749,quill -750,quilt -751,racer -752,racket -753,radiator -754,radio -755,radio telescope -756,rain barrel -757,recreational vehicle -758,reel -759,reflex camera -760,refrigerator -761,remote control -762,restaurant -763,revolver -764,rifle -765,rocking chair -766,rotisserie -767,rubber eraser -768,rugby ball -769,rule -770,running shoe -771,safe -772,safety pin -773,saltshaker -774,sandal -775,sarong -776,sax -777,scabbard -778,scale -779,school bus -780,schooner -781,scoreboard -782,screen -783,screw -784,screwdriver -785,seat belt -786,sewing machine -787,shield -788,shoe shop -789,shoji -790,shopping basket -791,shopping cart -792,shovel -793,shower cap -794,shower curtain -795,ski -796,ski mask -797,sleeping bag -798,slide rule -799,sliding door -800,slot -801,snorkel -802,snowmobile -803,snowplow -804,soap dispenser -805,soccer ball -806,sock -807,solar dish -808,sombrero -809,soup bowl -810,space bar -811,space heater -812,space shuttle -813,spatula -814,speedboat -815,spider web -816,spindle -817,sports car -818,spotlight -819,stage -820,steam locomotive -821,steel arch bridge -822,steel drum -823,stethoscope -824,stole -825,stone wall -826,stopwatch -827,stove -828,strainer -829,streetcar -830,stretcher -831,studio couch -832,stupa -833,submarine -834,suit -835,sundial -836,sunglass -837,sunglasses -838,sunscreen -839,suspension bridge -840,swab -841,sweatshirt -842,swimming trunks -843,swing -844,switch -845,syringe -846,table lamp -847,tank -848,tape player -849,teapot -850,teddy -851,television -852,tennis ball -853,thatch -854,theater curtain -855,thimble -856,thresher -857,throne -858,tile roof -859,toaster -860,tobacco shop -861,toilet seat -862,torch -863,totem pole -864,tow truck -865,toyshop -866,tractor -867,trailer truck -868,tray -869,trench coat -870,tricycle -871,trimaran -872,tripod -873,triumphal arch -874,trolleybus -875,trombone -876,tub -877,turnstile -878,typewriter keyboard -879,umbrella -880,unicycle -881,upright -882,vacuum -883,vase -884,vault -885,velvet -886,vending machine -887,vestment -888,viaduct -889,violin -890,volleyball -891,waffle iron -892,wall clock -893,wallet -894,wardrobe -895,warplane -896,washbasin -897,washer -898,water bottle -899,water jug -900,water tower -901,whiskey jug -902,whistle -903,wig -904,window screen -905,window shade -906,Windsor tie -907,wine bottle -908,wing -909,wok -910,wooden spoon -911,wool -912,worm fence -913,wreck -914,yawl -915,yurt -916,web site -917,comic book -918,crossword puzzle -919,street sign -920,traffic light -921,book jacket -922,menu -923,plate -924,guacamole -925,consomme -926,hot pot -927,trifle -928,ice cream -929,ice lolly -930,French loaf -931,bagel -932,pretzel -933,cheeseburger -934,hotdog -935,mashed potato -936,head cabbage -937,broccoli -938,cauliflower -939,zucchini -940,spaghetti squash -941,acorn squash -942,butternut squash -943,cucumber -944,artichoke -945,bell pepper -946,cardoon -947,mushroom -948,Granny Smith -949,strawberry -950,orange -951,lemon -952,fig -953,pineapple -954,banana -955,jackfruit -956,custard apple -957,pomegranate -958,hay -959,carbonara -960,chocolate sauce -961,dough -962,meat loaf -963,pizza -964,potpie -965,burrito -966,red wine -967,espresso -968,cup -969,eggnog -970,alp -971,bubble -972,cliff -973,coral reef -974,geyser -975,lakeside -976,promontory -977,sandbar -978,seashore -979,valley -980,volcano -981,ballplayer -982,groom -983,scuba diver -984,rapeseed -985,daisy -986,yellow lady's slipper -987,corn -988,acorn -989,hip -990,buckeye -991,coral fungus -992,agaric -993,gyromitra -994,stinkhorn -995,earthstar -996,hen-of-the-woods -997,bolete -998,ear -999,toilet tissue diff --git a/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/ResnetModelHelper.cpp b/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/ResnetModelHelper.cpp deleted file mode 100644 index 0c5d2760b..000000000 --- a/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/ResnetModelHelper.cpp +++ /dev/null @@ -1,255 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE.md in the repo root for license information. -#include "ResnetModelHelper.hpp" - -// clang-format off -#include -#include -// clang-format on - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace winrt::Windows::Foundation::Collections; -using namespace winrt::Windows::Graphics::Imaging; -using namespace winrt::Windows::Media; -using namespace winrt::Windows::Storage::Streams; -using namespace winrt::Windows::Storage; -using winrt::Windows::Foundation::IAsyncOperation; -using winrt::Windows::Foundation::IMemoryBufferReference; - -namespace ResnetModelHelper -{ -std::filesystem::path GetExecutablePath() -{ - auto filePath = wil::GetModuleFileNameW(); - std::filesystem::path fil{filePath.get()}; - return fil; -} - -IAsyncOperation LoadImageFileAsync(winrt::hstring filePath) -{ - StorageFile file = co_await StorageFile::GetFileFromPathAsync(filePath); - auto stream = co_await file.OpenAsync(FileAccessMode::Read); - BitmapDecoder decoder = co_await BitmapDecoder::CreateAsync(stream); - SoftwareBitmap softwareBitmap = co_await decoder.GetSoftwareBitmapAsync(); - - co_return softwareBitmap; -} - -std::vector BindSoftwareBitmapAsTensor(SoftwareBitmap const& bitmap) -{ - SoftwareBitmap bitmapBgra8 = SoftwareBitmap::Convert(bitmap, BitmapPixelFormat::Bgra8, BitmapAlphaMode::Ignore); - - winrt::Windows::Storage::Streams::InMemoryRandomAccessStream stream = InMemoryRandomAccessStream(); - - BitmapEncoder encoder = BitmapEncoder::CreateAsync(BitmapEncoder::BmpEncoderId(), stream).get(); - encoder.SetSoftwareBitmap(bitmapBgra8); - encoder.BitmapTransform().ScaledWidth(224); - encoder.BitmapTransform().ScaledHeight(224); - encoder.BitmapTransform().InterpolationMode(BitmapInterpolationMode::Fant); - encoder.FlushAsync().get(); - - stream.Seek(0); - BitmapDecoder decoder = BitmapDecoder::CreateAsync(stream).get(); - SoftwareBitmap resizedBitmap = decoder.GetSoftwareBitmapAsync(BitmapPixelFormat::Bgra8, BitmapAlphaMode::Ignore).get(); - - BitmapBuffer bitmapBuffer = resizedBitmap.LockBuffer(BitmapBufferAccessMode::Read); - - IMemoryBufferReference reference = bitmapBuffer.CreateReference(); - - auto spByteAccess = reference.as<::Windows::Foundation::IMemoryBufferByteAccess>(); - uint8_t* pixelData = nullptr; - uint32_t pixelDataCapacity = 0; - - spByteAccess->GetBuffer(&pixelData, &pixelDataCapacity); - - const int64_t channels = 3; // RGB - const int64_t height = 224; - const int64_t width = 224; - - std::vector tensorShape = {1, channels, height, width}; - std::vector tensorData(channels * height * width); - - for (int y = 0; y < height; ++y) - { - for (int x = 0; x < width; ++x) - { - int idx = (y * width + x) * 4; // BGRA stride - int offset = y * width + x; - - // Normalize using mean=[0.485, 0.456, 0.406] and std=[0.229, 0.224, 0.225] - float r = static_cast(pixelData[idx + 2]) / 255.0f; - float g = static_cast(pixelData[idx + 1]) / 255.0f; - float b = static_cast(pixelData[idx + 0]) / 255.0f; - - tensorData[0 * height * width + offset] = (r - 0.485f) / 0.229f; - tensorData[1 * height * width + offset] = (g - 0.456f) / 0.224f; - tensorData[2 * height * width + offset] = (b - 0.406f) / 0.225f; - } - } - return tensorData; -} - -std::vector LoadLabels(const std::filesystem::path& labelsPath) -{ - std::ifstream labelFile{labelsPath, std::ifstream::in}; - if (labelFile.fail()) - { - throw std::runtime_error("Unable to load file."); - } - - std::vector labels; - for (std::string line; std::getline(labelFile, line);) - { - labels.push_back(line); - } - - return labels; -} - -std::vector Softmax(const std::vector& logits) -{ - std::vector exps(logits.size()); - float maxLogit = *std::max_element(logits.begin(), logits.end()); - - float sum = 0.0f; - for (size_t i = 0; i < logits.size(); ++i) - { - exps[i] = std::exp(logits[i] - maxLogit); // stability trick - sum += exps[i]; - } - - for (float& val : exps) - { - val /= sum; - } - - return exps; -} - -/* Simple IEEE 754 half-precision (float16) conversion utility in C/C++. Can be replaced with half.hpp or other FP16 - * libraries if available. */ -uint16_t Float32ToFloat16(float value) -{ - uint32_t asInt; - memcpy(&asInt, &value, sizeof(value)); - - uint32_t sign = (asInt >> 16) & 0x8000; - uint32_t exponent = ((asInt >> 23) & 0xFF) - 127 + 15; - uint32_t mantissa = asInt & 0x007FFFFF; - - if (exponent <= 0) - { - return static_cast(sign); - } - else if (exponent >= 31) - { - return static_cast(sign | 0x7C00); // INF - } - - uint16_t half = static_cast(sign | (exponent << 10) | (mantissa >> 13)); - return half; -} - -std::vector ConvertFloat32ToFloat16(const std::vector& float32Data) -{ - std::vector float16Data(float32Data.size()); - for (size_t i = 0; i < float32Data.size(); ++i) - { - float16Data[i] = Float32ToFloat16(float32Data[i]); - } - return float16Data; -} - -float Float16ToFloat32(uint16_t value) -{ - uint32_t sign = (value >> 15) & 0x1; - uint32_t exponent = (value >> 10) & 0x1F; - uint32_t mantissa = value & 0x3FF; - - if (exponent == 0) - { - return static_cast((sign ? -1 : 1) * 0.0f); - } - else if (exponent == 31) - { - return (sign ? -1 : 1) * (mantissa == 0 ? std::numeric_limits::infinity() : std::nanf("")); - } - - exponent = exponent + (127 - 15); // Bias correction - mantissa = mantissa << 13; // Shift mantissa to float position - - uint32_t result = (sign << 31) | (exponent << 23) | mantissa; - return *reinterpret_cast(&result); -} - -std::vector ConvertFloat16ToFloat32(const std::vector& float16Data) -{ - std::vector float32Data(float16Data.size()); - for (size_t i = 0; i < float16Data.size(); ++i) - { - float32Data[i] = Float16ToFloat32(float16Data[i]); - } - return float32Data; -} - -void PrintResults(const std::vector& labels, const std::vector& results) -{ - // Apply softmax to the results - float maxLogit = *std::max_element(results.begin(), results.end()); - std::vector expScores; - float sumExp = 0.0f; - - for (float r : results) - { - float expScore = std::exp(r - maxLogit); - expScores.push_back(expScore); - sumExp += expScore; - } - - std::vector softmaxResults; - for (float e : expScores) - { - softmaxResults.push_back(e / sumExp); - } - - // Get top 5 results - std::vector> indexedResults; - for (size_t i = 0; i < softmaxResults.size(); ++i) - { - indexedResults.emplace_back(static_cast(i), softmaxResults[i]); - } - - std::sort(indexedResults.begin(), indexedResults.end(), [](const auto& a, const auto& b) { - return a.second > b.second; - }); - - indexedResults.resize(std::min(5, indexedResults.size())); - - // Display results - std::cout << "Top Predictions:\n"; - std::cout << "-------------------------------------------\n"; - std::cout << std::left << std::setw(32) << "Label" << std::right << std::setw(10) << "Confidence\n"; - std::cout << "-------------------------------------------\n"; - - for (const auto& result : indexedResults) - { - std::cout << std::left << std::setw(32) << labels[result.first] << std::right << std::setw(10) << std::fixed - << std::setprecision(2) << (result.second * 100) << "%\n"; - } - - std::cout << "-------------------------------------------\n"; -} - -} // namespace ResnetModelHelper diff --git a/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/ResnetModelHelper.hpp b/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/ResnetModelHelper.hpp deleted file mode 100644 index df000c4ac..000000000 --- a/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/ResnetModelHelper.hpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE.md in the repo root for license information. -#include -#include -#include -#include -#include -#include -#include -#include - -namespace ResnetModelHelper -{ -std::filesystem::path GetExecutablePath(); - -winrt::Windows::Foundation::IAsyncOperation LoadImageFileAsync(winrt::hstring filePath); - -std::vector BindSoftwareBitmapAsTensor(const winrt::Windows::Graphics::Imaging::SoftwareBitmap& bitmap); - -std::vector LoadLabels(const std::filesystem::path& labelsPath); - -std::vector Softmax(const std::vector& logits); - -std::vector ConvertFloat32ToFloat16(const std::vector& float32Data); - -std::vector ConvertFloat16ToFloat32(const std::vector& float16Data); - -void PrintResults(const std::vector& labels, const std::vector& results); -} // namespace ResnetModelHelper diff --git a/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/dog.jpg b/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/dog.jpg deleted file mode 100644 index 3a20c37d3..000000000 Binary files a/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/dog.jpg and /dev/null differ diff --git a/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/packages.config b/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/packages.config deleted file mode 100644 index 630b607bf..000000000 --- a/Samples/WindowsML/cpp/CppResnetBuildDemo/CppResnetBuildDemo/packages.config +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Samples/WindowsML/cpp/CppResnetBuildDemo/README.md b/Samples/WindowsML/cpp/CppResnetBuildDemo/README.md deleted file mode 100644 index 1b02eaf19..000000000 --- a/Samples/WindowsML/cpp/CppResnetBuildDemo/README.md +++ /dev/null @@ -1,187 +0,0 @@ -# Windows ML walkthrough (C++) - -This short tutorial walks through using Windows ML to run the ResNet-50 image classification model on Windows using C++, detailing model acquisition and preprocessing steps. The implementation involves dynamically selecting execution providers for optimized inference performance. - -The ResNet-50 model is a PyTorch model intended for image classification. - -In this tutorial, you'll acquire the ResNet-50 model and convert it to QDQ ONNX format by using the AI Toolkit. - -Then you'll load the model, prepare input tensors, and run inference using the Windows ML APIs with C++, including post-processing steps to apply softmax, and retrieve the top predictions. - -## Acquiring the model, and preprocessing - -You can acquire [ResNet-50](https://huggingface.co/microsoft/resnet-50) and convert ResNet-50 to QDQ ONNX format by using the AI Toolkit (see [convert models to ONNX format](https://code.visualstudio.com/docs/intelligentapps/modelconversion) for more info). - -The goal of this example code is to leverage the Windows ML runtime to do the heavy lifting. - -The Windows ML runtime will: - -* Load the model. -* Dynamically select the preferred IHV-provided execution provider (EP) for the model and download its EP from the Microsoft Store, on demand. -* Run inference on the model using the EP. - -For API reference, see [**OrtCompileApi struct**](https://onnxruntime.ai/docs/api/c/struct_ort_api.html), [**OrtSessionOptions**](https://onnxruntime.ai/docs/api/c/group___global.html#gaa6c56bcb36e39611481a17065d3ce620), [**Microsoft::Windows::AI::MachineLearning::Infrastructure class**](./api-reference.md#infrastructure-class), and [**Ort::GetApi**](https://onnxruntime.ai/docs/api/c/namespace_ort.html#a296b5958479d9889218b17bdb08c1894). - -```cpp -#include -#include - -// Create ONNX Runtime environment -auto env = Ort::Env(); - -// Use WinML to download and register Execution Providers -auto catalog = winrt::Microsoft::Windows::AI::MachineLearning::ExecutionProviderCatalog::GetDefault(); -auto providers = catalog.FindAllProviders(); -for (const auto& provider : providers) -{ - provider.EnsureReadyAsync().get(); - provider.TryRegister(); -} - -// Set the auto EP selection policy -Ort::SessionOptions sessionOptions; -sessionOptions.SetEpSelectionPolicy(OrtExecutionProviderDevicePolicy_MIN_OVERALL_POWER); -``` - -### EP compilation - -If your model isn't already compiled for the EP (which may vary depending on device), the model might need to be compiled against that EP. This is a one-time process. The example code below handles it by compiling the model on the first run, and then storing it locally. Subsequent runs of the code pick up the compiled version, and run that; resulting in optimized fast inferences. - -For API reference, see [**Ort::ModelCompilationOptions struct**](https://onnxruntime.ai/docs/api/c/struct_ort_1_1_model_compilation_options.html), [**Ort::Status struct**](https://onnxruntime.ai/docs/api/c/struct_ort_1_1_status.html), and [**Ort::CompileModel**](https://onnxruntime.ai/docs/api/c/namespace_ort.html#af5ec45452237ac4ab98dd7a11b9d678e). - -```cpp -// Compile the model if not already compiled -std::filesystem::path compiledModelPath = L"compiled_model\\model.onnx"; -bool isCompiledModelAvailable = std::filesystem::exists(compiledModelPath); - -if (!isCompiledModelAvailable) -{ - Ort::ModelCompilationOptions compile_options(env, sessionOptions); - compile_options.SetInputModelPath(modelPath.c_str()); - compile_options.SetOutputModelPath(compiledModelPath.c_str()); - - Ort::Status compileStatus = Ort::CompileModel(env, compile_options); - if (compileStatus.IsOK()) - { - isCompiledModelAvailable = std::filesystem::exists(compiledModelPath); - } -} - -std::filesystem::path modelPathToUse = isCompiledModelAvailable ? compiledModelPath : modelPath; -``` - -## Running the inference - -The input image is converted to tensor data format, and then inference runs on it. While this is typical of all code that uses the ONNX Runtime, the difference in this case is that it's ONNX Runtime directly through Windows ML. The only requirement is adding `#include ` to the code. - -Also see [Convert a model with AI Toolkit for VS Code](https://code.visualstudio.com/docs/intelligentapps/modelconversion) - -For API reference, see [**Ort::Session struct**](https://onnxruntime.ai/docs/api/c/struct_ort_1_1_session.html), [**Ort::MemoryInfo struct**](https://onnxruntime.ai/docs/api/c/struct_ort_1_1_memory_info.html), [**Ort::Value struct**](https://onnxruntime.ai/docs/api/c/struct_ort_1_1_value.html), [**Ort::AllocatorWithDefaultOptions struct**](https://onnxruntime.ai/docs/api/c/struct_ort_1_1_allocator_with_default_options.html), [**Ort::RunOptions struct**](https://onnxruntime.ai/docs/api/c/struct_ort_1_1_run_options.html). - -```cpp -// Create the session and load the model -Ort::Session session(env, modelPathToUse.c_str(), sessionOptions); - -// Load and preprocess image -auto imageFrameResult = ResnetModelHelper::LoadImageFileAsync(imagePath); -auto inputTensorData = ResnetModelHelper::BindSoftwareBitmapAsTensor(imageFrameResult.get()); - -// Create input tensor (handle both float32 and float16 models) -auto inputType = session.GetInputTypeInfo(0).GetTensorTypeAndShapeInfo().GetElementType(); -auto inputShape = std::array{1, 3, 224, 224}; -// ... convert tensor data based on model type and create OrtValue ... -Ort::Value inputTensor{ortValue}; - -// Run inference -auto inputName = session.GetInputNameAllocated(0, allocator); -auto outputName = session.GetOutputNameAllocated(0, allocator); -auto outputTensors = session.Run(Ort::RunOptions{nullptr}, inputNames.data(), &inputTensor, 1, outputNames.data(), 1); - -// Extract results (handle float16/float32 conversion if needed) -std::vector results; -// ... extract and convert output tensor data ... - -// Load labels and print results -auto labels = ResnetModelHelper::LoadLabels(labelsPath); -ResnetModelHelper::PrintResults(labels, results); -``` - -### Image preprocessing - -The C++ implementation includes comprehensive image preprocessing that handles image loading, resizing, and normalization: - -```cpp -std::vector BindSoftwareBitmapAsTensor(SoftwareBitmap const& bitmap) -{ - // Convert to BGRA8 format and resize to 224x224 - SoftwareBitmap bitmapBgra8 = SoftwareBitmap::Convert(bitmap, BitmapPixelFormat::Bgra8, BitmapAlphaMode::Ignore); - // ... use BitmapEncoder/Decoder to resize with high-quality interpolation ... - - // Extract pixel data and normalize using ImageNet parameters - // ... get pixel buffer access ... - uint8_t* pixelData = /* ... */; - - std::vector tensorData(3 * 224 * 224); - for (int y = 0; y < 224; ++y) - { - for (int x = 0; x < 224; ++x) - { - // Extract BGR values and normalize with ImageNet mean/std - float r = static_cast(pixelData[idx + 2]) / 255.0f; - float g = static_cast(pixelData[idx + 1]) / 255.0f; - float b = static_cast(pixelData[idx + 0]) / 255.0f; - - tensorData[0 * 224 * 224 + offset] = (r - 0.485f) / 0.229f; - tensorData[1 * 224 * 224 + offset] = (g - 0.456f) / 0.224f; - tensorData[2 * 224 * 224 + offset] = (b - 0.406f) / 0.225f; - } - } - return tensorData; -} -``` - -### Post-processing - -The softmax function is applied to returned raw output, and label data is used to map and print the names with the five highest probabilities. - -```cpp -void PrintResults(const std::vector& labels, const std::vector& results) -{ - // Apply softmax with numerical stability - float maxLogit = *std::max_element(results.begin(), results.end()); - std::vector softmaxResults; - // ... compute exp(logit - maxLogit) and normalize ... - - // Get top 5 results and sort by confidence - std::vector> indexedResults; - // ... create index-value pairs and sort descending ... - - // Display formatted results - std::cout << "Top Predictions:\n-------------------------------------------\n"; - std::cout << std::left << std::setw(32) << "Label" << std::right << std::setw(10) << "Confidence\n"; - std::cout << "-------------------------------------------\n"; - - for (const auto& result : indexedResults) - { - std::cout << std::left << std::setw(32) << labels[result.first] << std::right << std::setw(10) - << std::fixed << std::setprecision(2) << (result.second * 100) << "%\n"; - } - std::cout << "-------------------------------------------\n"; -} -``` - -### Output - -Here's an example of the kind of output to be expected. - -```console -------------------------------------------- -Label Confidence -------------------------------------------- -French bulldog 45.07% -bull mastiff 35.05% -boxer 2.85% -pug 1.01% -American Staffordshire terrier 0.57% -------------------------------------------- -``` diff --git a/Samples/WindowsML/cpp/Directory.Build.props b/Samples/WindowsML/cpp/Directory.Build.props index 365120f7e..e05a9f738 100644 --- a/Samples/WindowsML/cpp/Directory.Build.props +++ b/Samples/WindowsML/cpp/Directory.Build.props @@ -22,16 +22,17 @@ - 1.8.251106002 - 1.8.251105000 - 1.8.250831001 - 1.8.251104000 - 1.8.251104001 - 1.8.25090401 - 1.8.250904007 - 1.8.39 - 1.8.2109 - 1.8.251106002 + 2.1.3 + 2.1.0 + 2.0.4 + 2.0.21 + 2.0.13 + 2.1.0 + 2.0.5 + 2.1.10 + 2.1.1 + 2.1.3 + 2.1.1 2.0.240405.15 10.0.26100.4654 1.0.3179.45 diff --git a/Samples/WindowsML/cs/CSharpConsoleDesktop/README.md b/Samples/WindowsML/cs/CSharpConsoleDesktop/README.md index 08f2dc7a6..7ff767fa3 100644 --- a/Samples/WindowsML/cs/CSharpConsoleDesktop/README.md +++ b/Samples/WindowsML/cs/CSharpConsoleDesktop/README.md @@ -11,12 +11,16 @@ This sample demonstrates how to use ONNX Runtime in a C# desktop application, fo ```shell CSharpConsoleDesktop.exe [options] Options: - --ep_policy Set execution provider policy (NPU, CPU, GPU, DEFAULT). Default: DEFAULT - --compile Compile the model - --download Download required packages - --model Path to input ONNX model (default: SqueezeNet.onnx in executable directory) - --compiled_output Path for compiled output model (default: auto-generated with device info) - --image_path Path to the input image (default: sample kitten image) + --ep_policy (Required*) Set execution provider selection policy (NPU, CPU, GPU, DEFAULT) + --ep_name (Required*) Explicit execution provider name (mutually exclusive with --ep_policy) + --compile Compile the model + --download Download required packages + --model Path to input ONNX model (default: SqueezeNet.onnx in executable directory) + --compiled_output Path for compiled output model (default: auto-generated with device info) + --image_path Path to the input image (default: sample kitten image) + +Exactly one of --ep_policy or --ep_name must be specified. +--use_model_catalog and --model are mutually exclusive. ``` ## Key Features diff --git a/Samples/WindowsML/cs/ResnetBuildDemoCS/README.md b/Samples/WindowsML/cs/ResnetBuildDemoCS/README.md deleted file mode 100644 index 81e555135..000000000 --- a/Samples/WindowsML/cs/ResnetBuildDemoCS/README.md +++ /dev/null @@ -1,174 +0,0 @@ -# Windows ML walkthrough - -This short tutorial walks through using Windows ML to run the ResNet-50 image classification model on Windows, detailing model acquisition and preprocessing steps. The implementation involves dynamically selecting execution providers for optimized inference performance. - -The ResNet-50 model is a PyTorch model intended for image classification. - -In this tutorial, you'll acquire the ResNet-50 model and convert it to QDQ ONNX format by using the AI Toolkit. - -Then you'll load the model, prepare input tensors, and run inference using the Windows ML APIs, including post-processing steps to apply softmax, and retrieve the top predictions. - -## Acquiring the model, and preprocessing - -You can acquire [ResNet-50](https://huggingface.co/microsoft/resnet-50) and convert ResNet-50 to QDQ ONNX format by using the AI Toolkit (see [convert models to ONNX format](https://code.visualstudio.com/docs/intelligentapps/modelconversion) for more info). - -The goal of this example code is to leverage the Windows ML runtime to do the heavy lifting. - -The Windows ML runtime will: -* Load the model. -* Dynamically select the preferred IHV-provided execution provider (EP) for the model and download its EP from the Microsoft Store, on demand. -* Run inference on the model using the EP. - -For API reference, see [**OrtCompileApi struct**](https://onnxruntime.ai/docs/api/c/struct_ort_api.html), [**OrtSessionOptions**](https://onnxruntime.ai/docs/api/c/group___global.html#gaa6c56bcb36e39611481a17065d3ce620), [**Microsoft::Windows::AI::MachineLearning::Infrastructure class**](./api-reference.md#infrastructure-class), and [**Ort::GetApi**](https://onnxruntime.ai/docs/api/c/namespace_ort.html#a296b5958479d9889218b17bdb08c1894). - -```csharp -// Create a new instance of EnvironmentCreationOptions -EnvironmentCreationOptions envOptions = new() -{ - logId = "ResnetBuildDemo", - logLevel = OrtLoggingLevel.ORT_LOGGING_LEVEL_ERROR -}; - -// Pass the options by reference to CreateInstanceWithOptions -OrtEnv ortEnv = OrtEnv.CreateInstanceWithOptions(ref envOptions); - -// Use WinML to download and register Execution Providers -var catalog = ExecutionProviderCatalog.GetDefault(); -var registeredProviders = await catalog.EnsureAndRegisterAllAsync(); - -//Create Onnx session -Console.WriteLine("Creating session ..."); -var sessionOptions = new SessionOptions(); -// Set EP Selection Policy -sessionOptions.SetEpSelectionPolicy(ExecutionProviderDevicePolicy.MIN_OVERALL_POWER); -``` - -### EP compilation - -If your model isn't already compiled for the EP (which may vary depending on device), the model might need to be compiled against that EP. This is a one-time process. The example code below handles it by compiling the model on the first run, and then storing it locally. Subsequent runs of the code pick up the compiled version, and run that; resulting in optimized fast inferences. - -For API reference, see [**Ort::ModelCompilationOptions struct**](https://onnxruntime.ai/docs/api/c/struct_ort_1_1_model_compilation_options.html), [**Ort::Status struct**](https://onnxruntime.ai/docs/api/c/struct_ort_1_1_status.html), and [**Ort::CompileModel**](https://onnxruntime.ai/docs/api/c/namespace_ort.html#af5ec45452237ac4ab98dd7a11b9d678e). - -```csharp -// Compile the model if not already compiled -string compiledModelPath = @"C:\Build\compiled_model\model.onnx"; -bool isCompiled = File.Exists(compiledModelPath); -if (!isCompiled) -{ - Console.WriteLine("No compiled model found. Compiling model ..."); - using (var compileOptions = new OrtModelCompilationOptions(sessionOptions)) - { - compileOptions.SetInputModelPath(modelPath); - compileOptions.SetOutputModelPath(compiledModelPath); - compileOptions.CompileModel(); - isCompiled = File.Exists(compiledModelPath); - if (isCompiled) - { - Console.WriteLine("Model compiled successfully!"); - } - else - { - Console.WriteLine("Failed to compile the model. Will use original model."); - } - } -} -else -{ - Console.WriteLine("Found precompiled model."); -} -var modelPathToUse = isCompiled ? compiledModelPath : modelPath; -``` - -## Running the inference - -The input image is converted to tensor data format, and then inference runs on it. While this is typical of all code that uses the ONNX Runtime, the difference in this case is that it's ONNX Runtime directly through Windows ML. The only requirement is adding `#include ` to the code. - -Also see [Convert a model with AI Toolkit for VS Code](https://code.visualstudio.com/docs/intelligentapps/modelconversion) - -For API reference, see [**Ort::Session struct**](https://onnxruntime.ai/docs/api/c/struct_ort_1_1_session.html), [**Ort::MemoryInfo struct**](https://onnxruntime.ai/docs/api/c/struct_ort_1_1_memory_info.html), [**Ort::Value struct**](https://onnxruntime.ai/docs/api/c/struct_ort_1_1_value.html), [**Ort::AllocatorWithDefaultOptions struct**](https://onnxruntime.ai/docs/api/c/struct_ort_1_1_allocator_with_default_options.html), [**Ort::RunOptions struct**](https://onnxruntime.ai/docs/api/c/struct_ort_1_1_run_options.html). - -```csharp -using var session = new InferenceSession(modelPathToUse, sessionOptions); - -Console.WriteLine("Preparing input ..."); -// Load and preprocess image -var input = await PreprocessImageAsync(await LoadImageFileAsync(imagePath)); -// Prepare input tensor -var inputName = session.InputMetadata.First().Key; -var inputTensor = new DenseTensor( - input.ToArray(), // Use the DenseTensor directly - new[] { 1, 3, 224, 224 }, // Shape of the tensor - false // isReversedStride should be explicitly set to false -); - -// Bind inputs and run inference -var inputs = new List -{ - NamedOnnxValue.CreateFromTensor(inputName, inputTensor) -}; - -Console.WriteLine("Running inference ..."); -var results = session.Run(inputs); -for (int i = 0; i < 40; i++) -{ - results = session.Run(inputs); -} - -// Extract output tensor -var outputName = session.OutputMetadata.First().Key; -var resultTensor = results.First(r => r.Name == outputName).AsEnumerable().ToArray(); - -// Load labels and print results -var labels = LoadLabels(labelsPath); -PrintResults(labels, resultTensor); -``` - -### Post-processing. - -The softmax function is applied to returned raw output, and label data is used to map and print the names with the five highest probabilities. - -```csharp -private static void PrintResults(IList labels, IReadOnlyList results) -{ - // Apply softmax to the results - float maxLogit = results.Max(); - var expScores = results.Select(r => MathF.Exp(r - maxLogit)).ToList(); // stability with maxLogit - float sumExp = expScores.Sum(); - var softmaxResults = expScores.Select(e => e / sumExp).ToList(); - - // Get top 5 results - IEnumerable<(int Index, float Confidence)> topResults = softmaxResults - .Select((value, index) => (Index: index, Confidence: value)) - .OrderByDescending(x => x.Confidence) - .Take(5); - - // Display results - Console.WriteLine("Top Predictions:"); - Console.WriteLine("-------------------------------------------"); - Console.WriteLine("{0,-32} {1,10}", "Label", "Confidence"); - Console.WriteLine("-------------------------------------------"); - - foreach (var result in topResults) - { - Console.WriteLine("{0,-32} {1,10:P2}", labels[result.Index], result.Confidence); - } - - Console.WriteLine("-------------------------------------------"); -} -``` - -### Output - -Here's an example of the kind of output to be expected. - -```console -------------------------------------------- -Label Confidence -------------------------------------------- -French bulldog 45.07% -bull mastiff 35.05% -boxer 2.85% -pug 1.01% -American Staffordshire terrier 0.57% -------------------------------------------- -``` diff --git a/Samples/WindowsML/cs/ResnetBuildDemoCS/ResnetBuildDemoCS/Program.cs b/Samples/WindowsML/cs/ResnetBuildDemoCS/ResnetBuildDemoCS/Program.cs deleted file mode 100644 index fd7d690c5..000000000 --- a/Samples/WindowsML/cs/ResnetBuildDemoCS/ResnetBuildDemoCS/Program.cs +++ /dev/null @@ -1,245 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE.md in the repo root for license information. - -using Microsoft.ML.OnnxRuntime; -using Microsoft.ML.OnnxRuntime.Tensors; -using Microsoft.Windows.AI.MachineLearning; -using System.Reflection; -using System.Runtime.InteropServices.WindowsRuntime; -using Windows.Graphics.Imaging; -using Windows.Storage; -using Windows.Storage.Streams; - -internal class Program -{ - private static async Task LoadImageFileAsync(string filePath) - { - StorageFile file = await StorageFile.GetFileFromPathAsync(filePath); - var stream = await file.OpenAsync(FileAccessMode.Read); - BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream); - SoftwareBitmap softwareBitmap = await decoder.GetSoftwareBitmapAsync(); - - return softwareBitmap; - } - - public static async Task> PreprocessImageAsync(SoftwareBitmap softwareBitmap) - { - const int targetWidth = 224; - const int targetHeight = 224; - - float[] mean = new float[] { 0.485f, 0.456f, 0.406f }; - float[] std = new float[] { 0.229f, 0.224f, 0.225f }; - - // Convert to BGRA8 - if (softwareBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 || - softwareBitmap.BitmapAlphaMode != BitmapAlphaMode.Premultiplied) - { - softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied); - } - - // Resize - softwareBitmap = await ResizeSoftwareBitmapAsync(softwareBitmap, targetWidth, targetHeight); - - // Get pixel data - uint bufferSize = (uint)(targetWidth * targetHeight * 4); - var buffer = new Windows.Storage.Streams.Buffer(bufferSize); - softwareBitmap.CopyToBuffer(buffer); - byte[] pixels = buffer.ToArray(); - - // Output Tensor shape: [1, 3, 224, 224] - var tensorData = new DenseTensor(new[] { 1, 3, targetHeight, targetWidth }); - - for (int y = 0; y < targetHeight; y++) - { - for (int x = 0; x < targetWidth; x++) - { - int pixelIndex = (y * targetWidth + x) * 4; - float r = pixels[pixelIndex + 2] / 255f; - float g = pixels[pixelIndex + 1] / 255f; - float b = pixels[pixelIndex + 0] / 255f; - - // Normalize using mean/stddev - r = (r - mean[0]) / std[0]; - g = (g - mean[1]) / std[1]; - b = (b - mean[2]) / std[2]; - - int baseIndex = y * targetWidth + x; - tensorData[0, 0, y, x] = r; // R - tensorData[0, 1, y, x] = g; // G - tensorData[0, 2, y, x] = b; // B - } - } - - return tensorData; - } - - private static async Task ResizeSoftwareBitmapAsync(SoftwareBitmap bitmap, int width, int height) - { - using (var stream = new InMemoryRandomAccessStream()) - { - var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream); - encoder.SetSoftwareBitmap(bitmap); - encoder.IsThumbnailGenerated = false; - await encoder.FlushAsync(); - stream.Seek(0); - - var decoder = await BitmapDecoder.CreateAsync(stream); - var transform = new BitmapTransform() { - ScaledWidth = (uint)width, - ScaledHeight = (uint)height, - InterpolationMode = BitmapInterpolationMode.Fant - }; - var resized = await decoder.GetSoftwareBitmapAsync( - BitmapPixelFormat.Bgra8, - BitmapAlphaMode.Premultiplied, - transform, - ExifOrientationMode.IgnoreExifOrientation, - ColorManagementMode.DoNotColorManage); - - return resized; - } - } - - private static IList LoadLabels(string labelsPath) - { - return File.ReadAllLines(labelsPath) - .Select(line => line.Split(',', 2)[1]) - .ToList(); - } - - private static void PrintResults(IList labels, IReadOnlyList results) - { - // Apply softmax to the results - float maxLogit = results.Max(); - var expScores = results.Select(r => MathF.Exp(r - maxLogit)).ToList(); // stability with maxLogit - float sumExp = expScores.Sum(); - var softmaxResults = expScores.Select(e => e / sumExp).ToList(); - - // Get top 5 results - IEnumerable<(int Index, float Confidence)> topResults = softmaxResults - .Select((value, index) => (Index: index, Confidence: value)) - .OrderByDescending(x => x.Confidence) - .Take(5); - - // Display results - Console.WriteLine("Top Predictions:"); - Console.WriteLine("-------------------------------------------"); - Console.WriteLine("{0,-32} {1,10}", "Label", "Confidence"); - Console.WriteLine("-------------------------------------------"); - - foreach (var result in topResults) - { - Console.WriteLine("{0,-32} {1,10:P2}", labels[result.Index], result.Confidence); - } - - Console.WriteLine("-------------------------------------------"); - } - public static async Task Main(string[] arguments) - { - try - { - // Create a new instance of EnvironmentCreationOptions - EnvironmentCreationOptions envOptions = new() { - logId = "ResnetBuildDemo", - logLevel = OrtLoggingLevel.ORT_LOGGING_LEVEL_ERROR - }; - - // Pass the options by reference to CreateInstanceWithOptions - OrtEnv ortEnv = OrtEnv.CreateInstanceWithOptions(ref envOptions); - - // Use WinML to download and register Execution Providers - var catalog = ExecutionProviderCatalog.GetDefault(); - var registeredProviders = await catalog.EnsureAndRegisterCertifiedAsync(); - - // Prepare paths - string executableFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)!; - string labelsPath = Path.Combine(executableFolder, "ResNet50Labels.txt"); - string imagePath = Path.Combine(executableFolder, "dog.jpg"); - - // TODO: Please use AITK Model Conversion tool to download and convert Resnet, and paste the converted path here - string modelPath = @""; - string compiledModelPath = @""; - - if (string.IsNullOrEmpty(modelPath)) - { - Console.WriteLine("Please specify the path to the ResNet model in the program source code."); - Console.WriteLine("Exiting ..."); - return -1; - } - - // Create Onnx session - Console.WriteLine("Creating session ..."); - var sessionOptions = new SessionOptions(); - // Set EP Selection Policy - sessionOptions.SetEpSelectionPolicy(ExecutionProviderDevicePolicy.MIN_OVERALL_POWER); - - // Compile the model if not already compiled - bool isCompiled = File.Exists(compiledModelPath); - if (!isCompiled) - { - Console.WriteLine("No compiled model found. Compiling model ..."); - using (var compileOptions = new OrtModelCompilationOptions(sessionOptions)) - { - compileOptions.SetInputModelPath(modelPath); - compileOptions.SetOutputModelPath(compiledModelPath); - compileOptions.CompileModel(); - isCompiled = File.Exists(compiledModelPath); - if (isCompiled) - { - Console.WriteLine("Model compiled successfully!"); - } - else - { - Console.WriteLine("Failed to compile the model. Will use original model."); - } - } - } - else - { - Console.WriteLine("Found precompiled model."); - } - var modelPathToUse = isCompiled ? compiledModelPath : modelPath; - using var session = new InferenceSession(modelPathToUse, sessionOptions); - - Console.WriteLine("Preparing input ..."); - // Load and preprocess image - var input = await PreprocessImageAsync(await LoadImageFileAsync(imagePath)); - // Prepare input tensor - var inputName = session.InputMetadata.First().Key; - var inputTensor = new DenseTensor( - input.ToArray(), // Use the DenseTensor directly - new[] { 1, 3, 224, 224 }, // Shape of the tensor - false // isReversedStride should be explicitly set to false - ); - - // Bind inputs and run inference - var inputs = new List - { - NamedOnnxValue.CreateFromTensor(inputName, inputTensor) - }; - - Console.WriteLine("Running inference ..."); - var results = session.Run(inputs); - for (int i = 0; i < 40; i++) - { - results = session.Run(inputs); - } - - // Extract output tensor - var outputName = session.OutputMetadata.First().Key; - var resultTensor = results.First(r => r.Name == outputName).AsEnumerable().ToArray(); - - // Load labels and print results - var labels = LoadLabels(labelsPath); - PrintResults(labels, resultTensor); - return 0; - } - catch (Exception ex) - { - Console.Error.WriteLine($"Exception: {ex}"); - } - - return -1; - } - -} diff --git a/Samples/WindowsML/cs/ResnetBuildDemoCS/ResnetBuildDemoCS/ResNet50Labels.txt b/Samples/WindowsML/cs/ResnetBuildDemoCS/ResnetBuildDemoCS/ResNet50Labels.txt deleted file mode 100644 index 60d6558a9..000000000 --- a/Samples/WindowsML/cs/ResnetBuildDemoCS/ResnetBuildDemoCS/ResNet50Labels.txt +++ /dev/null @@ -1,1000 +0,0 @@ -0,tench -1,goldfish -2,great white shark -3,tiger shark -4,hammerhead -5,electric ray -6,stingray -7,cock -8,hen -9,ostrich -10,brambling -11,goldfinch -12,house finch -13,junco -14,indigo bunting -15,robin -16,bulbul -17,jay -18,magpie -19,chickadee -20,water ouzel -21,kite -22,bald eagle -23,vulture -24,great grey owl -25,European fire salamander -26,common newt -27,eft -28,spotted salamander -29,axolotl -30,bullfrog -31,tree frog -32,tailed frog -33,loggerhead -34,leatherback turtle -35,mud turtle -36,terrapin -37,box turtle -38,banded gecko -39,common iguana -40,American chameleon -41,whiptail -42,agama -43,frilled lizard -44,alligator lizard -45,Gila monster -46,green lizard -47,African chameleon -48,Komodo dragon -49,African crocodile -50,American alligator -51,triceratops -52,thunder snake -53,ringneck snake -54,hognose snake -55,green snake -56,king snake -57,garter snake -58,water snake -59,vine snake -60,night snake -61,boa constrictor -62,rock python -63,Indian cobra -64,green mamba -65,sea snake -66,horned viper -67,diamondback -68,sidewinder -69,trilobite -70,harvestman -71,scorpion -72,black and gold garden spider -73,barn spider -74,garden spider -75,black widow -76,tarantula -77,wolf spider -78,tick -79,centipede -80,black grouse -81,ptarmigan -82,ruffed grouse -83,prairie chicken -84,peacock -85,quail -86,partridge -87,African grey -88,macaw -89,sulphur-crested cockatoo -90,lorikeet -91,coucal -92,bee eater -93,hornbill -94,hummingbird -95,jacamar -96,toucan -97,drake -98,red-breasted merganser -99,goose -100,black swan -101,tusker -102,echidna -103,platypus -104,wallaby -105,koala -106,wombat -107,jellyfish -108,sea anemone -109,brain coral -110,flatworm -111,nematode -112,conch -113,snail -114,slug -115,sea slug -116,chiton -117,chambered nautilus -118,Dungeness crab -119,rock crab -120,fiddler crab -121,king crab -122,American lobster -123,spiny lobster -124,crayfish -125,hermit crab -126,isopod -127,white stork -128,black stork -129,spoonbill -130,flamingo -131,little blue heron -132,American egret -133,bittern -134,crane -135,limpkin -136,European gallinule -137,American coot -138,bustard -139,ruddy turnstone -140,red-backed sandpiper -141,redshank -142,dowitcher -143,oystercatcher -144,pelican -145,king penguin -146,albatross -147,grey whale -148,killer whale -149,dugong -150,sea lion -151,Chihuahua -152,Japanese spaniel -153,Maltese dog -154,Pekinese -155,Shih-Tzu -156,Blenheim spaniel -157,papillon -158,toy terrier -159,Rhodesian ridgeback -160,Afghan hound -161,basset -162,beagle -163,bloodhound -164,bluetick -165,black-and-tan coonhound -166,Walker hound -167,English foxhound -168,redbone -169,borzoi -170,Irish wolfhound -171,Italian greyhound -172,whippet -173,Ibizan hound -174,Norwegian elkhound -175,otterhound -176,Saluki -177,Scottish deerhound -178,Weimaraner -179,Staffordshire bullterrier -180,American Staffordshire terrier -181,Bedlington terrier -182,Border terrier -183,Kerry blue terrier -184,Irish terrier -185,Norfolk terrier -186,Norwich terrier -187,Yorkshire terrier -188,wire-haired fox terrier -189,Lakeland terrier -190,Sealyham terrier -191,Airedale -192,cairn -193,Australian terrier -194,Dandie Dinmont -195,Boston bull -196,miniature schnauzer -197,giant schnauzer -198,standard schnauzer -199,Scotch terrier -200,Tibetan terrier -201,silky terrier -202,soft-coated wheaten terrier -203,West Highland white terrier -204,Lhasa -205,flat-coated retriever -206,curly-coated retriever -207,golden retriever -208,Labrador retriever -209,Chesapeake Bay retriever -210,German short-haired pointer -211,vizsla -212,English setter -213,Irish setter -214,Gordon setter -215,Brittany spaniel -216,clumber -217,English springer -218,Welsh springer spaniel -219,cocker spaniel -220,Sussex spaniel -221,Irish water spaniel -222,kuvasz -223,schipperke -224,groenendael -225,malinois -226,briard -227,kelpie -228,komondor -229,Old English sheepdog -230,Shetland sheepdog -231,collie -232,Border collie -233,Bouvier des Flandres -234,Rottweiler -235,German shepherd -236,Doberman -237,miniature pinscher -238,Greater Swiss Mountain dog -239,Bernese mountain dog -240,Appenzeller -241,EntleBucher -242,boxer -243,bull mastiff -244,Tibetan mastiff -245,French bulldog -246,Great Dane -247,Saint Bernard -248,Eskimo dog -249,malamute -250,Siberian husky -251,dalmatian -252,affenpinscher -253,basenji -254,pug -255,Leonberg -256,Newfoundland -257,Great Pyrenees -258,Samoyed -259,Pomeranian -260,chow -261,keeshond -262,Brabancon griffon -263,Pembroke -264,Cardigan -265,toy poodle -266,miniature poodle -267,standard poodle -268,Mexican hairless -269,timber wolf -270,white wolf -271,red wolf -272,coyote -273,dingo -274,dhole -275,African hunting dog -276,hyena -277,red fox -278,kit fox -279,Arctic fox -280,grey fox -281,tabby -282,tiger cat -283,Persian cat -284,Siamese cat -285,Egyptian cat -286,cougar -287,lynx -288,leopard -289,snow leopard -290,jaguar -291,lion -292,tiger -293,cheetah -294,brown bear -295,American black bear -296,ice bear -297,sloth bear -298,mongoose -299,meerkat -300,tiger beetle -301,ladybug -302,ground beetle -303,long-horned beetle -304,leaf beetle -305,dung beetle -306,rhinoceros beetle -307,weevil -308,fly -309,bee -310,ant -311,grasshopper -312,cricket -313,walking stick -314,cockroach -315,mantis -316,cicada -317,leafhopper -318,lacewing -319,dragonfly -320,damselfly -321,admiral -322,ringlet -323,monarch -324,cabbage butterfly -325,sulphur butterfly -326,lycaenid -327,starfish -328,sea urchin -329,sea cucumber -330,wood rabbit -331,hare -332,Angora -333,hamster -334,porcupine -335,fox squirrel -336,marmot -337,beaver -338,guinea pig -339,sorrel -340,zebra -341,hog -342,wild boar -343,warthog -344,hippopotamus -345,ox -346,water buffalo -347,bison -348,ram -349,bighorn -350,ibex -351,hartebeest -352,impala -353,gazelle -354,Arabian camel -355,llama -356,weasel -357,mink -358,polecat -359,black-footed ferret -360,otter -361,skunk -362,badger -363,armadillo -364,three-toed sloth -365,orangutan -366,gorilla -367,chimpanzee -368,gibbon -369,siamang -370,guenon -371,patas -372,baboon -373,macaque -374,langur -375,colobus -376,proboscis monkey -377,marmoset -378,capuchin -379,howler monkey -380,titi -381,spider monkey -382,squirrel monkey -383,Madagascar cat -384,indri -385,Indian elephant -386,African elephant -387,lesser panda -388,giant panda -389,barracouta -390,eel -391,coho -392,rock beauty -393,anemone fish -394,sturgeon -395,gar -396,lionfish -397,puffer -398,abacus -399,abaya -400,academic gown -401,accordion -402,acoustic guitar -403,aircraft carrier -404,airliner -405,airship -406,altar -407,ambulance -408,amphibian -409,analog clock -410,apiary -411,apron -412,ashcan -413,assault rifle -414,backpack -415,bakery -416,balance beam -417,balloon -418,ballpoint -419,Band Aid -420,banjo -421,bannister -422,barbell -423,barber chair -424,barbershop -425,barn -426,barometer -427,barrel -428,barrow -429,baseball -430,basketball -431,bassinet -432,bassoon -433,bathing cap -434,bath towel -435,bathtub -436,beach wagon -437,beacon -438,beaker -439,bearskin -440,beer bottle -441,beer glass -442,bell cote -443,bib -444,bicycle-built-for-two -445,bikini -446,binder -447,binoculars -448,birdhouse -449,boathouse -450,bobsled -451,bolo tie -452,bonnet -453,bookcase -454,bookshop -455,bottlecap -456,bow -457,bow tie -458,brass -459,brassiere -460,breakwater -461,breastplate -462,broom -463,bucket -464,buckle -465,bulletproof vest -466,bullet train -467,butcher shop -468,cab -469,caldron -470,candle -471,cannon -472,canoe -473,can opener -474,cardigan -475,car mirror -476,carousel -477,carpenter's kit -478,carton -479,car wheel -480,cash machine -481,cassette -482,cassette player -483,castle -484,catamaran -485,CD player -486,cello -487,cellular telephone -488,chain -489,chainlink fence -490,chain mail -491,chain saw -492,chest -493,chiffonier -494,chime -495,china cabinet -496,Christmas stocking -497,church -498,cinema -499,cleaver -500,cliff dwelling -501,cloak -502,clog -503,cocktail shaker -504,coffee mug -505,coffeepot -506,coil -507,combination lock -508,computer keyboard -509,confectionery -510,container ship -511,convertible -512,corkscrew -513,cornet -514,cowboy boot -515,cowboy hat -516,cradle -517,crane -518,crash helmet -519,crate -520,crib -521,Crock Pot -522,croquet ball -523,crutch -524,cuirass -525,dam -526,desk -527,desktop computer -528,dial telephone -529,diaper -530,digital clock -531,digital watch -532,dining table -533,dishrag -534,dishwasher -535,disk brake -536,dock -537,dogsled -538,dome -539,doormat -540,drilling platform -541,drum -542,drumstick -543,dumbbell -544,Dutch oven -545,electric fan -546,electric guitar -547,electric locomotive -548,entertainment center -549,envelope -550,espresso maker -551,face powder -552,feather boa -553,file -554,fireboat -555,fire engine -556,fire screen -557,flagpole -558,flute -559,folding chair -560,football helmet -561,forklift -562,fountain -563,fountain pen -564,four-poster -565,freight car -566,French horn -567,frying pan -568,fur coat -569,garbage truck -570,gasmask -571,gas pump -572,goblet -573,go-kart -574,golf ball -575,golfcart -576,gondola -577,gong -578,gown -579,grand piano -580,greenhouse -581,grille -582,grocery store -583,guillotine -584,hair slide -585,hair spray -586,half track -587,hammer -588,hamper -589,hand blower -590,hand-held computer -591,handkerchief -592,hard disc -593,harmonica -594,harp -595,harvester -596,hatchet -597,holster -598,home theater -599,honeycomb -600,hook -601,hoopskirt -602,horizontal bar -603,horse cart -604,hourglass -605,iPod -606,iron -607,jack-o'-lantern -608,jean -609,jeep -610,jersey -611,jigsaw puzzle -612,jinrikisha -613,joystick -614,kimono -615,knee pad -616,knot -617,lab coat -618,ladle -619,lampshade -620,laptop -621,lawn mower -622,lens cap -623,letter opener -624,library -625,lifeboat -626,lighter -627,limousine -628,liner -629,lipstick -630,Loafer -631,lotion -632,loudspeaker -633,loupe -634,lumbermill -635,magnetic compass -636,mailbag -637,mailbox -638,maillot -639,maillot -640,manhole cover -641,maraca -642,marimba -643,mask -644,matchstick -645,maypole -646,maze -647,measuring cup -648,medicine chest -649,megalith -650,microphone -651,microwave -652,military uniform -653,milk can -654,minibus -655,miniskirt -656,minivan -657,missile -658,mitten -659,mixing bowl -660,mobile home -661,Model T -662,modem -663,monastery -664,monitor -665,moped -666,mortar -667,mortarboard -668,mosque -669,mosquito net -670,motor scooter -671,mountain bike -672,mountain tent -673,mouse -674,mousetrap -675,moving van -676,muzzle -677,nail -678,neck brace -679,necklace -680,nipple -681,notebook -682,obelisk -683,oboe -684,ocarina -685,odometer -686,oil filter -687,organ -688,oscilloscope -689,overskirt -690,oxcart -691,oxygen mask -692,packet -693,paddle -694,paddlewheel -695,padlock -696,paintbrush -697,pajama -698,palace -699,panpipe -700,paper towel -701,parachute -702,parallel bars -703,park bench -704,parking meter -705,passenger car -706,patio -707,pay-phone -708,pedestal -709,pencil box -710,pencil sharpener -711,perfume -712,Petri dish -713,photocopier -714,pick -715,pickelhaube -716,picket fence -717,pickup -718,pier -719,piggy bank -720,pill bottle -721,pillow -722,ping-pong ball -723,pinwheel -724,pirate -725,pitcher -726,plane -727,planetarium -728,plastic bag -729,plate rack -730,plow -731,plunger -732,Polaroid camera -733,pole -734,police van -735,poncho -736,pool table -737,pop bottle -738,pot -739,potter's wheel -740,power drill -741,prayer rug -742,printer -743,prison -744,projectile -745,projector -746,puck -747,punching bag -748,purse -749,quill -750,quilt -751,racer -752,racket -753,radiator -754,radio -755,radio telescope -756,rain barrel -757,recreational vehicle -758,reel -759,reflex camera -760,refrigerator -761,remote control -762,restaurant -763,revolver -764,rifle -765,rocking chair -766,rotisserie -767,rubber eraser -768,rugby ball -769,rule -770,running shoe -771,safe -772,safety pin -773,saltshaker -774,sandal -775,sarong -776,sax -777,scabbard -778,scale -779,school bus -780,schooner -781,scoreboard -782,screen -783,screw -784,screwdriver -785,seat belt -786,sewing machine -787,shield -788,shoe shop -789,shoji -790,shopping basket -791,shopping cart -792,shovel -793,shower cap -794,shower curtain -795,ski -796,ski mask -797,sleeping bag -798,slide rule -799,sliding door -800,slot -801,snorkel -802,snowmobile -803,snowplow -804,soap dispenser -805,soccer ball -806,sock -807,solar dish -808,sombrero -809,soup bowl -810,space bar -811,space heater -812,space shuttle -813,spatula -814,speedboat -815,spider web -816,spindle -817,sports car -818,spotlight -819,stage -820,steam locomotive -821,steel arch bridge -822,steel drum -823,stethoscope -824,stole -825,stone wall -826,stopwatch -827,stove -828,strainer -829,streetcar -830,stretcher -831,studio couch -832,stupa -833,submarine -834,suit -835,sundial -836,sunglass -837,sunglasses -838,sunscreen -839,suspension bridge -840,swab -841,sweatshirt -842,swimming trunks -843,swing -844,switch -845,syringe -846,table lamp -847,tank -848,tape player -849,teapot -850,teddy -851,television -852,tennis ball -853,thatch -854,theater curtain -855,thimble -856,thresher -857,throne -858,tile roof -859,toaster -860,tobacco shop -861,toilet seat -862,torch -863,totem pole -864,tow truck -865,toyshop -866,tractor -867,trailer truck -868,tray -869,trench coat -870,tricycle -871,trimaran -872,tripod -873,triumphal arch -874,trolleybus -875,trombone -876,tub -877,turnstile -878,typewriter keyboard -879,umbrella -880,unicycle -881,upright -882,vacuum -883,vase -884,vault -885,velvet -886,vending machine -887,vestment -888,viaduct -889,violin -890,volleyball -891,waffle iron -892,wall clock -893,wallet -894,wardrobe -895,warplane -896,washbasin -897,washer -898,water bottle -899,water jug -900,water tower -901,whiskey jug -902,whistle -903,wig -904,window screen -905,window shade -906,Windsor tie -907,wine bottle -908,wing -909,wok -910,wooden spoon -911,wool -912,worm fence -913,wreck -914,yawl -915,yurt -916,web site -917,comic book -918,crossword puzzle -919,street sign -920,traffic light -921,book jacket -922,menu -923,plate -924,guacamole -925,consomme -926,hot pot -927,trifle -928,ice cream -929,ice lolly -930,French loaf -931,bagel -932,pretzel -933,cheeseburger -934,hotdog -935,mashed potato -936,head cabbage -937,broccoli -938,cauliflower -939,zucchini -940,spaghetti squash -941,acorn squash -942,butternut squash -943,cucumber -944,artichoke -945,bell pepper -946,cardoon -947,mushroom -948,Granny Smith -949,strawberry -950,orange -951,lemon -952,fig -953,pineapple -954,banana -955,jackfruit -956,custard apple -957,pomegranate -958,hay -959,carbonara -960,chocolate sauce -961,dough -962,meat loaf -963,pizza -964,potpie -965,burrito -966,red wine -967,espresso -968,cup -969,eggnog -970,alp -971,bubble -972,cliff -973,coral reef -974,geyser -975,lakeside -976,promontory -977,sandbar -978,seashore -979,valley -980,volcano -981,ballplayer -982,groom -983,scuba diver -984,rapeseed -985,daisy -986,yellow lady's slipper -987,corn -988,acorn -989,hip -990,buckeye -991,coral fungus -992,agaric -993,gyromitra -994,stinkhorn -995,earthstar -996,hen-of-the-woods -997,bolete -998,ear -999,toilet tissue diff --git a/Samples/WindowsML/cs/ResnetBuildDemoCS/ResnetBuildDemoCS/ResnetBuildDemoCS.csproj b/Samples/WindowsML/cs/ResnetBuildDemoCS/ResnetBuildDemoCS/ResnetBuildDemoCS.csproj deleted file mode 100644 index 1d2979257..000000000 --- a/Samples/WindowsML/cs/ResnetBuildDemoCS/ResnetBuildDemoCS/ResnetBuildDemoCS.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - Exe - None - - - - - - - - - - - - - - diff --git a/Samples/WindowsML/cs/ResnetBuildDemoCS/ResnetBuildDemoCS/dog.jpg b/Samples/WindowsML/cs/ResnetBuildDemoCS/ResnetBuildDemoCS/dog.jpg deleted file mode 100644 index 3a20c37d3..000000000 Binary files a/Samples/WindowsML/cs/ResnetBuildDemoCS/ResnetBuildDemoCS/dog.jpg and /dev/null differ diff --git a/Samples/WindowsML/python/Model/SqueezeNet.LICENSE.txt b/Samples/WindowsML/python/Model/SqueezeNet.LICENSE.txt deleted file mode 100644 index f1a045049..000000000 --- a/Samples/WindowsML/python/Model/SqueezeNet.LICENSE.txt +++ /dev/null @@ -1,20 +0,0 @@ -BSD LICENSE. - -Redistribution and use in source and binary forms, with or without modification, are permitted -provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this list of conditions -and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions -and the following disclaimer in the documentation and/or other materials provided with the -distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR -IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER -IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Samples/WindowsML/python/SqueezeNetPython/Install-Requirements.ps1 b/Samples/WindowsML/python/SqueezeNetPython/Install-Requirements.ps1 index 292d31cb5..be1bcefda 100644 --- a/Samples/WindowsML/python/SqueezeNetPython/Install-Requirements.ps1 +++ b/Samples/WindowsML/python/SqueezeNetPython/Install-Requirements.ps1 @@ -1,7 +1,4 @@ # Install dependencies for SqueezeNetPython sample -# Install onnxruntime-winml from ORT-Nightly feed -pip install --upgrade --pre -r requirements-ort.txt - # Install remaining dependencies from PyPI pip install --upgrade --pre -r requirements.txt diff --git a/Samples/WindowsML/python/SqueezeNetPython/requirements-ort.txt b/Samples/WindowsML/python/SqueezeNetPython/requirements-ort.txt deleted file mode 100644 index e0536a44a..000000000 --- a/Samples/WindowsML/python/SqueezeNetPython/requirements-ort.txt +++ /dev/null @@ -1,3 +0,0 @@ -# onnxruntime-winml from ORT-Nightly feed ---index-url https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/pypi/simple/ -onnxruntime-winml diff --git a/Samples/WindowsML/python/SqueezeNetPython/requirements.txt b/Samples/WindowsML/python/SqueezeNetPython/requirements.txt index 4c3d2b303..4424221ab 100644 --- a/Samples/WindowsML/python/SqueezeNetPython/requirements.txt +++ b/Samples/WindowsML/python/SqueezeNetPython/requirements.txt @@ -1,4 +1,4 @@ pillow numpy -wasdk-Microsoft.Windows.AI.MachineLearning[all] -wasdk-Microsoft.Windows.ApplicationModel.DynamicDependency.Bootstrap +wasdk-Microsoft.Windows.AI.MachineLearning[all]==2.1.3 +wasdk-Microsoft.Windows.ApplicationModel.DynamicDependency.Bootstrap==2.1.3