This commit is contained in:
REDMOND\jingf 2022-03-11 16:45:29 -08:00
Родитель cd3c2ed012
Коммит 3c426e024d
8 изменённых файлов: 74 добавлений и 37 удалений

Просмотреть файл

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\BatchSupport\packages\Microsoft.Windows.CppWinRT.2.0.220131.2\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\..\BatchSupport\packages\Microsoft.Windows.CppWinRT.2.0.220131.2\build\native\Microsoft.Windows.CppWinRT.props')" />
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.220131.2\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.220131.2\build\native\Microsoft.Windows.CppWinRT.props')" />
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug_NuGet|Win32">
<Configuration>Debug_NuGet</Configuration>
@ -69,7 +69,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
@ -251,13 +251,13 @@
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\..\BatchSupport\packages\Microsoft.Windows.CppWinRT.2.0.220131.2\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\..\BatchSupport\packages\Microsoft.Windows.CppWinRT.2.0.220131.2\build\native\Microsoft.Windows.CppWinRT.targets')" />
<Import Project="..\packages\Microsoft.Windows.CppWinRT.2.0.220131.2\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.220131.2\build\native\Microsoft.Windows.CppWinRT.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\BatchSupport\packages\Microsoft.Windows.CppWinRT.2.0.220131.2\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\BatchSupport\packages\Microsoft.Windows.CppWinRT.2.0.220131.2\build\native\Microsoft.Windows.CppWinRT.props'))" />
<Error Condition="!Exists('..\..\BatchSupport\packages\Microsoft.Windows.CppWinRT.2.0.220131.2\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\BatchSupport\packages\Microsoft.Windows.CppWinRT.2.0.220131.2\build\native\Microsoft.Windows.CppWinRT.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.220131.2\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.220131.2\build\native\Microsoft.Windows.CppWinRT.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Windows.CppWinRT.2.0.220131.2\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.CppWinRT.2.0.220131.2\build\native\Microsoft.Windows.CppWinRT.targets'))" />
</Target>
</Project>

Просмотреть файл

@ -1,18 +1,29 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.32126.315
# Visual Studio Version 17
VisualStudioVersion = 17.1.32210.238
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinMLPIXSample", "WinMLPIXSample\WinMLPIXSample.vcxproj", "{3F9AE007-1715-46FF-8A52-E0A420290FCC}"
ProjectSection(ProjectDependencies) = postProject
{12103A5B-677A-4286-83D2-54EAB9010C16} = {12103A5B-677A-4286-83D2-54EAB9010C16}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SampleSharedLib", "..\..\SampleSharedLib\SampleSharedLib\SampleSharedLib.vcxproj", "{12103A5B-677A-4286-83D2-54EAB9010C16}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug_NuGet|x64 = Debug_NuGet|x64
Debug_NuGet|x86 = Debug_NuGet|x86
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3F9AE007-1715-46FF-8A52-E0A420290FCC}.Debug_NuGet|x64.ActiveCfg = Debug|x64
{3F9AE007-1715-46FF-8A52-E0A420290FCC}.Debug_NuGet|x64.Build.0 = Debug|x64
{3F9AE007-1715-46FF-8A52-E0A420290FCC}.Debug_NuGet|x86.ActiveCfg = Debug|Win32
{3F9AE007-1715-46FF-8A52-E0A420290FCC}.Debug_NuGet|x86.Build.0 = Debug|Win32
{3F9AE007-1715-46FF-8A52-E0A420290FCC}.Debug|x64.ActiveCfg = Debug|x64
{3F9AE007-1715-46FF-8A52-E0A420290FCC}.Debug|x64.Build.0 = Debug|x64
{3F9AE007-1715-46FF-8A52-E0A420290FCC}.Debug|x86.ActiveCfg = Debug|Win32
@ -21,6 +32,18 @@ Global
{3F9AE007-1715-46FF-8A52-E0A420290FCC}.Release|x64.Build.0 = Release|x64
{3F9AE007-1715-46FF-8A52-E0A420290FCC}.Release|x86.ActiveCfg = Release|Win32
{3F9AE007-1715-46FF-8A52-E0A420290FCC}.Release|x86.Build.0 = Release|Win32
{12103A5B-677A-4286-83D2-54EAB9010C16}.Debug_NuGet|x64.ActiveCfg = Debug_NuGet|x64
{12103A5B-677A-4286-83D2-54EAB9010C16}.Debug_NuGet|x64.Build.0 = Debug_NuGet|x64
{12103A5B-677A-4286-83D2-54EAB9010C16}.Debug_NuGet|x86.ActiveCfg = Debug_NuGet|Win32
{12103A5B-677A-4286-83D2-54EAB9010C16}.Debug_NuGet|x86.Build.0 = Debug_NuGet|Win32
{12103A5B-677A-4286-83D2-54EAB9010C16}.Debug|x64.ActiveCfg = Debug|x64
{12103A5B-677A-4286-83D2-54EAB9010C16}.Debug|x64.Build.0 = Debug|x64
{12103A5B-677A-4286-83D2-54EAB9010C16}.Debug|x86.ActiveCfg = Debug|Win32
{12103A5B-677A-4286-83D2-54EAB9010C16}.Debug|x86.Build.0 = Debug|Win32
{12103A5B-677A-4286-83D2-54EAB9010C16}.Release|x64.ActiveCfg = Release|x64
{12103A5B-677A-4286-83D2-54EAB9010C16}.Release|x64.Build.0 = Release|x64
{12103A5B-677A-4286-83D2-54EAB9010C16}.Release|x86.ActiveCfg = Release|Win32
{12103A5B-677A-4286-83D2-54EAB9010C16}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Просмотреть файл

