Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions DigitDisplay/DigitDisplay.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -103,6 +106,7 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down
37 changes: 10 additions & 27 deletions DigitDisplay/ParallelRecognizerControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public ParallelRecognizerControl(string classifierName, FSharpFunc<int[], string
Loaded += RecognizerControl_Loaded;
}

private void RecognizerControl_Loaded(object sender, RoutedEventArgs e)
private async void RecognizerControl_Loaded(object sender, RoutedEventArgs e)
{

ClassifierText.Text = classifierName;
PopulatePanel(rawData);
await PopulatePanelAsync(rawData);
}

private struct PredictionData
Expand All @@ -49,39 +49,22 @@ private struct PredictionData
public string imageData;
}

private void PopulatePanel(string[] rawData)
private async Task PopulatePanelAsync(string[] rawData)
{
startTime = DateTime.Now;

var options = new ParallelOptions();
options.TaskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
IProgress<(string prediction, string actual, string imageData)> progress = new Progress<(string prediction, string actual, string imageData)>(args =>
{
CreateUIElements(args.prediction, args.actual, args.imageData, DigitsBox);
});

var loopResult = Parallel.ForEach(rawData, s =>
var loopResult = await Task.Run(() => Parallel.ForEach(rawData, s =>
{
int act = s.Split(',').Select(x => Convert.ToInt32(x)).First();
int[] ints = s.Split(',').Select(x => Convert.ToInt32(x)).Skip(1).ToArray();
var result = Recognizer.predict<string>(ints, classifier);

//predictions.Enqueue(new PredictionData() {
// prediction = result, actual = act.ToString(), imageData = s });

Task.Factory.StartNew(() =>
CreateUIElements(result, act.ToString(), s, DigitsBox),
CancellationToken.None,
TaskCreationOptions.None,
options.TaskScheduler
);
});

//Parallel.Invoke(options, () =>
//{
// PredictionData d;
// while (predictions.TryDequeue(out d))
// {
// if (d.imageData != null)
// CreateUIElements(d.prediction, d.actual, d.imageData, DigitsBox);
// }
//});
progress.Report((result, act.ToString(), s));
}));
}

private void CreateUIElements(string prediction, string actual, string imageData,
Expand Down
4 changes: 4 additions & 0 deletions DigitDisplay/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="System.ValueTuple" version="4.4.0" targetFramework="net45" />
</packages>