This commit is contained in:
Sheil Kumar 2021-12-03 07:46:38 -08:00
Родитель 71f68bfde7
Коммит 61dad9ba39
4 изменённых файлов: 8 добавлений и 80 удалений

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

@ -35,7 +35,7 @@
</StackPanel>
</DataTemplate>
</Page.Resources>
<Grid Padding="0,20,0,0">
<Grid Padding="0,10,0,0">
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Enter the Key:" FontSize="16"
@ -69,7 +69,7 @@
Padding="7, 0, 0, 7"
/>
</StackPanel>
<StackPanel Orientation="Horizontal" Padding="0,2,0,0">
<StackPanel Orientation="Horizontal" Padding="0,10,0,0">
<Image x:Name="InputImage" Source="ms-appx:///InputData/hummingbird.jpg"
Margin="0,1,0,0"

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

@ -64,8 +64,6 @@ namespace WinMLSamplesGallery.Samples
private Dictionary<Classifier, Func<LearningModel>> _preProcessorDictionary;
private static Dictionary<long, string> _labels;
private static Dictionary<long, string> _imagenetLabels;
private static Dictionary<long, string> _ilsvrc2013Labels;
private BitmapDecoder CurrentImageDecoder { get; set; }
@ -131,16 +129,6 @@ namespace WinMLSamplesGallery.Samples
private void EnsureInitialized()
{
if (_imagenetLabels == null)
{
_imagenetLabels = LoadLabels("ms-appx:///InputData/sysnet.txt");
}
if (_ilsvrc2013Labels == null)
{
_ilsvrc2013Labels = LoadLabels("ms-appx:///InputData/ilsvrc2013.txt");
}
if (_modelDictionary == null)
{
_modelDictionary = new Dictionary<Classifier, string>{
@ -168,10 +156,10 @@ namespace WinMLSamplesGallery.Samples
if (_postProcessorDictionary == null)
{
_postProcessorDictionary = new Dictionary<Classifier, Func<LearningModel>>{
{ Classifier.DenseNet121, () => TensorizationModels.ReshapeThenSoftmaxThenTopK(new long[] { BatchSize, _imagenetLabels.Count, 1, 1 },
{ Classifier.DenseNet121, () => TensorizationModels.ReshapeThenSoftmaxThenTopK(new long[] { BatchSize, ClassificationLabels.ImageNet.Count, 1, 1 },
TopK,
BatchSize,
_imagenetLabels.Count) },
ClassificationLabels.ImageNet.Count) },
{ Classifier.EfficientNetLite4, () => TensorizationModels.SoftMaxThenTopK(TopK) },
{ Classifier.ShuffleNet_V1, () => TensorizationModels.TopK(TopK) },
{ Classifier.SqueezeNet, () => TensorizationModels.SoftMaxThenTopK(TopK) },
@ -257,11 +245,11 @@ namespace WinMLSamplesGallery.Samples
if (model == Classifier.RCNN_ILSVRC13)
{
_labels = _ilsvrc2013Labels;
_labels = ClassificationLabels.ILSVRC2013;
}
else
{
_labels = _imagenetLabels;
_labels = ClassificationLabels.ImageNet;
}
CurrentModel = model;
@ -396,24 +384,6 @@ namespace WinMLSamplesGallery.Samples
}
#pragma warning restore CA1416 // Validate platform compatibility
private static Dictionary<long, string> LoadLabels(string csvFile)
{
var file = StorageFile.GetFileFromApplicationUriAsync(new Uri(csvFile)).GetAwaiter().GetResult();
var text = Windows.Storage.FileIO.ReadTextAsync(file).GetAwaiter().GetResult();
var labels = new Dictionary<long, string>();
var records = text.Split(Environment.NewLine);
foreach (var record in records)
{
var fields = record.Split(",", 2);
if (fields.Length == 2)
{
var index = long.Parse(fields[0]);
labels[index] = fields[1];
}
}
return labels;
}
private void TryPerformInference()
{
if (CurrentImageDecoder != null)

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

@ -38,8 +38,6 @@ namespace WinMLSamplesGallery.Samples
private LearningModelSession _tensorizationSession;
private LearningModelSession _postProcessingSession;
private static Dictionary<long, string> _imagenetLabels;
private Image<Bgra32> CurrentImage { get; set; }
#pragma warning disable CA1416 // Validate platform compatibility
@ -58,7 +56,6 @@ namespace WinMLSamplesGallery.Samples
{
this.InitializeComponent();
_imagenetLabels = LoadLabels("ms-appx:///InputData/sysnet.txt");
var tensorizationModel = TensorizationModels.BasicTensorization(Height, Width, BatchSize, Channels, Height, Width, "nearest");
_tensorizationSession = CreateLearningModelSession(tensorizationModel, SelectedDeviceKind);
_inferenceSession = CreateLearningModelSession("ms-appx:///Models/squeezenet1.1-7.onnx");
@ -104,7 +101,7 @@ namespace WinMLSamplesGallery.Samples
// Return results
var probabilities = topKValues.GetAsVectorView();
var indices = topKIndices.GetAsVectorView();
var labels = indices.Select((index) => _imagenetLabels[index]);
var labels = indices.Select((index) => ClassificationLabels.ImageNet[index]);
stop = HighResolutionClock.UtcNow();
var postProcessDuration = HighResolutionClock.DurationInMs(start, stop);
@ -168,24 +165,6 @@ namespace WinMLSamplesGallery.Samples
}
#pragma warning restore CA1416 // Validate platform compatibility
private static Dictionary<long, string> LoadLabels(string csvFile)
{
var file = StorageFile.GetFileFromApplicationUriAsync(new Uri(csvFile)).GetAwaiter().GetResult();
var text = Windows.Storage.FileIO.ReadTextAsync(file).GetAwaiter().GetResult();
var labels = new Dictionary<long, string>();
var records = text.Split(Environment.NewLine);
foreach (var record in records)
{
var fields = record.Split(",", 2);
if (fields.Length == 2)
{
var index = long.Parse(fields[0]);
labels[index] = fields[1];
}
}
return labels;
}
private void TryPerformInference(bool reloadImages = true)
{
if (CurrentImage != null)

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

@ -41,8 +41,6 @@ namespace WinMLSamplesGallery.Samples
private LearningModelSession _tensorizationSession;
private LearningModelSession _postProcessingSession;
private static Dictionary<long, string> _imagenetLabels;
private WinMLSamplesGalleryNative.OpenCVImage Original { get; set; }
private WinMLSamplesGalleryNative.OpenCVImage Noisy { get; set; }
private WinMLSamplesGalleryNative.OpenCVImage Denoised { get; set; }
@ -115,7 +113,6 @@ namespace WinMLSamplesGallery.Samples
this.InitializeComponent();
CurrentImagePath = null;
InferenceChoice = ClassifyChoice.Denoised;
_imagenetLabels = LoadLabels("ms-appx:///InputData/sysnet.txt");
_inferenceSession = CreateLearningModelSession("ms-appx:///Models/squeezenet1.1-7.onnx");
_postProcessingSession = CreateLearningModelSession(TensorizationModels.SoftMaxThenTopK(TopK));
@ -157,7 +154,7 @@ namespace WinMLSamplesGallery.Samples
// Return results
var probabilities = topKValues.GetAsVectorView();
var indices = topKIndices.GetAsVectorView();
var labels = indices.Select((index) => _imagenetLabels[index]);
var labels = indices.Select((index) => ClassificationLabels.ImageNet[index]);
stop = HighResolutionClock.UtcNow();
var postProcessDuration = HighResolutionClock.DurationInMs(start, stop);
@ -219,24 +216,6 @@ namespace WinMLSamplesGallery.Samples
}
#pragma warning restore CA1416 // Validate platform compatibility
private static Dictionary<long, string> LoadLabels(string csvFile)
{
var file = StorageFile.GetFileFromApplicationUriAsync(new Uri(csvFile)).GetAwaiter().GetResult();
var text = Windows.Storage.FileIO.ReadTextAsync(file).GetAwaiter().GetResult();
var labels = new Dictionary<long, string>();
var records = text.Split(Environment.NewLine);
foreach (var record in records)
{
var fields = record.Split(",", 2);
if (fields.Length == 2)
{
var index = long.Parse(fields[0]);
labels[index] = fields[1];
}
}
return labels;
}
private void TryPerformInference(bool reloadImages = true)
{
if (CurrentImagePath != null)