MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
ResultCollection.cs
1using System;
2using System.Collections.Generic;
3using System.Drawing;
4using System.Linq;
5using System.Text;
6using MyCaffe.basecode;
8using MyCaffe.db.image;
9using MyCaffe.param;
10
11namespace MyCaffe.common
12{
16 public class ResultCollection
17 {
18 Dictionary<int, string> m_rgLabels = new Dictionary<int, string>();
19 List<Result> m_rgResultsOriginal = new List<Result>();
20 List<Result> m_rgResultsSorted = new List<Result>();
21 RESULT_TYPE m_resultType = RESULT_TYPE.NONE;
22
26 public enum RESULT_TYPE
27 {
31 NONE,
35 PROBABILITIES,
39 DISTANCES,
43 MULTIBOX,
48 }
49
55 public ResultCollection(List<Result> rgResults, LayerParameter.LayerType outputLayerType)
56 {
57 m_resultType = GetResultType(outputLayerType);
58 m_rgResultsOriginal = rgResults;
59
60 foreach (Result item in rgResults)
61 {
62 m_rgResultsSorted.Add(item);
63 }
64
65 m_rgResultsSorted = m_rgResultsSorted.OrderByDescending(p => p.Score).ToList();
66 }
67
74 {
75 switch (type)
76 {
77 case LayerParameter.LayerType.SOFTMAX:
78 return RESULT_TYPE.PROBABILITIES;
79
80 case LayerParameter.LayerType.DECODE:
81 return RESULT_TYPE.DISTANCES;
82
83 case LayerParameter.LayerType.DETECTION_OUTPUT:
84 return RESULT_TYPE.MULTIBOX;
85
86 default:
87 return RESULT_TYPE.NONE;
88 }
89 }
90
95 {
96 get { return m_resultType; }
97 }
98
102 public List<double> GetEncoding()
103 {
104 List<double> rg = new List<double>();
105
106 foreach (Result item in m_rgResultsOriginal)
107 {
108 rg.Add(item.Score);
109 }
110
111 return rg;
112 }
113
117 public List<Result> ResultsOriginal
118 {
119 get { return m_rgResultsOriginal; }
120 }
121
125 public List<Result> ResultsSorted
126 {
127 get { return m_rgResultsSorted; }
128 }
129
139 {
140 get { return m_rgResultsSorted[0].Label; }
141 }
142
152 {
153 get { return m_rgResultsSorted[0].Score; }
154 }
155
165 {
166 get { return m_rgResultsSorted[m_rgResultsSorted.Count-1].Label; }
167 }
168
178 {
179 get { return m_rgResultsSorted[m_rgResultsSorted.Count-1].Score; }
180 }
181
185 public int DetectedLabel
186 {
187 get
188 {
189 if (m_resultType == RESULT_TYPE.DISTANCES)
191 else
193 }
194 }
195
200 {
201 get
202 {
203 if (m_resultType == RESULT_TYPE.DISTANCES)
205 else
207 }
208 }
209
213 public Dictionary<int, string> Labels
214 {
215 get { return m_rgLabels; }
216 }
217
222 public void SetLabels(List<LabelDescriptor> rgLabels)
223 {
224 m_rgLabels = new Dictionary<int, string>();
225
226 foreach (LabelDescriptor l in rgLabels)
227 {
228 if (!m_rgLabels.ContainsKey(l.Label))
229 m_rgLabels.Add(l.Label, l.Name);
230 }
231 }
232
237 public override string ToString()
238 {
239 string strOut = "";
240
241 for (int i = 0; i < m_rgResultsOriginal.Count; i++)
242 {
243 int nLabel = m_rgResultsOriginal[i].Label;
244 double dfVal = m_rgResultsOriginal[i].Score;
245 string strName = null;
246
247 if (m_rgLabels.ContainsKey(nLabel))
248 strName = m_rgLabels[nLabel];
249
250 if (nLabel == DetectedLabelMaxSignal)
251 strOut += "[";
252
253 if (strName != null)
254 strOut += strName;
255 else
256 strOut += nLabel.ToString();
257
258 strOut += "->";
259 strOut += dfVal.ToString("N4");
260
261 if (nLabel == DetectedLabelMaxSignal)
262 strOut += "]";
263
264 if (i < m_rgResultsOriginal.Count - 1)
265 strOut += ", ";
266 }
267
268 return strOut;
269 }
270
276 public Image ToImage(ColorMapper clrMap)
277 {
278 int nW = (int)Math.Ceiling(Math.Sqrt(m_rgResultsOriginal.Count));
279 int nH = nW;
280 Size sz = new Size(nW, nH);
281 return ImageData.GetImage(m_rgResultsOriginal, sz, clrMap);
282 }
283 }
284}
The ColorMapper maps a value within a number range, to a Color within a color scheme.
Definition: ColorMapper.cs:14
The ImageData class is a helper class used to convert between Datum, other raw data,...
Definition: ImageData.cs:14
static Bitmap GetImage(SimpleDatum d, ColorMapper clrMap=null, List< int > rgClrOrder=null)
Converts a SimplDatum (or Datum) into an image, optionally using a ColorMapper.
Definition: ImageData.cs:506
The Result class contains a single result.
Definition: Result.cs:14
double Score
Returns the score of the run.
Definition: Result.cs:53
The LabelDescriptor class describes a single label.
int Label
Specifies the original label
string Name
Specifies the label name.
The ResultCollection contains the result of a given CaffeControl::Run.
ResultCollection(List< Result > rgResults, LayerParameter.LayerType outputLayerType)
The ResultCollection constructor.
override string ToString()
Returns a string representation of the results.
RESULT_TYPE ResultType
Returns the result type of the result data: PROBABILITIES (Sigmoid), DISTANCES (Decode),...
int DetectedLabelMaxSignal
Returns the detected label with the maximum signal.
List< Result > ResultsSorted
Returns the original results in sorted order.
double DetectedLabelOutput
Returns the detected label output depending on the result type (distance or probability) with a defau...
static RESULT_TYPE GetResultType(LayerParameter.LayerType type)
Get the result type based on the layer-type used.
List< double > GetEncoding()
Returns the data encoding values.
void SetLabels(List< LabelDescriptor > rgLabels)
Sets the label names in the label dictionary lookup.
Image ToImage(ColorMapper clrMap)
Converts the result collection into an image.
int DetectedLabel
Returns the detected label depending on the result type (distance or probability) with a default type...
RESULT_TYPE
Defines the type of result.
int DetectedLabelMinSignal
Returns the detected label with the minimum signal.
double DetectedLabelOutputMaxSignal
Returns the detected label output with the maximum signal.
List< Result > ResultsOriginal
Returns the original results.
Dictionary< int, string > Labels
Returns the dictionary lookup of the labels and their names.
double DetectedLabelOutputMinSignal
Returns the detected label output of the label with the minimum signal.
Specifies the base parameter for all layers.
LayerType
Specifies the layer type.
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
@ TEMPORAL
Specifies to use the tempoal database.
@ NONE
No training category specified.
The MyCaffe.common namespace contains common MyCaffe classes.
Definition: BatchInput.cs:8
The MyCaffe.db.image namespace contains all image database related classes.
Definition: Database.cs:18
The MyCaffe.param namespace contains parameters used to create models.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12