MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
LabelStats.cs
2using System;
3using System.Collections.Generic;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7
8namespace MyCaffe.db.image
9{
10#pragma warning disable 1591
11
12 public class LabelStats
13 {
14 List<LabelDescriptor> m_rgLabels;
15 List<ulong> m_rgCounts;
16 List<ulong> m_rgBoosts;
17 object m_objSync = new object();
18 object m_objSyncBoost = new object();
19
20 public LabelStats(int nCount)
21 {
22 m_rgLabels = new List<LabelDescriptor>(nCount);
23 m_rgCounts = new List<ulong>(nCount);
24 m_rgBoosts = new List<ulong>();
25 }
26
27 public void Reset()
28 {
29 lock (m_objSyncBoost)
30 {
31 m_rgBoosts = new List<ulong>();
32 }
33 }
34
35 private int find(int nLabel)
36 {
37 for (int i = 0; i < m_rgLabels.Count; i++)
38 {
39 if (m_rgLabels[i].Label == nLabel)
40 return i;
41 }
42
43 return -1;
44 }
45
46 public void Add(LabelDescriptor label)
47 {
48 lock (m_objSync)
49 {
50 m_rgLabels.Add(label);
51 m_rgCounts.Add(0);
52 m_rgLabels = m_rgLabels.OrderBy(p => p.Label).ToList();
53 }
54 }
55
56 public void UpdateLabel(int nLabel)
57 {
58 int nIdx = find(nLabel);
59 if (nIdx >= 0)
60 m_rgCounts[nIdx]++;
61 }
62
63 public void UpdateBoost(int nBoost)
64 {
65 lock (m_objSyncBoost)
66 {
67 while (m_rgBoosts.Count <= nBoost)
68 {
69 m_rgBoosts.Add(0);
70 }
71
72 m_rgBoosts[nBoost]++;
73 }
74 }
75
76 public Dictionary<int, ulong> GetCounts()
77 {
78 lock (m_objSync)
79 {
80 Dictionary<int, ulong> rg = new Dictionary<int, ulong>();
81
82 for (int i = 0; i < m_rgLabels.Count; i++)
83 {
84 rg.Add(m_rgLabels[i].Label, m_rgCounts[i]);
85 }
86
87 return rg;
88 }
89 }
90
91 public string GetQueryBoostHitPercentsAsText(int nMax = 10)
92 {
93 string strOut = "{";
94 double dfTotal = 0;
95
96 lock (m_objSyncBoost)
97 {
98 for (int i = 0; i < m_rgBoosts.Count; i++)
99 {
100 dfTotal += m_rgBoosts[i];
101 }
102
103 for (int i = 0; i < m_rgBoosts.Count && i < nMax; i++)
104 {
105 double dfPct = m_rgBoosts[i] / dfTotal;
106 strOut += dfPct.ToString("P");
107 strOut += ",";
108 }
109 }
110
111 if (m_rgBoosts.Count > nMax)
112 strOut += "...";
113 else
114 strOut = strOut.TrimEnd(',');
115
116 strOut += "}";
117
118 return strOut;
119 }
120
121 public string GetQueryLabelHitPercentsAsText(int nMax = 10)
122 {
123 string strOut = "{";
124 double dfTotal = 0;
125
126 lock (m_objSync)
127 {
128 for (int i = 0; i < m_rgCounts.Count; i++)
129 {
130 dfTotal += m_rgCounts[i];
131 }
132
133 for (int i = 0; i < m_rgCounts.Count && i < nMax; i++)
134 {
135 double dfPct = m_rgCounts[i] / dfTotal;
136 strOut += dfPct.ToString("P");
137 strOut += ",";
138 }
139 }
140
141 if (m_rgCounts.Count > nMax)
142 strOut += "...";
143 else
144 strOut = strOut.TrimEnd(',');
145
146 strOut += "}";
147
148 return strOut;
149 }
150
151 public string GetQueryLabelEpochAsText(int nMax = 10)
152 {
153 string strOut = "{";
154
155 lock (m_objSync)
156 {
157 for (int i = 0; i < m_rgLabels.Count && i < nMax; i++)
158 {
159 int nImageCount = m_rgLabels[i].ImageCount;
160 double dfPct = (nImageCount == 0) ? 0 : (double)m_rgCounts[i] / nImageCount;
161 strOut += dfPct.ToString("N2");
162 strOut += ",";
163 }
164 }
165
166 if (m_rgCounts.Count > nMax)
167 strOut += "...";
168 else
169 strOut = strOut.TrimEnd(',');
170
171 strOut += "}";
172
173 return strOut;
174 }
175 }
176
177#pragma warning restore 1591
178}
The LabelDescriptor class describes a single label.
The descriptors namespace contains all descriptor used to describe various items stored within the da...
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe.db.image namespace contains all image database related classes.
Definition: Database.cs:18
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12