2using System.Collections.Generic;
6using System.Threading.Tasks;
20 List<KeyValuePair<int, double>> m_rgResults =
new List<KeyValuePair<int, double>>();
34 public ResultDescriptor(
int nID,
string strName,
string strOwner,
int nIdx,
int nLabel,
int nResultCount,
byte[] rgResults,
int nSrcId, DateTime dt)
35 : base(nID, strName, strOwner)
41 m_rgResults = createResults(nResultCount, rgResults);
49 get {
return m_nIdx; }
57 get {
return m_nLabel; }
65 get {
return m_rgResults.Count; }
71 public List<KeyValuePair<int, double>>
Results
73 get {
return m_rgResults; }
81 get {
return m_nSourceID; }
98 public static byte[]
CreateResults(List<Result> rgResults,
bool bInvert)
100 List<byte> rgData =
new List<byte>();
101 double dfMax =
double.MinValue;
102 double dfMin =
double.MaxValue;
106 foreach (
Result kv
in rgResults)
108 if (dfMax < kv.
Score)
111 if (dfMin > kv.
Score)
116 using (MemoryStream ms =
new MemoryStream())
117 using (BinaryWriter bw =
new BinaryWriter(ms))
119 bw.Write(rgResults.Count);
121 foreach (
Result kv
in rgResults)
125 double dfValue = kv.
Score;
128 dfValue = dfMax - dfValue;
145 List<Result> rgRes =
new List<Result>();
147 using (MemoryStream ms =
new MemoryStream(rgData))
148 using (BinaryReader br =
new BinaryReader(ms))
161 List<Result> rgRes =
new List<Result>();
163 int nCount = br.ReadInt32();
165 for (
int i = 0; i < nCount; i++)
167 int nLabel = br.ReadInt32();
168 double dfVal = br.ReadDouble();
184 using (MemoryStream ms =
new MemoryStream())
185 using (BinaryWriter bw =
new BinaryWriter(ms))
187 bw.Write(rgrgResults.Count);
189 for (
int i = 0; i < rgrgResults.Count; i++)
191 bw.Write(rgrgResults[i].Item1.ImageID);
192 bw.Write(rgrgResults[i].Item1.Index);
193 bw.Write(rgrgResults[i].Item1.TimeStamp.ToFileTimeUtc());
208 public static List<Tuple<SimpleDatum, List<Result>>>
GetResults(
int nBatchCount,
byte[] rgData)
210 if (nBatchCount <= 0)
211 throw new Exception(
"The batch count must be >= 1!");
213 List<Tuple<SimpleDatum, List<Result>>> rgRes1 =
new List<Tuple<SimpleDatum, List<Result>>>();
215 using (MemoryStream ms =
new MemoryStream(rgData))
216 using (BinaryReader br =
new BinaryReader(ms))
218 int nCount = br.ReadInt32();
219 if (nCount != nBatchCount)
220 throw new Exception(
"The batch count does not match the expected count of " + nCount.ToString());
222 for (
int i = 0; i < nCount; i++)
224 int nImageID = br.ReadInt32();
225 int nIdx = br.ReadInt32();
226 long lTime = br.ReadInt64();
227 DateTime dt = DateTime.FromFileTimeUtc(lTime);
235 rgRes1.Add(
new Tuple<
SimpleDatum, List<Result>>(sd, rgRes));
242 private List<KeyValuePair<int, double>> createResults(
int nCount,
byte[] rgData)
244 List<KeyValuePair<int, double>> rgResults =
new List<KeyValuePair<int, double>>();
247 for (
int i = 0; i < nCount; i++)
249 int nVal = BitConverter.ToInt32(rgData, nIdx);
251 double dfVal = BitConverter.ToDouble(rgData, nIdx);
252 nIdx +=
sizeof(double);
254 rgResults.Add(
new KeyValuePair<int, double>(nVal, dfVal));
266 return m_dt.ToString() +
" ~ " + m_nLabel.ToString();
The Result class contains a single result.
int Label
Returns the label.
double Score
Returns the score of the run.
The SimpleDatum class holds a data input within host memory.
void SetImageID(int nID)
Set the image ID.
DateTime TimeStamp
Get/set the Timestamp.
int Index
Returns the index of the SimpleDatum.
The BaseDescriptor is the base class for all other descriptors, where descriptors are used to describ...
The ResultDescriptor class describes the results of a run.
static List< Tuple< SimpleDatum, List< Result > > > GetResults(int nBatchCount, byte[] rgData)
Extracts the raw image result batch from the result binary data.
ResultDescriptor(int nID, string strName, string strOwner, int nIdx, int nLabel, int nResultCount, byte[] rgResults, int nSrcId, DateTime dt)
The ResultDescriptor constructor.
static List< Result > GetResults(BinaryReader br)
Extract the results from the binary data.
int Label
Returns the expected label of the result.
static byte[] CreateResults(List< Result > rgResults, bool bInvert)
The CreateResults function converts the list of (int nLabel, double dfResult) pairs into a array of b...
DateTime TimeStamp
Returns the time-stamp of the result.
static byte[] CreateResults(List< Tuple< SimpleDatum, List< Result > > > rgrgResults)
The CreateResults function converts the batch of lists of (int nLabel, double dfResult) pairs into a ...
int SourceID
Returns the data source ID.
static List< Result > GetResults(byte[] rgData)
Extract the results from the binary data.
List< KeyValuePair< int, double > > Results
Returns the raw result data that is converted into the full list of (int nLabel, double dfResult) pai...
int ResultCount
Returns the number of items (classes) participating in the results.
int Index
Returns the index of the results.
override string ToString()
Creates the string representation of the descriptor.
The descriptors namespace contains all descriptor used to describe various items stored within the da...