Skip to content

Commit 95690c0

Browse files
Merge pull request #335 from microsoft/user/t-limay/StyleTransfer
StyleTransfer Demo
2 parents 027c094 + b6617d8 commit 95690c0

39 files changed

+2847
-89
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ These generic examples show how to use various models and input feeds with Windo
3838
- **[SqueezeNetObjectDetection\UWP\js](https://github.com/Microsoft/Windows-Machine-Learning/tree/master/Samples/SqueezeNetObjectDetection/UWP/js)**: a UWP Javascript app that uses the SqueezeNet model to detect the predominant object in an image.
3939
- **[SqueezeNetObjectDetection\Desktop\cpp](https://github.com/Microsoft/Windows-Machine-Learning/tree/master/Samples/SqueezeNetObjectDetection/Desktop/cpp)**: a classic desktop C++/WinRT app that uses the SqueezeNet model to detect the predominant object in an image.
4040
- **[SqueezeNetObjectDetection\NETCore\cs](https://github.com/Microsoft/Windows-Machine-Learning/tree/master/Samples/SqueezeNetObjectDetection/Desktop/cpp)**: a .NET Core 2 application that uses the SqueezeNet model to detect the predominant object in an image.
41+
- **[StyleTransfer](https://github.com/Microsoft/Windows-Machine-Learning/tree/master/Samples/StyleTransfer**: a UWP C# app that uses a custom C++ Video Effect to apply style transfer in real-time to videos.
4142
- **[MNIST\UWP\cs](https://github.com/Microsoft/Windows-Machine-Learning/tree/master/Samples/MNIST/Tutorial/cs)**: a UWP C# app that uses the MNIST model to detect handwritten numbers.
4243
- **[MNIST\UWP\cppcx](https://github.com/Microsoft/Windows-Machine-Learning/tree/master/Samples/MNIST/UWP)**: a UWP C++/CX app that uses the MNIST model to detect handwritten numbers.
4344
- **[CustomTensorization](https://github.com/Microsoft/Windows-Machine-Learning/tree/master/Samples/CustomTensorization)**: a Windows Console Application (C++/WinRT) that shows how to do custom tensorization.

Samples/FNSCandyStyleTransfer/UWP/cs/MainPage.xaml

Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -23,94 +23,94 @@ Copyright (C) Microsoft Corporation. All rights reserved.
2323
</Page.Resources>
2424

2525
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
26-
27-
<Grid>
28-
<Grid.RowDefinitions>
29-
<RowDefinition Height="80"/>
30-
<RowDefinition Height="300*"/>
31-
<RowDefinition Height="30"/>
32-
</Grid.RowDefinitions>
33-
34-
<!--Status and result display-->
26+
27+
<Grid>
28+
<Grid.RowDefinitions>
29+
<RowDefinition Height="80"/>
30+
<RowDefinition Height="300*"/>
31+
<RowDefinition Height="30"/>
32+
</Grid.RowDefinitions>
33+
34+
<!--Status and result display-->
3535
<StackPanel x:Name="UIStatusPanel" Background="#BFFFFFFF" VerticalAlignment="Top" Grid.Row="0">
3636
<ContentControl Name="UIModelControls">
37-
<StackPanel Orientation="Horizontal">
38-
<ToggleSwitch Name="UIToggleInferenceDevice"
37+
<StackPanel Orientation="Horizontal">
38+
<ToggleSwitch Name="UIToggleInferenceDevice"
3939
OnContent="GPU"
4040
OffContent="CPU"
4141
IsOn="True"
4242
Toggled="UIToggleInferenceDevice_Toggled"
4343
Margin="10,0,0,0"/>
4444

45-
<ListBox Name="UIStyleList" SelectionChanged="UIStyleList_SelectionChanged">
46-
<ListBox.ItemsPanel>
47-
<ItemsPanelTemplate>
48-
<VirtualizingStackPanel Orientation="Horizontal"/>
49-
</ItemsPanelTemplate>
50-
</ListBox.ItemsPanel>
51-
</ListBox>
45+
<ListBox Name="UIStyleList" SelectionChanged="UIStyleList_SelectionChanged">
46+
<ListBox.ItemsPanel>
47+
<ItemsPanelTemplate>
48+
<VirtualizingStackPanel Orientation="Horizontal"/>
49+
</ItemsPanelTemplate>
50+
</ListBox.ItemsPanel>
51+
</ListBox>
5252

53-
</StackPanel>
54-
</ContentControl>
53+
</StackPanel>
54+
</ContentControl>
5555

5656

57-
<!--Image preview and acquisition control-->
58-
<ContentControl Name="UIImageControls"
57+
<!--Image preview and acquisition control-->
58+
<ContentControl Name="UIImageControls"
5959
VerticalAlignment="Stretch"
6060
HorizontalAlignment="Stretch"
6161
IsEnabled="False">
6262

63-
<StackPanel Orientation="Horizontal">
64-
<Button Name="UIButtonLiveStream"
63+
<StackPanel Orientation="Horizontal">
64+
<Button Name="UIButtonLiveStream"
6565
ToolTipService.ToolTip="Camera preview"
6666
Click="UIButtonLiveStream_Click">
67-
<Button.Content>
68-
<SymbolIcon Symbol="Video"/>
69-
</Button.Content>
70-
</Button>
71-
<Button Name="UIButtonAcquireImage"
67+
<Button.Content>
68+
<SymbolIcon Symbol="Video"/>
69+
</Button.Content>
70+
</Button>
71+
<Button Name="UIButtonAcquireImage"
7272
ToolTipService.ToolTip="Take a photo"
7373
Click="UIButtonAcquireImage_Click">
74-
<Button.Content>
75-
<SymbolIcon Symbol="Camera"/>
76-
</Button.Content>
77-
</Button>
78-
<Button Name="UIButtonFilePick"
74+
<Button.Content>
75+
<SymbolIcon Symbol="Camera"/>
76+
</Button.Content>
77+
</Button>
78+
<Button Name="UIButtonFilePick"
7979
ToolTipService.ToolTip="Select an image from a file"
8080
Click="UIButtonFilePick_Click">
81-
<Button.Content>
82-
<SymbolIcon Symbol="OpenFile"/>
83-
</Button.Content>
84-
</Button>
85-
<Button Name="UIButtonInking"
81+
<Button.Content>
82+
<SymbolIcon Symbol="OpenFile"/>
83+
</Button.Content>
84+
</Button>
85+
<Button Name="UIButtonInking"
8686
ToolTipService.ToolTip="Draw on a canvas"
8787
Click="UIButtonInking_Click">
88-
<Button.Content>
89-
<SymbolIcon Symbol="Edit"/>
90-
</Button.Content>
91-
</Button>
92-
<Button Name="UIButtonSaveImage"
88+
<Button.Content>
89+
<SymbolIcon Symbol="Edit"/>
90+
</Button.Content>
91+
</Button>
92+
<Button Name="UIButtonSaveImage"
9393
ToolTipService.ToolTip="Save the image result to a file"
9494
IsEnabled="false"
9595
VerticalAlignment="Bottom"
9696
Click="UIButtonSaveImage_Click"
9797
Background="#FF939393" >
98-
<Button.Content>
99-
<SymbolIcon Symbol="Save"/>
100-
</Button.Content>
101-
</Button>
98+
<Button.Content>
99+
<SymbolIcon Symbol="Save"/>
100+
</Button.Content>
101+
</Button>
102102

103-
</StackPanel>
104-
</ContentControl>
105-
</StackPanel>
106-
<!--<StackPanel Orientation="Horizontal">-->
103+
</StackPanel>
104+
</ContentControl>
105+
</StackPanel>
106+
<!--<StackPanel Orientation="Horizontal">-->
107107

108108
<!--<Viewbox Stretch="Uniform" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="1">-->
109-
<Grid Grid.Row="1">
110-
<Grid.ColumnDefinitions>
111-
<ColumnDefinition Width="200*"/>
112-
<ColumnDefinition Width="200*"/>
113-
</Grid.ColumnDefinitions>
109+
<Grid Grid.Row="1">
110+
<Grid.ColumnDefinitions>
111+
<ColumnDefinition Width="200*"/>
112+
<ColumnDefinition Width="200*"/>
113+
</Grid.ColumnDefinitions>
114114

115115
<Viewbox Stretch="Uniform">
116116
<StackPanel Name="UIInkControls"
@@ -138,46 +138,46 @@ Copyright (C) Microsoft Corporation. All rights reserved.
138138
</Viewbox>
139139

140140
<!--Camera preview-->
141-
<MediaPlayerElement Name="UIMediaPlayerElement"
141+
<MediaPlayerElement Name="UIMediaPlayerElement"
142142
Stretch="Uniform"
143143
AreTransportControlsEnabled="False"
144144
Canvas.ZIndex="-1"
145145
MaxWidth="720"
146146
MaxHeight="720"
147147
Grid.Column="0"/>
148148

149-
<Image Name="UIInputImage"
149+
<Image Name="UIInputImage"
150150
Grid.Column="0"
151151
Stretch="Uniform"
152152
MaxWidth="720"
153153
MaxHeight="720"/>
154154

155-
<Grid Grid.Column="1" VerticalAlignment="Stretch">
155+
<Grid Grid.Column="1" VerticalAlignment="Stretch">
156156

157-
<Image Name="UIResultImage"
157+
<Image Name="UIResultImage"
158158
Stretch="Uniform"
159159
MaxWidth="720"
160160
MaxHeight="720"/>
161161

162-
<ProgressRing Name="UIProcessingProgressRing"
162+
<ProgressRing Name="UIProcessingProgressRing"
163163
MaxWidth="720"
164164
MaxHeight="720"
165165
IsActive="false"
166166
Visibility="Collapsed"/>
167-
</Grid>
168167
</Grid>
169-
<!--</Viewbox>-->
170-
171-
<StackPanel Name="UICameraSelectionControls" Orientation="vertical" Visibility="Collapsed" VerticalAlignment="Bottom" HorizontalAlignment="Left" Grid.Row="1">
172-
<TextBlock Text="Camera: " Style="{StaticResource TextBlockStyling}"/>
173-
<ComboBox Name="UICmbCamera" SelectionChanged="UICmbCamera_SelectionChanged" Foreground="White" >
174-
<ComboBox.Background>
175-
<SolidColorBrush Color="Black" Opacity="0.3"/>
176-
</ComboBox.Background>
177-
</ComboBox>
178-
<TextBlock Text="Preview resolution: " Style="{StaticResource TextBlockStyling}"/>
179-
<TextBlock Name="UITxtBlockPreviewProperties" Text="0x0" Style="{StaticResource TextBlockStyling}"/>
180-
</StackPanel>
168+
</Grid>
169+
<!--</Viewbox>-->
170+
171+
<StackPanel Name="UICameraSelectionControls" Orientation="vertical" Visibility="Collapsed" VerticalAlignment="Bottom" HorizontalAlignment="Left" Grid.Row="1">
172+
<TextBlock Text="Camera: " Style="{StaticResource TextBlockStyling}"/>
173+
<ComboBox Name="UICmbCamera" SelectionChanged="UICmbCamera_SelectionChanged" Foreground="White" >
174+
<ComboBox.Background>
175+
<SolidColorBrush Color="Black" Opacity="0.3"/>
176+
</ComboBox.Background>
177+
</ComboBox>
178+
<TextBlock Text="Preview resolution: " Style="{StaticResource TextBlockStyling}"/>
179+
<TextBlock Name="UITxtBlockPreviewProperties" Text="0x0" Style="{StaticResource TextBlockStyling}"/>
180+
</StackPanel>
181181

182182
<Border x:Name="UIStatusBorder" Grid.Row="2">
183183
<StackPanel Orientation="Horizontal">
@@ -207,6 +207,6 @@ Copyright (C) Microsoft Corporation. All rights reserved.
207207
</Border>
208208

209209
</Grid>
210-
210+
211211
</Grid>
212212
</Page>

Samples/FNSCandyStyleTransfer/UWP/cs/MainPage.xaml.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -584,22 +584,22 @@ private void UIStyleList_SelectionChanged(object sender, SelectionChangedEventAr
584584
_frameAquisitionLock.Release();
585585

586586
}).ContinueWith(async (antecedent) =>
587-
{
588-
if (antecedent.IsCompletedSuccessfully && _isReadyForEval)
589587
{
590-
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
588+
if (antecedent.IsCompletedSuccessfully && _isReadyForEval)
591589
{
592-
NotifyUser($"Ready to stylize! ", NotifyType.StatusMessage);
593-
UIImageControls.IsEnabled = true;
594-
UIModelControls.IsEnabled = true;
595-
UIToggleInferenceDevice.IsEnabled = true;
596-
if (_isrocessingImages)
590+
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
597591
{
598-
UIButtonFilePick_Click(null, null);
599-
}
600-
});
601-
}
602-
});
592+
NotifyUser($"Ready to stylize! ", NotifyType.StatusMessage);
593+
UIImageControls.IsEnabled = true;
594+
UIModelControls.IsEnabled = true;
595+
UIToggleInferenceDevice.IsEnabled = true;
596+
if (_isrocessingImages)
597+
{
598+
UIButtonFilePick_Click(null, null);
599+
}
600+
});
601+
}
602+
});
603603
}
604604

