Skip to content

Commit 93e6abb

Browse files
authored
Merge pull request #491 from microsoft/user/numform/set_model_names
Set Model Names in Samples for Telemetry
2 parents 7087c45 + 0ff01df commit 93e6abb

File tree

12 files changed

+51
-14
lines changed

12 files changed

+51
-14
lines changed

Samples/WinMLSamplesGallery/WinMLSamplesGallery (Package)/WinMLSamplesGallery (Package).wapproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
</ItemGroup>
133133
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" />
134134
<ItemGroup>
135-
<PackageReference Include="Microsoft.AI.MachineLearning" Version="1.9.1" />
135+
<PackageReference Include="Microsoft.AI.MachineLearning" Version="1.11.0" />
136136
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.0-stable" />
137137
</ItemGroup>
138138
</Project>

Samples/WinMLSamplesGallery/WinMLSamplesGallery/Pages/SampleBasePage.xaml.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Microsoft.UI.Xaml;
22
using Microsoft.UI.Xaml.Controls;
33
using Microsoft.UI.Xaml.Navigation;
4+
using Microsoft.AI.MachineLearning;
5+
using Microsoft.AI.MachineLearning.Experimental;
46
using System;
57

68
namespace WinMLSamplesGallery
@@ -56,5 +58,12 @@ protected override async void OnNavigatingFrom(NavigatingCancelEventArgs e)
5658
page.StopAllEvents();
5759
}
5860
}
61+
62+
public static void SetModelNameForTelemetry(String modelName, String sampleName, LearningModel model)
63+
{
64+
var telemetryModelName = modelName + "_" + sampleName;
65+
var experimentalModel = new LearningModelExperimental(model);
66+
experimentalModel.SetName(telemetryModelName);
67+
}
5968
}
6069
}

Samples/WinMLSamplesGallery/WinMLSamplesGallery/Samples/AdapterSelection/AdapterSelection.xaml.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public AdapterSelection()
3333

3434
adapter_options.AddRange(adapters);
3535
AdapterListView.ItemsSource = adapter_options;
36+
37+
// Run in background thread to avoid blocking UI on sample launch
38+
Task.Run(() => SetModelNameForTelemetry(device));
3639
}
3740

3841
private void ChangeAdapter(object sender, RoutedEventArgs e)
@@ -100,5 +103,16 @@ private List<string> RemoveMicrosoftBasicRenderDriver(string[] adapters_arr)
100103
}
101104
return adapters;
102105
}
106+
107+
// Session must be created for telemety to be sent
108+
private void SetModelNameForTelemetry(LearningModelDevice device)
109+
{
110+
var modelName = "squeezenet1.1-7.onnx";
111+
var modelPath = Path.Join(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "Models", modelName);
112+
var model = LearningModel.LoadFromFilePath(modelPath);
113+
var options = new LearningModelSessionOptions();
114+
SampleBasePage.SetModelNameForTelemetry("SqueezeNet", "AdapterSelection", model);
115+
new LearningModelSession(model, device, options);
116+
}
103117
}
104118
}

Samples/WinMLSamplesGallery/WinMLSamplesGallery/Samples/Batching/Batching.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public Batching()
4444
var modelName = "squeezenet1.1-7-batched.onnx";
4545
var modelPath = Path.Join(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "Models", modelName);
4646
_model = LearningModel.LoadFromFilePath(modelPath);
47+
SampleBasePage.SetModelNameForTelemetry("SqueezeNet", "Batching", _model);
4748
}
4849

4950
async private void StartInference(object sender, RoutedEventArgs e)

Samples/WinMLSamplesGallery/WinMLSamplesGallery/Samples/EncryptedModel/EncryptedModel.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ private void DecryptAndEvauluate()
5454
// The encrypted model (encrypted.onnx) is embedded as a resource in
5555
// the native binary: WinMLSamplesGalleryNative.dll.
5656
var inferenceModel = WinMLSamplesGalleryNative.EncryptedModels.LoadEncryptedResource(DecryptionKey.Password);
57+
SampleBasePage.SetModelNameForTelemetry("Encrypted", "EncryptedModel", inferenceModel);
5758
var postProcessingModel = TensorizationModels.SoftMaxThenTopK(10);
5859