@ -5,6 +5,7 @@
void LoadModel()
{
// load the model
auto modelPath = static_cast<hstring>(FileHelper::GetModulePath().c_str()) + modelName;
printf("Loading modelfile '%ws' on the '%s' device\n", modelPath.c_str(), deviceName.c_str());
DWORD ticks = GetTickCount();
model = LearningModel::LoadFromFilePath(modelPath);
@ -12,21 +13,18 @@ void LoadModel()
printf("model file loaded in %d ticks\n", ticks);
}
VideoFrame LoadImageFile(hstring filePath)
VideoFrame LoadImageFile()
{
printf("Loading the image...\n");
DWORD ticks = GetTickCount();
VideoFrame inputImage = nullptr;
TCHAR buffer[MAX_PATH] = { 0 };
wstring dir;
GetCurrentDirectory(MAX_PATH, buffer);
dir.assign(buffer).append(filePath);
auto imagePath = static_cast<hstring>(FileHelper::GetModulePath().c_str()) + imageName;
try
{
// open the file
StorageFile file = StorageFile::GetFileFromPathAsync(dir).get();
StorageFile file = StorageFile::GetFileFromPathAsync(imagePath).get();
// get a stream on it
auto stream = file.OpenAsync(FileAccessMode::Read).get();
// Create the decoder from the stream
@ -124,10 +122,11 @@ void PrintResults(IVectorView<float> results)
void LoadLabels()
{
// Parse labels from labels file. We know the file's entries are already sorted in order.
ifstream labelFile{ labelsFilePath, ifstream::in };
auto labelsFilePath = static_cast<hstring>(FileHelper::GetModulePath().c_str()) + labelsName;
ifstream labelFile{ labelsFilePath.c_str(), ifstream::in};
if (labelFile.fail())
{
printf("failed to load the %s file. Make sure it exists in the same folder as the app\r\n", labelsFilePath.c_str());
printf("failed to load the %s file. Make sure it exists in the same folder as the app\r\n", labelsName.c_str());
exit(EXIT_FAILURE);
}

Просмотреть файл

@ -14,19 +14,19 @@ using namespace winrt::Windows::Storage;
using namespace std;
// Global variables
static hstring modelPath = L".\\Assets\\SqueezeNet.onnx";
static hstring modelName = L"SqueezeNet.onnx";
static string deviceName = "default";
static hstring imagePath = L"\\Assets\\kitten_224.png";
static hstring imageName = L"kitten_224.png";
static LearningModel model = nullptr;
static LearningModelSession session = nullptr;
static LearningModelBinding binding = nullptr;
static VideoFrame imageFrame = nullptr;
static string labelsFilePath = ".\\Assets\\Labels.txt";
static hstring labelsName = L"Labels.txt";
static vector<string> labels;
// Forward declarations
void LoadModel();
VideoFrame LoadImageFile(hstring filePath);
VideoFrame LoadImageFile();
void CreateSession(ID3D12CommandQueue* commandQueue);
void BindModel();
void EvaluateModel();

Просмотреть файл

@ -77,11 +77,12 @@
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\..\SampleSharedLib\SampleSharedLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">ole32.lib;oleaut32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)\SampleSharedLib.lib;ole32.lib;oleaut32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Platform)'=='Win32'">
@ -95,12 +96,14 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\..\SampleSharedLib\SampleSharedLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)\SampleSharedLib.lib;ole32.lib;oleaut32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
@ -117,14 +120,26 @@
<ClCompile Include="WinMLHelper.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="Assets\SqueezeNet.onnx" />
<CopyFileToFolders Include="..\..\..\..\SharedContent\models\SqueezeNet.onnx">
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
<FileType>Document</FileType>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
</CopyFileToFolders>
<None Include="packages.config" />
<None Include="PropertySheet.props" />
<None Include="readme.md" />
<Text Include="Assets\Labels.txt" />
</ItemGroup>
<ItemGroup>
<Image Include="Assets\kitten_224.png" />
<CopyFileToFolders Include="..\..\..\..\SharedContent\media\kitten_224.png">
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
</CopyFileToFolders>
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="Assets\Labels.txt">
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
</CopyFileToFolders>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

Просмотреть файл

@ -10,7 +10,7 @@
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<UniqueIdentifier>{5f44b9c5-7076-4e47-ace0-bb83f8c4913b}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
@ -42,19 +42,17 @@
<ItemGroup>
<None Include="PropertySheet.props" />
<None Include="packages.config" />
<None Include="Assets\SqueezeNet.onnx">
<Filter>Resource Files</Filter>
</None>
<None Include="readme.md" />
</ItemGroup>
<ItemGroup>
<Text Include="Assets\Labels.txt">
<CopyFileToFolders Include="..\..\..\..\SharedContent\media\kitten_224.png">
<Filter>Resource Files</Filter>
</Text>
</ItemGroup>
<ItemGroup>
<Image Include="Assets\kitten_224.png">
</CopyFileToFolders>
<CopyFileToFolders Include="Assets\Labels.txt">
<Filter>Resource Files</Filter>
</Image>
</CopyFileToFolders>
<CopyFileToFolders Include="..\..\..\..\SharedContent\models\SqueezeNet.onnx">
<Filter>Resource Files</Filter>
</CopyFileToFolders>
</ItemGroup>
</Project>

Просмотреть файл

@ -73,14 +73,14 @@ void GetD3D12CommandAssets()
d3d12Device->CreateCommandList(0, type, commandAllocator, nullptr, __uuidof(ID3D12CommandList), (void**)&commandList);
}
void LoadAndEvaluate(ID3D12CommandQueue* commandQueue)
void LoadAndEvaluate()
{
// Setting markers for each step, these markers will split the commands into sections for easier debugging
PIXSetMarker(commandQueue, color, "Start loading model...");
LoadModel();
PIXSetMarker(commandQueue, color, "Start loading image...");
LoadImageFile(imagePath);
LoadImageFile();
PIXSetMarker(commandQueue, color, "Start creating session...");
CreateSession(commandQueue);
@ -109,7 +109,7 @@ void CaptureWithUserSetMarker()
PIXBeginEvent(commandQueue, color, "WinMLPIXSample");
// Do the ML computation
LoadAndEvaluate(commandQueue);
LoadAndEvaluate();
// End PIX event
PIXEndEvent(commandQueue);

Просмотреть файл

@ -16,4 +16,6 @@
#include <d3d12.h>
#include <dxgi1_4.h>
#include "pix3.h"
#include "pix3.h"
#include "FileHelper.h"