Add UWP Image recognition sample using ResNet model; Add Test for sample
change project setting to use common props; fix wrong name Cntk.Core_app-2.1.d.dll upgrade to use 2.1 Add missing pfx files
32
CNTK.sln
|
@ -1589,6 +1589,16 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CNTKLibraryCPPUWPEvalExampl
|
|||
{E5606ECE-48CA-4464-BB12-09D81D02B9EF} = {E5606ECE-48CA-4464-BB12-09D81D02B9EF}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageRecognitionAppCS", "Tests\EndToEndTests\EvalClientTests\UWPImageRecognitionTest\ImageRecognitionAppCS\ImageRecognitionAppCS.csproj", "{EA6DC625-7AD7-44A8-BDE9-4620D01B3AA5}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{C5E944BA-A7C4-482F-BE01-077A7DFC159C} = {C5E944BA-A7C4-482F-BE01-077A7DFC159C}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ImageRecognitionLib", "Tests\EndToEndTests\EvalClientTests\UWPImageRecognitionTest\ImageRecognizerLib\ImageRecognizerLib.vcxproj", "{C5E944BA-A7C4-482F-BE01-077A7DFC159C}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{E5606ECE-48CA-4464-BB12-09D81D02B9EF} = {E5606ECE-48CA-4464-BB12-09D81D02B9EF}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug_CpuOnly|x64 = Debug_CpuOnly|x64
|
||||
|
@ -2229,6 +2239,26 @@ Global
|
|||
{D5CB8825-0D1F-4940-9906-9BD87614B24E}.Release_UWP|x64.Build.0 = Release_UWP|x64
|
||||
{D5CB8825-0D1F-4940-9906-9BD87614B24E}.Release_UWP|x64.Deploy.0 = Release_UWP|x64
|
||||
{D5CB8825-0D1F-4940-9906-9BD87614B24E}.Release|x64.ActiveCfg = Release_UWP|x64
|
||||
{EA6DC625-7AD7-44A8-BDE9-4620D01B3AA5}.Debug_CpuOnly|x64.ActiveCfg = Debug_UWP|x64
|
||||
{EA6DC625-7AD7-44A8-BDE9-4620D01B3AA5}.Debug_UWP|x64.ActiveCfg = Debug_UWP|x64
|
||||
{EA6DC625-7AD7-44A8-BDE9-4620D01B3AA5}.Debug_UWP|x64.Build.0 = Debug_UWP|x64
|
||||
{EA6DC625-7AD7-44A8-BDE9-4620D01B3AA5}.Debug_UWP|x64.Deploy.0 = Debug_UWP|x64
|
||||
{EA6DC625-7AD7-44A8-BDE9-4620D01B3AA5}.Debug|x64.ActiveCfg = Debug_UWP|x64
|
||||
{EA6DC625-7AD7-44A8-BDE9-4620D01B3AA5}.Release_CpuOnly|x64.ActiveCfg = Release_UWP|x64
|
||||
{EA6DC625-7AD7-44A8-BDE9-4620D01B3AA5}.Release_NoOpt|x64.ActiveCfg = Release_UWP|x64
|
||||
{EA6DC625-7AD7-44A8-BDE9-4620D01B3AA5}.Release_UWP|x64.ActiveCfg = Release_UWP|x64
|
||||
{EA6DC625-7AD7-44A8-BDE9-4620D01B3AA5}.Release_UWP|x64.Build.0 = Release_UWP|x64
|
||||
{EA6DC625-7AD7-44A8-BDE9-4620D01B3AA5}.Release_UWP|x64.Deploy.0 = Release_UWP|x64
|
||||
{EA6DC625-7AD7-44A8-BDE9-4620D01B3AA5}.Release|x64.ActiveCfg = Release_UWP|x64
|
||||
{C5E944BA-A7C4-482F-BE01-077A7DFC159C}.Debug_CpuOnly|x64.ActiveCfg = Debug_UWP|x64
|
||||
{C5E944BA-A7C4-482F-BE01-077A7DFC159C}.Debug_UWP|x64.ActiveCfg = Debug_UWP|x64
|
||||
{C5E944BA-A7C4-482F-BE01-077A7DFC159C}.Debug_UWP|x64.Build.0 = Debug_UWP|x64
|
||||
{C5E944BA-A7C4-482F-BE01-077A7DFC159C}.Debug|x64.ActiveCfg = Debug_UWP|x64
|
||||
{C5E944BA-A7C4-482F-BE01-077A7DFC159C}.Release_CpuOnly|x64.ActiveCfg = Release_UWP|x64
|
||||
{C5E944BA-A7C4-482F-BE01-077A7DFC159C}.Release_NoOpt|x64.ActiveCfg = Release_UWP|x64
|
||||
{C5E944BA-A7C4-482F-BE01-077A7DFC159C}.Release_UWP|x64.ActiveCfg = Release_UWP|x64
|
||||
{C5E944BA-A7C4-482F-BE01-077A7DFC159C}.Release_UWP|x64.Build.0 = Release_UWP|x64
|
||||
{C5E944BA-A7C4-482F-BE01-077A7DFC159C}.Release|x64.ActiveCfg = Release_UWP|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -2448,5 +2478,7 @@ Global
|
|||
{BEF04803-47B4-4322-B9D7-E10A8468E79F} = {4EAFF1B2-2D70-4486-B95E-684E39A50609}
|
||||
{C28E4FD7-F9A9-4473-8E5D-D209AF36A1E7} = {4EAFF1B2-2D70-4486-B95E-684E39A50609}
|
||||
{D5CB8825-0D1F-4940-9906-9BD87614B24E} = {05E45AF7-C069-4057-BC16-0A532D068CE4}
|
||||
{EA6DC625-7AD7-44A8-BDE9-4620D01B3AA5} = {05E45AF7-C069-4057-BC16-0A532D068CE4}
|
||||
{C5E944BA-A7C4-482F-BE01-077A7DFC159C} = {05E45AF7-C069-4057-BC16-0A532D068CE4}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<Application
|
||||
x:Class="ImageRecognitionCS.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:ImageRecognitionCS"
|
||||
RequestedTheme="Light">
|
||||
|
||||
</Application>
|
|
@ -0,0 +1,100 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.ApplicationModel.Activation;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Controls.Primitives;
|
||||
using Windows.UI.Xaml.Data;
|
||||
using Windows.UI.Xaml.Input;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
|
||||
namespace ImageRecognitionCS
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides application-specific behavior to supplement the default Application class.
|
||||
/// </summary>
|
||||
sealed partial class App : Application
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the singleton application object. This is the first line of authored code
|
||||
/// executed, and as such is the logical equivalent of main() or WinMain().
|
||||
/// </summary>
|
||||
public App()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.Suspending += OnSuspending;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the application is launched normally by the end user. Other entry points
|
||||
/// will be used such as when the application is launched to open a specific file.
|
||||
/// </summary>
|
||||
/// <param name="e">Details about the launch request and process.</param>
|
||||
protected override void OnLaunched(LaunchActivatedEventArgs e)
|
||||
{
|
||||
Frame rootFrame = Window.Current.Content as Frame;
|
||||
|
||||
// Do not repeat app initialization when the Window already has content,
|
||||
// just ensure that the window is active
|
||||
if (rootFrame == null)
|
||||
{
|
||||
// Create a Frame to act as the navigation context and navigate to the first page
|
||||
rootFrame = new Frame();
|
||||
|
||||
rootFrame.NavigationFailed += OnNavigationFailed;
|
||||
|
||||
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
|
||||
{
|
||||
//TODO: Load state from previously suspended application
|
||||
}
|
||||
|
||||
// Place the frame in the current Window
|
||||
Window.Current.Content = rootFrame;
|
||||
}
|
||||
|
||||
if (e.PrelaunchActivated == false)
|
||||
{
|
||||
if (rootFrame.Content == null)
|
||||
{
|
||||
// When the navigation stack isn't restored navigate to the first page,
|
||||
// configuring the new page by passing required information as a navigation
|
||||
// parameter
|
||||
rootFrame.Navigate(typeof(MainPage), e.Arguments);
|
||||
}
|
||||
// Ensure the current window is active
|
||||
Window.Current.Activate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when Navigation to a certain page fails
|
||||
/// </summary>
|
||||
/// <param name="sender">The Frame which failed navigation</param>
|
||||
/// <param name="e">Details about the navigation failure</param>
|
||||
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
|
||||
{
|
||||
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when application execution is being suspended. Application state is saved
|
||||
/// without knowing whether the application will be terminated or resumed with the contents
|
||||
/// of memory still intact.
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the suspend request.</param>
|
||||
/// <param name="e">Details about the suspend request.</param>
|
||||
private void OnSuspending(object sender, SuspendingEventArgs e)
|
||||
{
|
||||
var deferral = e.SuspendingOperation.GetDeferral();
|
||||
//TODO: Save application state and stop any background activity
|
||||
deferral.Complete();
|
||||
}
|
||||
}
|
||||
}
|
Двоичные данные
Examples/Evaluation/UWPImageRecognition/App/Assets/LockScreenLogo.scale-200.png
Normal file
После Ширина: | Высота: | Размер: 1.4 KiB |
Двоичные данные
Examples/Evaluation/UWPImageRecognition/App/Assets/SplashScreen.scale-200.png
Normal file
После Ширина: | Высота: | Размер: 7.5 KiB |
Двоичные данные
Examples/Evaluation/UWPImageRecognition/App/Assets/Square150x150Logo.scale-200.png
Normal file
После Ширина: | Высота: | Размер: 2.9 KiB |
Двоичные данные
Examples/Evaluation/UWPImageRecognition/App/Assets/Square44x44Logo.scale-200.png
Normal file
После Ширина: | Высота: | Размер: 1.6 KiB |
Двоичные данные
Examples/Evaluation/UWPImageRecognition/App/Assets/Square44x44Logo.targetsize-24_altform-unplated.png
Normal file
После Ширина: | Высота: | Размер: 1.2 KiB |
После Ширина: | Высота: | Размер: 1.4 KiB |
Двоичные данные
Examples/Evaluation/UWPImageRecognition/App/Assets/Wide310x150Logo.scale-200.png
Normal file
После Ширина: | Высота: | Размер: 3.1 KiB |
После Ширина: | Высота: | Размер: 49 KiB |
После Ширина: | Высота: | Размер: 46 KiB |
|
@ -0,0 +1,147 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<UsingTask TaskName="DownloadFile" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll">
|
||||
<ParameterGroup>
|
||||
<Url ParameterType="System.String" Required="true" />
|
||||
<File ParameterType="System.String" Required="false" />
|
||||
<OutputFolder ParameterType="System.String" Required="false" />
|
||||
</ParameterGroup>
|
||||
<Task>
|
||||
<Using Namespace="System.Web" />
|
||||
<Code Type="Fragment" Language="cs"><![CDATA[
|
||||
var localPath = (OutputFolder != null ? OutputFolder + "/" : "") + (File ?? System.IO.Path.GetFileName(new Uri(Url).LocalPath));
|
||||
if(!System.IO.File.Exists(localPath)) {
|
||||
using (var client = new System.Net.WebClient())
|
||||
{
|
||||
client.DownloadFile(Url, localPath);
|
||||
}
|
||||
}
|
||||
]]></Code>
|
||||
</Task>
|
||||
</UsingTask>
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x64</Platform>
|
||||
<ProjectGuid>{AE11A2D5-D085-4345-8057-40079BA8DE1B}</ProjectGuid>
|
||||
<OutputType>AppContainerExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ImageRecognitionApp</RootNamespace>
|
||||
<AssemblyName>ImageRecognitionApp</AssemblyName>
|
||||
<DefaultLanguage>en-US</DefaultLanguage>
|
||||
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
|
||||
<TargetPlatformVersion>10.0.14393.0</TargetPlatformVersion>
|
||||
<TargetPlatformMinVersion>10.0.10586.0</TargetPlatformMinVersion>
|
||||
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<WindowsXamlEnableOverview>true</WindowsXamlEnableOverview>
|
||||
<PackageCertificateKeyFile>ImageRecognitionCS_TemporaryKey.pfx</PackageCertificateKeyFile>
|
||||
<AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
|
||||
<AppxBundle>Always</AppxBundle>
|
||||
<AppxBundlePlatforms>x64</AppxBundlePlatforms>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included -->
|
||||
<Content Include="Assets\imagenet1000_clsid.txt">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Assets\ResNet18_ImageNet_CNTK.model">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="project.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ImageRecognizerDriver.cs" />
|
||||
<Compile Include="MainPage.xaml.cs">
|
||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AppxManifest Include="Package.appxmanifest">
|
||||
<SubType>Designer</SubType>
|
||||
</AppxManifest>
|
||||
<Content Include="ImageRecognitionCS_TemporaryKey.pfx" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Assets\broccoli.jpg" />
|
||||
<Content Include="Assets\cauliflower.jpg" />
|
||||
<Content Include="Properties\Default.rd.xml" />
|
||||
<Content Include="Assets\LockScreenLogo.scale-200.png" />
|
||||
<Content Include="Assets\SplashScreen.scale-200.png" />
|
||||
<Content Include="Assets\Square150x150Logo.scale-200.png" />
|
||||
<Content Include="Assets\Square44x44Logo.scale-200.png" />
|
||||
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
|
||||
<Content Include="Assets\StoreLogo.png" />
|
||||
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<CNTKBinSuffix>
|
||||
</CNTKBinSuffix>
|
||||
<CNTKBinSuffix Condition="'$(Configuration)' == 'Debug'">d</CNTKBinSuffix>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="..\$(Platform)\$(Configuration)\ImageRecognizerLib\Cntk.Core_app-2.1$(CNTKBinSuffix).dll">
|
||||
<DeploymentContent>true</DeploymentContent>
|
||||
</Content>
|
||||
<Content Include="..\$(Platform)\$(Configuration)\ImageRecognizerLib\Cntk.Math_app-2.1$(CNTKBinSuffix).dll">
|
||||
<DeploymentContent>true</DeploymentContent>
|
||||
</Content>
|
||||
<Content Include="..\$(Platform)\$(Configuration)\ImageRecognizerLib\libopenblas.dll">
|
||||
<DeploymentContent>true</DeploymentContent>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="App.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Page Include="MainPage.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ImageRecognizerLib\ImageRecognizerLib.vcxproj">
|
||||
<Project>{2c7af00a-703a-4521-974d-7f4e47f92a03}</Project>
|
||||
<Name>ImageRecognizerLib</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
|
||||
<Target Name="BeforeBuild">
|
||||
<!-- Model file is downloaded from a public location before build -->
|
||||
<DownloadFile Url="https://www.cntk.ai/Models/CNTK_Pretrained/ResNet18_ImageNet_CNTK.model" OutputFolder="Assets" />
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
</Project>
|
Двоичные данные
Examples/Evaluation/UWPImageRecognition/App/ImageRecognitionCS_TemporaryKey.pfx
Normal file
|
@ -0,0 +1,113 @@
|
|||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
|
||||
//
|
||||
|
||||
using ImageRecognitionLib;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Graphics.Imaging;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.Pickers;
|
||||
|
||||
namespace ImageRecognitionUtils
|
||||
{
|
||||
interface IImageRecognizerConsole
|
||||
{
|
||||
void ShowText(string text);
|
||||
void ShowProgress(bool progress);
|
||||
}
|
||||
|
||||
class ImageRecognizerDriver
|
||||
{
|
||||
IImageRecognizerConsole console;
|
||||
CNTKImageRecognizer cntkRecognizer;
|
||||
|
||||
public ImageRecognizerDriver(IImageRecognizerConsole console)
|
||||
{
|
||||
this.console = console;
|
||||
}
|
||||
|
||||
public async Task Start()
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
console.ShowText("Loading CNTK Model... ");
|
||||
console.ShowProgress(true);
|
||||
|
||||
try
|
||||
{
|
||||
this.cntkRecognizer = await CNTKImageRecognizer.Create("Assets\\ResNet18_ImageNet_CNTK.model", "Assets\\imagenet1000_clsid.txt");
|
||||
sw.Stop();
|
||||
console.ShowText($"Elapsed time: {sw.ElapsedMilliseconds} ms");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
console.ShowText($"error: {ex.Message}");
|
||||
sw.Stop();
|
||||
}
|
||||
console.ShowProgress(false);
|
||||
}
|
||||
|
||||
public async Task PickAndRecognizeImage()
|
||||
{
|
||||
var picker = new FileOpenPicker();
|
||||
picker.ViewMode = PickerViewMode.Thumbnail;
|
||||
picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
|
||||
picker.FileTypeFilter.Add(".jpg");
|
||||
var file = await picker.PickSingleFileAsync();
|
||||
if (file != null)
|
||||
{
|
||||
console.ShowProgress(true);
|
||||
try
|
||||
{
|
||||
await RecognizeFile(file);
|
||||
}
|
||||
finally
|
||||
{
|
||||
console.ShowProgress(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RecognizeFile(StorageFile file)
|
||||
{
|
||||
var fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
|
||||
|
||||
var decoder = await BitmapDecoder.CreateAsync(fileStream);
|
||||
|
||||
uint sHeight = cntkRecognizer.GetRequiredHeight();
|
||||
uint sWidth = cntkRecognizer.GetRequiredWidth();
|
||||
|
||||
BitmapTransform transform = new BitmapTransform()
|
||||
{
|
||||
ScaledHeight = sHeight,
|
||||
ScaledWidth = sWidth
|
||||
};
|
||||
|
||||
PixelDataProvider pixelData = await decoder.GetPixelDataAsync(
|
||||
BitmapPixelFormat.Rgba8,
|
||||
BitmapAlphaMode.Straight,
|
||||
transform,
|
||||
ExifOrientationMode.RespectExifOrientation,
|
||||
ColorManagementMode.DoNotColorManage);
|
||||
|
||||
var data = pixelData.DetachPixelData();
|
||||
var sw = Stopwatch.StartNew();
|
||||
|
||||
string objectName = "?";
|
||||
try
|
||||
{
|
||||
objectName = await cntkRecognizer.RecognizeObjectAsync(data);
|
||||
}
|
||||
catch
|
||||
{
|
||||
objectName = "error";
|
||||
}
|
||||
|
||||
sw.Stop();
|
||||
|
||||
console.ShowText(String.Format("\n{0} -> {1}. Elapsed time: {2} ms", file.Name, objectName, sw.ElapsedMilliseconds));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<Page
|
||||
x:Class="ImageRecognitionCS.MainPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:ImageRecognitionCS"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" RequestedTheme="Dark">
|
||||
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="10,10,10,10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row ="0" x:Name="text" Margin="10" TextWrapping="Wrap" Text="" HorizontalAlignment="Left" FontSize="20" />
|
||||
<Button Grid.Row ="1" x:Name="cntkPickButton" Height="40" Content="Pick Image" HorizontalAlignment="Left" VerticalAlignment="Top" Click="CNTKButton_Click"/>
|
||||
<ProgressRing Grid.Row ="1" x:Name="progress" Height="40" Width="40" HorizontalAlignment="Left" Margin="100,00,0,0" VerticalAlignment="Top"/>
|
||||
<TextBlock Grid.Row ="2" Margin="10" TextWrapping="Wrap" Text="(Hint: some sample images are located in the Assets folder)" HorizontalAlignment="Left" FontSize="14" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Page>
|
|
@ -0,0 +1,42 @@
|
|||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using ImageRecognitionUtils;
|
||||
|
||||
namespace ImageRecognitionCS
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty page that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
public sealed partial class MainPage : Page, IImageRecognizerConsole
|
||||
{
|
||||
ImageRecognizerDriver driver;
|
||||
|
||||
void IImageRecognizerConsole.ShowText(string text)
|
||||
{
|
||||
this.text.Text += text;
|
||||
}
|
||||
|
||||
void IImageRecognizerConsole.ShowProgress(bool progress)
|
||||
{
|
||||
this.progress.IsActive = progress;
|
||||
this.cntkPickButton.IsEnabled = !progress;
|
||||
}
|
||||
|
||||
public MainPage()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.driver = new ImageRecognizerDriver(this);
|
||||
var t = this.driver.Start();
|
||||
}
|
||||
|
||||
private async void CNTKButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
await driver.PickAndRecognizeImage();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp">
|
||||
<Identity Name="73fcf8ed-2ba5-43af-91fa-e0727f20ff30" Publisher="CN=arturl" Version="1.0.0.0" />
|
||||
<mp:PhoneIdentity PhoneProductId="73fcf8ed-2ba5-43af-91fa-e0727f20ff30" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
|
||||
<Properties>
|
||||
<DisplayName>ImageRecognitionCS</DisplayName>
|
||||
<PublisherDisplayName>arturl</PublisherDisplayName>
|
||||
<Logo>Assets\StoreLogo.png</Logo>
|
||||
</Properties>
|
||||
<Dependencies>
|
||||
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
|
||||
</Dependencies>
|
||||
<Resources>
|
||||
<Resource Language="x-generate" />
|
||||
</Resources>
|
||||
<Applications>
|
||||
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="ImageRecognitionCS.App">
|
||||
<uap:VisualElements DisplayName="CNTK ImageRecognition UWP Sample" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="CNTK ImageRecognition UWP Sample" BackgroundColor="transparent">
|
||||
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png">
|
||||
</uap:DefaultTile>
|
||||
<uap:SplashScreen Image="Assets\SplashScreen.png" />
|
||||
</uap:VisualElements>
|
||||
</Application>
|
||||
</Applications>
|
||||
<Capabilities>
|
||||
<Capability Name="internetClient" />
|
||||
<uap:Capability Name="picturesLibrary" />
|
||||
</Capabilities>
|
||||
</Package>
|
|
@ -0,0 +1,29 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("CNTKImageRecognitionApp")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("CNTKImageRecognitionApp")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: ComVisible(false)]
|
|
@ -0,0 +1,31 @@
|
|||
<!--
|
||||
This file contains Runtime Directives used by .NET Native. The defaults here are suitable for most
|
||||
developers. However, you can modify these parameters to modify the behavior of the .NET Native
|
||||
optimizer.
|
||||
|
||||
Runtime Directives are documented at https://go.microsoft.com/fwlink/?LinkID=391919
|
||||
|
||||
To fully enable reflection for App1.MyClass and all of its public/private members
|
||||
<Type Name="App1.MyClass" Dynamic="Required All"/>
|
||||
|
||||
To enable dynamic creation of the specific instantiation of AppClass<T> over System.Int32
|
||||
<TypeInstantiation Name="App1.AppClass" Arguments="System.Int32" Activate="Required Public" />
|
||||
|
||||
Using the Namespace directive to apply reflection policy to all the types in a particular namespace
|
||||
<Namespace Name="DataClasses.ViewModels" Seralize="All" />
|
||||
-->
|
||||
|
||||
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
|
||||
<Application>
|
||||
<!--
|
||||
An Assembly element with Name="*Application*" applies to all assemblies in
|
||||
the application package. The asterisks are not wildcards.
|
||||
-->
|
||||
<Assembly Name="*Application*" Dynamic="Required All" />
|
||||
|
||||
|
||||
<!-- Add your application specific runtime directives here. -->
|
||||
|
||||
|
||||
</Application>
|
||||
</Directives>
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2"
|
||||
},
|
||||
"frameworks": {
|
||||
"uap10.0": {}
|
||||
},
|
||||
"runtimes": {
|
||||
"win10-arm": {},
|
||||
"win10-arm-aot": {},
|
||||
"win10-x86": {},
|
||||
"win10-x86-aot": {},
|
||||
"win10-x64": {},
|
||||
"win10-x64-aot": {}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26228.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageRecognitionApp", "App\ImageRecognitionApp.csproj", "{AE11A2D5-D085-4345-8057-40079BA8DE1B}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ImageRecognizerLib", "ImageRecognizerLib\ImageRecognizerLib.vcxproj", "{2C7AF00A-703A-4521-974D-7F4E47F92A03}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{AE11A2D5-D085-4345-8057-40079BA8DE1B}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{AE11A2D5-D085-4345-8057-40079BA8DE1B}.Debug|x64.Build.0 = Debug|x64
|
||||
{AE11A2D5-D085-4345-8057-40079BA8DE1B}.Debug|x64.Deploy.0 = Debug|x64
|
||||
{AE11A2D5-D085-4345-8057-40079BA8DE1B}.Release|x64.ActiveCfg = Release|x64
|
||||
{AE11A2D5-D085-4345-8057-40079BA8DE1B}.Release|x64.Build.0 = Release|x64
|
||||
{AE11A2D5-D085-4345-8057-40079BA8DE1B}.Release|x64.Deploy.0 = Release|x64
|
||||
{2C7AF00A-703A-4521-974D-7F4E47F92A03}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{2C7AF00A-703A-4521-974D-7F4E47F92A03}.Debug|x64.Build.0 = Debug|x64
|
||||
{2C7AF00A-703A-4521-974D-7F4E47F92A03}.Release|x64.ActiveCfg = Release|x64
|
||||
{2C7AF00A-703A-4521-974D-7F4E47F92A03}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,127 @@
|
|||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
|
||||
//
|
||||
|
||||
#include "pch.h"
|
||||
#include "CNTKImageRecognizer.h"
|
||||
|
||||
using namespace ImageRecognitionLib;
|
||||
using namespace Platform;
|
||||
using namespace Microsoft::MSR::CNTK;
|
||||
|
||||
#include "utils.inl"
|
||||
|
||||
std::wstring CNTKImageRecognizer::classifyImage(const uint8_t* image_data, size_t image_data_len)
|
||||
{
|
||||
// Prepare the input vector and convert it to the correct color scheme (BBB ... GGG ... RRR)
|
||||
size_t resized_image_data_len = GetRequiredWidth() * GetRequiredHeight() * GetRequiredChannels();
|
||||
std::vector<uint8_t> image_data_array(resized_image_data_len);
|
||||
memcpy_s(image_data_array.data(), image_data_len, image_data, resized_image_data_len);
|
||||
std::vector<float> rawFeatures = get_features(image_data_array.data(), GetRequiredWidth(), GetRequiredHeight());
|
||||
|
||||
// Prepare the input layer of the computation graph
|
||||
// Most of the work is putting rawFeatures into CNTK's data representation format
|
||||
std::unordered_map<CNTK::Variable, CNTK::ValuePtr> inputLayer = {};
|
||||
|
||||
auto features = CNTK::Value::CreateBatch<float>(inputShape, rawFeatures, evalDevice, false);
|
||||
inputVar = model->Arguments()[0];
|
||||
inputLayer.insert({ inputVar, features });
|
||||
|
||||
// Prepare the output layer of the computation graph
|
||||
// For this a NULL blob will be placed into the output layer
|
||||
// so that CNTK can place its own datastructure there
|
||||
std::unordered_map<CNTK::Variable, CNTK::ValuePtr> outputLayer = {};
|
||||
CNTK::Variable outputVar = model->Output();
|
||||
CNTK::NDShape outputShape = outputVar.Shape();
|
||||
size_t possibleClasses = outputShape.Dimensions()[0];
|
||||
|
||||
std::vector<float> rawOutputs(possibleClasses);
|
||||
auto outputs = CNTK::Value::CreateBatch<float>(outputShape, rawOutputs, evalDevice, false);
|
||||
outputLayer.insert({ outputVar, NULL });
|
||||
|
||||
// Evaluate the image and extract the results (which will be a [ #classes x 1 x 1 ] tensor)
|
||||
model->Evaluate(inputLayer, outputLayer, evalDevice);
|
||||
|
||||
CNTK::ValuePtr outputVal = outputLayer[outputVar];
|
||||
std::vector<std::vector<float>> resultsWrapper;
|
||||
std::vector<float> results;
|
||||
|
||||
outputVal.get()->CopyVariableValueTo(outputVar, resultsWrapper);
|
||||
results = resultsWrapper[0];
|
||||
|
||||
// Map the results to the string representation of the class
|
||||
int64_t image_class = find_class(results);
|
||||
return classNames.at(image_class);
|
||||
}
|
||||
|
||||
uint32_t CNTKImageRecognizer::GetRequiredWidth()
|
||||
{
|
||||
return (uint32_t)inputShape[0];
|
||||
}
|
||||
|
||||
uint32_t CNTKImageRecognizer::GetRequiredHeight()
|
||||
{
|
||||
return (uint32_t)inputShape[1];
|
||||
}
|
||||
|
||||
uint32_t CNTKImageRecognizer::GetRequiredChannels()
|
||||
{
|
||||
return (uint32_t)inputShape[2];
|
||||
}
|
||||
|
||||
CNTKImageRecognizer::CNTKImageRecognizer(String^ modelFile, Platform::String^ classesFile)
|
||||
{
|
||||
std::wstring w_str = std::wstring(modelFile->Data());
|
||||
model = CNTK::Function::Load(w_str, evalDevice);
|
||||
|
||||
// List out all the outputs and their indexes
|
||||
// The probability output is usually listed as 'z' and is
|
||||
// usually the last layer
|
||||
size_t z_index = model->Outputs().size() - 1;
|
||||
|
||||
// Modify the in-memory model to use the z layer as the actual output
|
||||
auto z_layer = model->Outputs()[z_index];
|
||||
model = CNTK::Combine({ z_layer.Owner() });
|
||||
|
||||
// Extract information about what the model accepts as input
|
||||
inputVar = model->Arguments()[0];
|
||||
// Shape contains image [width, height, depth] respectively
|
||||
inputShape = inputVar.Shape();
|
||||
|
||||
// Load the class names
|
||||
w_str = std::wstring(classesFile->Data());
|
||||
classNames = read_class_names(w_str);
|
||||
}
|
||||
|
||||
Windows::Foundation::IAsyncOperation<CNTKImageRecognizer^>^ CNTKImageRecognizer::Create(Platform::String^ modelFile, Platform::String^ classesFile)
|
||||
{
|
||||
return concurrency::create_async([=] {
|
||||
return ref new CNTKImageRecognizer(modelFile, classesFile);
|
||||
});
|
||||
}
|
||||
|
||||
Windows::Foundation::IAsyncOperation<Platform::String^>^ CNTKImageRecognizer::RecognizeObjectAsync(const Platform::Array<byte>^ bytes)
|
||||
{
|
||||
return concurrency::create_async([=] {
|
||||
// The data we've got is in RGBA format. We should convert it to BGR
|
||||
std::vector<uint8_t> rgb((bytes->Length / 4) * 3);
|
||||
uint8_t* rgba = bytes->Data;
|
||||
|
||||
uint32_t i = 0;
|
||||
for (uint32_t j = 0; j < bytes->Length;)
|
||||
{
|
||||
uint32_t r = j++; // R
|
||||
uint32_t g = j++; // G
|
||||
uint32_t b = j++; // B
|
||||
uint32_t a = j++; // A (skipped)
|
||||
|
||||
rgb[i++] = rgba[r];
|
||||
rgb[i++] = rgba[g];
|
||||
rgb[i++] = rgba[b];
|
||||
}
|
||||
|
||||
auto image_class = classifyImage(rgb.data(), rgb.size());
|
||||
return ref new Platform::String(image_class.c_str());
|
||||
});
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CNTKLibrary.h"
|
||||
|
||||
namespace ImageRecognitionLib
|
||||
{
|
||||
public ref class CNTKImageRecognizer sealed
|
||||
{
|
||||
CNTK::DeviceDescriptor evalDevice = CNTK::DeviceDescriptor::UseDefaultDevice();
|
||||
CNTK::FunctionPtr model;
|
||||
CNTK::Variable inputVar;
|
||||
CNTK::NDShape inputShape;
|
||||
std::vector<std::wstring> classNames;
|
||||
CNTKImageRecognizer(Platform::String^ modelFile, Platform::String^ classesFile);
|
||||
std::wstring classifyImage(const uint8_t* image_data, size_t image_data_len);
|
||||
|
||||
public:
|
||||
static Windows::Foundation::IAsyncOperation<CNTKImageRecognizer^>^ CNTKImageRecognizer::Create(Platform::String^ modelFile, Platform::String^ classesFile);
|
||||
Windows::Foundation::IAsyncOperation<Platform::String^>^ RecognizeObjectAsync(const Platform::Array<byte>^ bytes);
|
||||
uint32_t GetRequiredWidth();
|
||||
uint32_t GetRequiredHeight();
|
||||
uint32_t GetRequiredChannels();
|
||||
};
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{2C7AF00A-703A-4521-974D-7F4E47F92A03}</ProjectGuid>
|
||||
<Keyword>WindowsRuntimeComponent</Keyword>
|
||||
<RootNamespace>ImageRecognitionLib</RootNamespace>
|
||||
<DefaultLanguage>en-US</DefaultLanguage>
|
||||
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
|
||||
<AppContainerApplication>true</AppContainerApplication>
|
||||
<ApplicationType>Windows Store</ApplicationType>
|
||||
<WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
|
||||
<WindowsTargetPlatformMinVersion>10.0.10586.0</WindowsTargetPlatformMinVersion>
|
||||
<ApplicationTypeRevision>10.0</ApplicationTypeRevision>
|
||||
<ProjectName>ImageRecognizerLib</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
<PropertyGroup>
|
||||
<GenerateManifest>false</GenerateManifest>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PreprocessorDefinitions>NOMINMAX;_WINRT_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
|
||||
<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
|
||||
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
|
||||
<DisableSpecificWarnings>28204</DisableSpecificWarnings>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
<AdditionalDependencies>WindowsApp.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<GenerateDebugInformation>DebugFastLink</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PreprocessorDefinitions>NOMINMAX;_WINRT_DLL;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
|
||||
<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
|
||||
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
|
||||
<DisableSpecificWarnings>28204</DisableSpecificWarnings>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
<AdditionalDependencies>WindowsApp.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="CNTKImageRecognizer.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="CNTKImageRecognizer.cpp" />
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<None Include="utils.inl" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="..\packages\CNTK.UWP.CPUOnly.2.1.0\build\native\CNTK.UWP.CPUOnly.targets" Condition="Exists('..\packages\CNTK.UWP.CPUOnly.2.1.0\build\native\CNTK.UWP.CPUOnly.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('..\packages\CNTK.UWP.CPUOnly.2.1.0\build\native\CNTK.UWP.CPUOnly.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CNTK.UWP.CPUOnly.2.1.0\build\native\CNTK.UWP.CPUOnly.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Resources">
|
||||
<UniqueIdentifier>db3762fa-8b14-4981-83ba-3ce94d06ad0e</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="pch.cpp" />
|
||||
<ClCompile Include="CNTKImageRecognizer.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.h" />
|
||||
<ClInclude Include="CNTKImageRecognizer.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<None Include="utils.inl" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="CNTK.UWP.CPUOnly" version="2.1.0" targetFramework="native" />
|
||||
</packages>
|
|
@ -0,0 +1 @@
|
|||
#include "pch.h"
|
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <collection.h>
|
||||
#include <ppltasks.h>
|
||||
#include <string>
|
||||
#include <experimental/filesystem>
|
||||
#include <chrono>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <locale>
|
||||
#include <codecvt>
|
||||
#include <string>
|
|
@ -0,0 +1,63 @@
|
|||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
|
||||
//
|
||||
|
||||
inline std::vector<float> get_features(uint8_t* image_data_array, uint32_t reqWidth, uint32_t reqHeight)
|
||||
{
|
||||
uint32_t size = reqWidth * reqHeight * 3;
|
||||
|
||||
// BGR conversion to BBB..GGG..RRR
|
||||
std::vector<float> featuresLocal;
|
||||
|
||||
// convert BGR array to BBB...GGG...RRR array
|
||||
for (uint32_t c = 0; c < 3; c++) {
|
||||
for (uint32_t p = c; p < size; p = p + 3)
|
||||
{
|
||||
float v = image_data_array[p];
|
||||
featuresLocal.push_back(v);
|
||||
}
|
||||
}
|
||||
return featuresLocal;
|
||||
}
|
||||
|
||||
inline int64_t find_class(std::vector<float> outputs)
|
||||
{
|
||||
return std::distance(outputs.begin(), std::max_element(outputs.begin(), outputs.end()));
|
||||
}
|
||||
|
||||
inline bool does_file_exist(std::wstring file_name)
|
||||
{
|
||||
return std::experimental::filesystem::exists(file_name);
|
||||
}
|
||||
|
||||
inline std::wstring strtowstr(const std::string& str)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
|
||||
return converter.from_bytes(str);
|
||||
}
|
||||
|
||||
inline std::string wstrtostr(const std::wstring& wstr)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
|
||||
return converter.to_bytes(wstr);
|
||||
}
|
||||
|
||||
inline std::vector<std::wstring> read_class_names(const std::wstring filename)
|
||||
{
|
||||
std::vector<std::wstring> classNames;
|
||||
std::wifstream fp(filename);
|
||||
if (!fp.is_open())
|
||||
{
|
||||
return classNames;
|
||||
}
|
||||
std::wstring name;
|
||||
while (!fp.eof())
|
||||
{
|
||||
std::getline(fp, name);
|
||||
if (name.length())
|
||||
classNames.push_back(name.substr(name.find(' ') + 1));
|
||||
}
|
||||
fp.close();
|
||||
return classNames;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<Application
|
||||
x:Class="ImageRecognitionCS.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:ImageRecognitionCS"
|
||||
RequestedTheme="Light">
|
||||
|
||||
</Application>
|
|
@ -0,0 +1,100 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.ApplicationModel.Activation;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Controls.Primitives;
|
||||
using Windows.UI.Xaml.Data;
|
||||
using Windows.UI.Xaml.Input;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
|
||||
namespace ImageRecognitionCS
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides application-specific behavior to supplement the default Application class.
|
||||
/// </summary>
|
||||
sealed partial class App : Application
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the singleton application object. This is the first line of authored code
|
||||
/// executed, and as such is the logical equivalent of main() or WinMain().
|
||||
/// </summary>
|
||||
public App()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.Suspending += OnSuspending;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the application is launched normally by the end user. Other entry points
|
||||
/// will be used such as when the application is launched to open a specific file.
|
||||
/// </summary>
|
||||
/// <param name="e">Details about the launch request and process.</param>
|
||||
protected override void OnLaunched(LaunchActivatedEventArgs e)
|
||||
{
|
||||
Frame rootFrame = Window.Current.Content as Frame;
|
||||
|
||||
// Do not repeat app initialization when the Window already has content,
|
||||
// just ensure that the window is active
|
||||
if (rootFrame == null)
|
||||
{
|
||||
// Create a Frame to act as the navigation context and navigate to the first page
|
||||
rootFrame = new Frame();
|
||||
|
||||
rootFrame.NavigationFailed += OnNavigationFailed;
|
||||
|
||||
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
|
||||
{
|
||||
//TODO: Load state from previously suspended application
|
||||
}
|
||||
|
||||
// Place the frame in the current Window
|
||||
Window.Current.Content = rootFrame;
|
||||
}
|
||||
|
||||
if (e.PrelaunchActivated == false)
|
||||
{
|
||||
if (rootFrame.Content == null)
|
||||
{
|
||||
// When the navigation stack isn't restored navigate to the first page,
|
||||
// configuring the new page by passing required information as a navigation
|
||||
// parameter
|
||||
rootFrame.Navigate(typeof(MainPage), e.Arguments);
|
||||
}
|
||||
// Ensure the current window is active
|
||||
Window.Current.Activate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when Navigation to a certain page fails
|
||||
/// </summary>
|
||||
/// <param name="sender">The Frame which failed navigation</param>
|
||||
/// <param name="e">Details about the navigation failure</param>
|
||||
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
|
||||
{
|
||||
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when application execution is being suspended. Application state is saved
|
||||
/// without knowing whether the application will be terminated or resumed with the contents
|
||||
/// of memory still intact.
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the suspend request.</param>
|
||||
/// <param name="e">Details about the suspend request.</param>
|
||||
private void OnSuspending(object sender, SuspendingEventArgs e)
|
||||
{
|
||||
var deferral = e.SuspendingOperation.GetDeferral();
|
||||
//TODO: Save application state and stop any background activity
|
||||
deferral.Complete();
|
||||
}
|
||||
}
|
||||
}
|
После Ширина: | Высота: | Размер: 1.4 KiB |
После Ширина: | Высота: | Размер: 7.5 KiB |
После Ширина: | Высота: | Размер: 2.9 KiB |
После Ширина: | Высота: | Размер: 1.6 KiB |
После Ширина: | Высота: | Размер: 1.2 KiB |
Двоичные данные
Tests/EndToEndTests/EvalClientTests/UWPImageRecognitionTest/ImageRecognitionAppCS/Assets/StoreLogo.png
Normal file
После Ширина: | Высота: | Размер: 1.4 KiB |
После Ширина: | Высота: | Размер: 3.1 KiB |
|
@ -0,0 +1,137 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Import Project="$(SolutionDir)\CNTK.Common.props" />
|
||||
<UsingTask TaskName="DownloadFile" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll">
|
||||
<ParameterGroup>
|
||||
<Url ParameterType="System.String" Required="true" />
|
||||
<File ParameterType="System.String" Required="false" />
|
||||
<OutputFolder ParameterType="System.String" Required="false" />
|
||||
</ParameterGroup>
|
||||
<Task>
|
||||
<Using Namespace="System.Web" />
|
||||
<Code Type="Fragment" Language="cs"><![CDATA[
|
||||
var localPath = (OutputFolder != null ? OutputFolder + "/" : "") + (File ?? System.IO.Path.GetFileName(new Uri(Url).LocalPath));
|
||||
if(!System.IO.File.Exists(localPath)) {
|
||||
using (var client = new System.Net.WebClient())
|
||||
{
|
||||
client.DownloadFile(Url, localPath);
|
||||
}
|
||||
}
|
||||
]]></Code>
|
||||
</Task>
|
||||
</UsingTask>
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug_UWP</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x64</Platform>
|
||||
<ProjectGuid>{EA6DC625-7AD7-44A8-BDE9-4620D01B3AA5}</ProjectGuid>
|
||||
<OutputType>AppContainerExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ImageRecognitionAppCS</RootNamespace>
|
||||
<AssemblyName>ImageRecognitionAppCS</AssemblyName>
|
||||
<DefaultLanguage>en-US</DefaultLanguage>
|
||||
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
|
||||
<TargetPlatformVersion>10.0.14393.0</TargetPlatformVersion>
|
||||
<TargetPlatformMinVersion>10.0.10586.0</TargetPlatformMinVersion>
|
||||
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<PackageCertificateKeyFile>ImageRecognitionAppCS_TemporaryKey.pfx</PackageCertificateKeyFile>
|
||||
<CNTKRoot>$(RepoRootPath)</CNTKRoot>
|
||||
<AppSrcDir>$(CNTKRoot)\Examples\Evaluation\UWPImageRecognition\App</AppSrcDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug_UWP|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>$(OutDir)</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release_UWP|x64'">
|
||||
<OutputPath>$(OutDir)</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included -->
|
||||
<Content Include="Assets\imagenet1000_clsid.txt" />
|
||||
<Content Include="Assets\ResNet18_ImageNet_CNTK.model">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Include="project.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="MainPage.xaml.cs">
|
||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="$(AppSrcDir)\ImageRecognizerDriver.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AppxManifest Include="Package.appxmanifest">
|
||||
<SubType>Designer</SubType>
|
||||
</AppxManifest>
|
||||
<None Include="ImageRecognitionAppCS_TemporaryKey.pfx" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<CNTKBinSuffix/>
|
||||
<CNTKBinSuffix Condition="$(DebugBuild)">d</CNTKBinSuffix>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Properties\Default.rd.xml" />
|
||||
<Content Include="Assets\LockScreenLogo.scale-200.png" />
|
||||
<Content Include="Assets\SplashScreen.scale-200.png" />
|
||||
<Content Include="Assets\Square150x150Logo.scale-200.png" />
|
||||
<Content Include="Assets\Square44x44Logo.scale-200.png" />
|
||||
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
|
||||
<Content Include="Assets\StoreLogo.png" />
|
||||
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
|
||||
<Content Include="$(CNTKRoot)\$(Platform)\$(Configuration)\Cntk.Core_app-2.1$(CNTKBinSuffix).dll">
|
||||
<DeploymentContent>true</DeploymentContent>
|
||||
</Content>
|
||||
<Content Include="$(CNTKRoot)\$(Platform)\$(Configuration)\Cntk.Math_app-2.1$(CNTKBinSuffix).dll">
|
||||
<DeploymentContent>true</DeploymentContent>
|
||||
</Content>
|
||||
<Content Include="$(CNTKRoot)\$(Platform)\$(Configuration)\libopenblas.dll">
|
||||
<DeploymentContent>true</DeploymentContent>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="App.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Page Include="MainPage.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ImageRecognizerLib\ImageRecognizerLib.vcxproj">
|
||||
<Project>{c5e944ba-a7c4-482f-be01-077a7dfc159c}</Project>
|
||||
<Name>ImageRecognizerLib</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
|
||||
<Target Name="BeforeBuild">
|
||||
<!-- Model file is downloaded from a public location before build -->
|
||||
<DownloadFile Url="https://www.cntk.ai/Models/CNTK_Pretrained/ResNet18_ImageNet_CNTK.model" OutputFolder="Assets" />
|
||||
</Target>
|
||||
</Project>
|
|
@ -0,0 +1,24 @@
|
|||
<Page
|
||||
x:Class="ImageRecognitionCS.MainPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:ImageRecognitionCS"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" RequestedTheme="Dark">
|
||||
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="10,10,10,10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row ="0" x:Name="text" Margin="10" TextWrapping="Wrap" Text="" HorizontalAlignment="Left" FontSize="20" />
|
||||
<Button Grid.Row ="1" x:Name="cntkPickButton" Height="40" Content="Pick Image" HorizontalAlignment="Left" VerticalAlignment="Top" Click="CNTKButton_Click"/>
|
||||
<ProgressRing Grid.Row ="1" x:Name="progress" Height="40" Width="40" HorizontalAlignment="Left" Margin="100,00,0,0" VerticalAlignment="Top"/>
|
||||
<TextBlock Grid.Row ="2" Margin="10" TextWrapping="Wrap" Text="(Hint: some sample images are located in the Assets folder)" HorizontalAlignment="Left" FontSize="14" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Page>
|
|
@ -0,0 +1,42 @@
|
|||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using ImageRecognitionUtils;
|
||||
|
||||
namespace ImageRecognitionCS
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty page that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
public sealed partial class MainPage : Page, IImageRecognizerConsole
|
||||
{
|
||||
ImageRecognizerDriver driver;
|
||||
|
||||
void IImageRecognizerConsole.ShowText(string text)
|
||||
{
|
||||
this.text.Text += text;
|
||||
}
|
||||
|
||||
void IImageRecognizerConsole.ShowProgress(bool progress)
|
||||
{
|
||||
this.progress.IsActive = progress;
|
||||
this.cntkPickButton.IsEnabled = !progress;
|
||||
}
|
||||
|
||||
public MainPage()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.driver = new ImageRecognizerDriver(this);
|
||||
var t = this.driver.Start();
|
||||
}
|
||||
|
||||
private async void CNTKButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
await driver.PickAndRecognizeImage();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<Package
|
||||
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
|
||||
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
|
||||
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
|
||||
IgnorableNamespaces="uap mp">
|
||||
|
||||
<Identity
|
||||
Name="17818944-1829-420e-a994-2aa41adae07d"
|
||||
Publisher="CN=arturl"
|
||||
Version="1.0.0.0" />
|
||||
|
||||
<mp:PhoneIdentity PhoneProductId="17818944-1829-420e-a994-2aa41adae07d" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
||||
|
||||
<Properties>
|
||||
<DisplayName>ImageRecognitionAppCS</DisplayName>
|
||||
<PublisherDisplayName>arturl</PublisherDisplayName>
|
||||
<Logo>Assets\StoreLogo.png</Logo>
|
||||
</Properties>
|
||||
|
||||
<Dependencies>
|
||||
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
|
||||
</Dependencies>
|
||||
|
||||
<Resources>
|
||||
<Resource Language="x-generate"/>
|
||||
</Resources>
|
||||
|
||||
<Applications>
|
||||
<Application Id="App"
|
||||
Executable="$targetnametoken$.exe"
|
||||
EntryPoint="ImageRecognitionAppCS.App">
|
||||
<uap:VisualElements
|
||||
DisplayName="ImageRecognitionAppCS"
|
||||
Square150x150Logo="Assets\Square150x150Logo.png"
|
||||
Square44x44Logo="Assets\Square44x44Logo.png"
|
||||
Description="ImageRecognitionAppCS"
|
||||
BackgroundColor="transparent">
|
||||
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/>
|
||||
<uap:SplashScreen Image="Assets\SplashScreen.png" />
|
||||
</uap:VisualElements>
|
||||
</Application>
|
||||
</Applications>
|
||||
|
||||
<Capabilities>
|
||||
<Capability Name="internetClient" />
|
||||
</Capabilities>
|
||||
</Package>
|
|
@ -0,0 +1,29 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("ImageRecognitionAppCS")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("ImageRecognitionAppCS")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: ComVisible(false)]
|
|
@ -0,0 +1,31 @@
|
|||
<!--
|
||||
This file contains Runtime Directives used by .NET Native. The defaults here are suitable for most
|
||||
developers. However, you can modify these parameters to modify the behavior of the .NET Native
|
||||
optimizer.
|
||||
|
||||
Runtime Directives are documented at http://go.microsoft.com/fwlink/?LinkID=391919
|
||||
|
||||
To fully enable reflection for App1.MyClass and all of its public/private members
|
||||
<Type Name="App1.MyClass" Dynamic="Required All"/>
|
||||
|
||||
To enable dynamic creation of the specific instantiation of AppClass<T> over System.Int32
|
||||
<TypeInstantiation Name="App1.AppClass" Arguments="System.Int32" Activate="Required Public" />
|
||||
|
||||
Using the Namespace directive to apply reflection policy to all the types in a particular namespace
|
||||
<Namespace Name="DataClasses.ViewModels" Seralize="All" />
|
||||
-->
|
||||
|
||||
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
|
||||
<Application>
|
||||
<!--
|
||||
An Assembly element with Name="*Application*" applies to all assemblies in
|
||||
the application package. The asterisks are not wildcards.
|
||||
-->
|
||||
<Assembly Name="*Application*" Dynamic="Required All" />
|
||||
|
||||
|
||||
<!-- Add your application specific runtime directives here. -->
|
||||
|
||||
|
||||
</Application>
|
||||
</Directives>
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2"
|
||||
},
|
||||
"frameworks": {
|
||||
"uap10.0": {}
|
||||
},
|
||||
"runtimes": {
|
||||
"win10-arm": {},
|
||||
"win10-arm-aot": {},
|
||||
"win10-x86": {},
|
||||
"win10-x86-aot": {},
|
||||
"win10-x64": {},
|
||||
"win10-x64-aot": {}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug_UWP|x64">
|
||||
<Configuration>Debug_UWP</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release_UWP|x64">
|
||||
<Configuration>Release_UWP</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{c5e944ba-a7c4-482f-be01-077a7dfc159c}</ProjectGuid>
|
||||
<Keyword>WindowsRuntimeComponent</Keyword>
|
||||
<RootNamespace>ImageRecognitionLib</RootNamespace>
|
||||
<DefaultLanguage>en-US</DefaultLanguage>
|
||||
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
|
||||
<AppContainerApplication>true</AppContainerApplication>
|
||||
<ApplicationType>Windows Store</ApplicationType>
|
||||
<WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
|
||||
<WindowsTargetPlatformMinVersion>10.0.10586.0</WindowsTargetPlatformMinVersion>
|
||||
<ApplicationTypeRevision>10.0</ApplicationTypeRevision>
|
||||
<ProjectName>ImageRecognitionLib</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_UWP|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_UWP|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<Import Project="$(SolutionDir)\CNTK.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup>
|
||||
<GenerateManifest>false</GenerateManifest>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<PreprocessorDefinitions>_WINRT_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
|
||||
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
|
||||
<DisableSpecificWarnings>28204</DisableSpecificWarnings>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)\Source\CNTKv2LibraryDll\API;$(SolutionDir)\Examples\Evaluation\UWPImageRecognition\ImageRecognizerLib;$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release_UWP|x64'">true</CompileAsWinRT>
|
||||
<CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug_UWP|x64'">true</CompileAsWinRT>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
<AdditionalDependencies>Cntk.Core$(OutputSuffix)-$(CntkComponentVersion).lib;WindowsApp.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)$(Platform)\$(Configuration)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="$(SolutionDir)\Examples\Evaluation\UWPImageRecognition\ImageRecognizerLib\CNTKImageRecognizer.cpp" />
|
||||
<None Include="$(SolutionDir)\Examples\Evaluation\UWPImageRecognition\utils.inl" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Resources">
|
||||
<UniqueIdentifier>3abff664-a4cb-460a-9fe4-03e82cd8356e</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="$(SolutionDir)\Examples\Evaluation\UWPImageRecognition\ImageRecognizerLib\CNTKImageRecognizer.cpp" />
|
||||
<ClCompile Include="$(SolutionDir)\Examples\Evaluation\UWPImageRecognition\ImageRecognizerLib\pch.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="$(SolutionDir)$(Platform)\$(Configuration)\Cntk.Core$(OutputSuffix)-$(CntkComponentVersion).dll" />
|
||||
<None Include="$(SolutionDir)$(Platform)\$(Configuration)\Cntk.Math$(OutputSuffix)-$(CntkComponentVersion).dll" />
|
||||
<None Include="$(SolutionDir)$(Platform)\$(Configuration)\libopenblas.dll" />
|
||||
</ItemGroup>
|
||||
</Project>
|