5960
// Update the status

Samples/WinMLSamplesGallery/WinMLSamplesGallery/Samples/ImageClassifier/ImageClassifier.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ private void InitializeWindowsMachineLearning()
243243
{
244244
var modelPath = _modelDictionary[model];
245245
var inferenceModel = LearningModel.LoadFromFilePath(modelPath);
246+
SetModelNameForTelemetry(inferenceModel);
247+
246248
_inferenceSession = CreateLearningModelSession(inferenceModel);
247249

248250
var preProcessor = _preProcessorDictionary[model];
@@ -444,5 +446,13 @@ private void DeviceComboBox_SelectionChanged(object sender, SelectionChangedEven
444446
{
445447
TryPerformInference();
446448
}
449+
450+
private void SetModelNameForTelemetry(LearningModel model)
451+
{
452+
var viewModel = (ClassifierViewModel)AllModelsGrid.SelectedItem;
453+
var modelName = viewModel.Title;
454+
var sampleName = "ImageClassifier";
455+
SampleBasePage.SetModelNameForTelemetry(modelName, sampleName, model);
456+
}
447457
}
448458
}

Samples/WinMLSamplesGallery/WinMLSamplesGallery/Samples/ImageEffects/ImageEffects.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ private LearningModelSession CreateLearningModelSession(LearningModel model, boo
364364
CloseModelOnSessionCreation = closeModel, // Close the model to prevent extra memory usage
365365
BatchSizeOverride = 0
366366
};
367+
SampleBasePage.SetModelNameForTelemetry("TensorizationModel", "ImageEffects", model);
367368
var session = new LearningModelSession(model, device, options);
368369
return session;
369370
}

Samples/WinMLSamplesGallery/WinMLSamplesGallery/Samples/ImageSharpInterop/ImageSharpInterop.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public ImageSharpInterop()
6161
var inferenceModelName = "squeezenet1.1-7.onnx";
6262
var inferenceModelPath = Path.Join(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "Models", inferenceModelName);
6363
var inferenceModel = LearningModel.LoadFromFilePath(inferenceModelPath);
64+
SampleBasePage.SetModelNameForTelemetry("SqueezeNet", "ImageSharp", inferenceModel);
6465
_inferenceSession = CreateLearningModelSession(inferenceModel);
6566

6667
var postProcessingModel = TensorizationModels.SoftMaxThenTopK(TopK);

Samples/WinMLSamplesGallery/WinMLSamplesGallery/WinMLSamplesGallery.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
</ItemGroup>
7979

8080
<ItemGroup>
81-
<PackageReference Include="Microsoft.AI.MachineLearning" Version="1.9.1" />
81+
<PackageReference Include="Microsoft.AI.MachineLearning" Version="1.11.0" />
8282
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="1.3.5" />
8383
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.0-stable" />
8484
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.4" />

Samples/WinMLSamplesGallery/WinMLSamplesGalleryNative.Interop/WinMLSamplesGalleryNative.Interop.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.AI.MachineLearning" Version="1.9.1" />
12+
<PackageReference Include="Microsoft.AI.MachineLearning" Version="1.11.0" />
1313
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="1.3.5" />
1414
</ItemGroup>
1515

@@ -20,7 +20,7 @@
2020
<Target Name="GenerateProjection" BeforeTargets="DispatchToInnerBuilds;Build;CoreCompile">
2121
<ItemGroup>
2222
<WinMLSamplesGalleryNativeWinMDs Include="$(SolutionDir)WinMLSamplesGalleryNative\bin\neutral\WinMLSamplesGalleryNative.winmd" />
23-
<WinMLSamplesGalleryNativeWinMDs Include="$(SolutionDir)packages\Microsoft.AI.MachineLearning.1.9.1\winmds\Microsoft.AI.MachineLearning.winmd" />
23+
<WinMLSamplesGalleryNativeWinMDs Include="$(SolutionDir)packages\Microsoft.AI.MachineLearning.1.11.0\winmds\Microsoft.AI.MachineLearning.winmd" />
2424
</ItemGroup>
2525

2626
<PropertyGroup>

0 commit comments

Comments
 (0)