605605
/// <summary>

Samples/StyleTransfer/App.xaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Application
2+
x:Class="StyleTransfer.App"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:StyleTransfer">
6+
7+
<Application.Resources>
8+
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
9+
</Application.Resources>
10+
11+
</Application>

Samples/StyleTransfer/App.xaml.cs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
using GalaSoft.MvvmLight.Threading;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Runtime.InteropServices.WindowsRuntime;
7+
using Windows.ApplicationModel;
8+
using Windows.ApplicationModel.Activation;
9+
using Windows.Foundation;
10+
using Windows.Foundation.Collections;
11+
using Windows.UI.Xaml;
12+
using Windows.UI.Xaml.Controls;
13+
using Windows.UI.Xaml.Controls.Primitives;
14+
using Windows.UI.Xaml.Data;
15+
using Windows.UI.Xaml.Input;
16+
using Windows.UI.Xaml.Media;
17+
using Windows.UI.Xaml.Navigation;
18+
19+
namespace StyleTransfer
20+
{
21+
/// <summary>
22+
/// Provides application-specific behavior to supplement the default Application class.
23+
/// </summary>
24+
sealed partial class App : Application
25+
{
26+
/// <summary>
27+
/// Initializes the singleton application object. This is the first line of authored code
28+
/// executed, and as such is the logical equivalent of main() or WinMain().
29+
/// </summary>
30+
public App()
31+
{
32+
this.InitializeComponent();
33+
this.Suspending += OnSuspending;
34+
}
35+
36+
/// <summary>
37+
/// Invoked when the application is launched normally by the end user. Other entry points
38+
/// will be used such as when the application is launched to open a specific file.
39+
/// </summary>
40+
/// <param name="e">Details about the launch request and process.</param>
41+
protected override void OnLaunched(LaunchActivatedEventArgs e)
42+
{
43+
Frame rootFrame = Window.Current.Content as Frame;
44+
45+
// Do not repeat app initialization when the Window already has content,
46+
// just ensure that the window is active
47+
if (rootFrame == null)
48+
{
49+
// Create a Frame to act as the navigation context and navigate to the first page
50+
rootFrame = new Frame();
51+
52+
rootFrame.NavigationFailed += OnNavigationFailed;
53+
54+
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
55+
{
56+
//TODO: Load state from previously suspended application
57+
}
58+
59+
// Place the frame in the current Window
60+
Window.Current.Content = rootFrame;
61+
}
62+
63+
if (e.PrelaunchActivated == false)
64+
{
65+
if (rootFrame.Content == null)
66+
{
67+
// When the navigation stack isn't restored navigate to the first page,
68+
// configuring the new page by passing required information as a navigation
69+
// parameter
70+
rootFrame.Navigate(typeof(MainPage), e.Arguments);
71+
}
72+
// Ensure the current window is active
73+
Window.Current.Activate();
74+
}
75+
DispatcherHelper.Initialize();
76+
}
77+
78+
/// <summary>
79+
/// Invoked when Navigation to a certain page fails
80+
/// </summary>
81+
/// <param name="sender">The Frame which failed navigation</param>
82+
/// <param name="e">Details about the navigation failure</param>
83+
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
84+
{
85+
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
86+
}
87+
88+
/// <summary>
89+
/// Invoked when application execution is being suspended. Application state is saved
90+
/// without knowing whether the application will be terminated or resumed with the contents
91+
/// of memory still intact.
92+
/// </summary>
93+
/// <param name="sender">The source of the suspend request.</param>
94+
/// <param name="e">Details about the suspend request.</param>
95+
private void OnSuspending(object sender, SuspendingEventArgs e)
96+
{
97+
var deferral = e.SuspendingOperation.GetDeferral();
98+
//TODO: Save application state and stop any background activity
99+
deferral.Complete();
100+
}
101+
}
102+
}

0 commit comments

Comments
 (0)