-
Notifications
You must be signed in to change notification settings - Fork 8
/
LeNetSnapshot.cs
85 lines (75 loc) · 3.05 KB
/
LeNetSnapshot.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AdvancedOCR
{
class LeNetSnapshot
{
public LeNetSnapshot(LeNetNetwork network)
{
Network = network;
Input = new StepSnapshot(network.inputLayer);
FirstConvolutions = network.FirstConvolutions.Select(step => new StepSnapshot(step)).ToArray();
FirstSubsampling = network.FirstSubsampling.Select(step => new StepSnapshot(step)).ToArray();
SecondConvolutions = network.SecondConvolutions.Select(step => new StepSnapshot(step)).ToArray();
SecondSubsampling = network.SecondSubsampling.Select(step => new StepSnapshot(step)).ToArray();
Consolidation = new StepSnapshot(network.Consolidation, 1);
Output = new StepSnapshot(network.Output, LeNetConfiguration.OutputWidth);
Marking = new StepSnapshot(network.Marking, network.Marking.Length);
}
public readonly LeNetNetwork Network;
public StepSnapshot Input { get; protected set; }
public StepSnapshot[] FirstConvolutions { get; protected set; }
public StepSnapshot[] FirstSubsampling { get; protected set; }
public StepSnapshot[] SecondConvolutions { get; protected set; }
public StepSnapshot[] SecondSubsampling { get; protected set; }
public StepSnapshot Consolidation { get; protected set; }
public StepSnapshot Output { get; protected set; }
public StepSnapshot Marking { get; protected set; }
protected IEnumerable<StepSnapshot> All()
{
yield return Input;
foreach (StepSnapshot snapshot in FirstConvolutions)
yield return snapshot;
foreach (StepSnapshot snapshot in FirstSubsampling)
yield return snapshot;
foreach (StepSnapshot snapshot in SecondConvolutions)
yield return snapshot;
foreach (StepSnapshot snapshot in SecondSubsampling)
yield return snapshot;
yield return Consolidation;
yield return Output;
yield return Marking;
}
public bool UpdateRequested { get; protected set; }
public void RequestUpdate()
{
if (!UpdateRequested)
{
UpdateRequested = true;
}
}
public event EventHandler Updated;
protected void OnUpdated()
{
UpdateRequested = false;
EventHandler handler = Updated;
if (handler != null) handler(this, EventArgs.Empty);
}
public void UpdateSnapshot()
{
if (!UpdateRequested) return;
foreach (StepSnapshot snapshot in All())
snapshot.UpdateSnapshot();
Task.Run(new Action(UpdateOutputBitmaps));
}
protected void UpdateOutputBitmaps()
{
foreach (StepSnapshot snapshot in All())
snapshot.UpdateOutputBitmap();
OnUpdated();
}
}
}