MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
Imageset.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Drawing;
6using MyCaffe.basecode;
7using System.Threading;
8using System.Diagnostics;
10
11namespace MyCaffe.db.image
12{
16 public class ImageSet : IDisposable
17 {
18 CryptoRandom m_random = null;
19 SourceDescriptor m_src;
20 List<LabelSet> m_rgLabelSet = new List<LabelSet>();
21 List<LabelSet> m_rgLabelSetWithData = new List<LabelSet>();
22 SimpleDatum[] m_rgImages;
23 List<int> m_rgIndexes = new List<int>();
24 List<int> m_rgLabelIndexes = new List<int>();
25 List<SimpleDatum> m_rgImagesLimitLoaded = new List<SimpleDatum>();
26 SimpleDatum m_imgMean = null;
27 int m_nLastFindIdx = 0;
28 int m_nLastIdx = -1;
29 int m_nFixedIndex = -1;
30 object m_syncObj = new object();
31 int m_nLoadLimit = 0;
32 DB_LOAD_METHOD m_loadMethod;
33 Dictionary<int, double> m_rgLabelBoosts = new Dictionary<int, double>();
34 double m_dfLabelBoostTotal = 0;
35 DatasetFactory m_factory;
36 int m_nLastImageIdxFromLoad = 0;
37 int m_nLoadedCount = 0;
38 LabelStats m_rgLabelStats;
39
43 public event EventHandler<CalculateImageMeanArgs> OnCalculateImageMean;
44
53 public ImageSet(DatasetFactory factory, SourceDescriptor src, DB_LOAD_METHOD loadMethod, int nLoadLimit, CryptoRandom random)
54 {
55 m_random = random;
56 m_factory = new DatasetFactory(factory);
57 m_factory.Open(src.ID);
58 m_loadMethod = loadMethod;
59 m_nLoadLimit = nLoadLimit;
60 m_src = new SourceDescriptor(src);
61 m_imgMean = null;
62
63 m_rgImages = new SimpleDatum[m_src.ImageCount];
64 m_rgLabelStats = new LabelStats(src.Labels.Count);
65
66 foreach (LabelDescriptor label in src.Labels)
67 {
68 if (label.ImageCount > 0)
69 {
70 m_rgLabelSet.Add(new LabelSet(label, m_random));
71 }
72
73 m_rgLabelStats.Add(label);
74 }
75 }
76
80 protected ImageSet()
81 {
82 }
83
84
89 protected virtual void Dispose(bool bDisposing)
90 {
91 if (m_factory != null)
92 {
93 m_factory.Close();
94 m_factory.Dispose();
95 m_factory = null;
96 }
97 }
98
102 public void Dispose()
103 {
104 Dispose(true);
105 }
106
111 public Dictionary<int, ulong> GetQueryLabelCounts()
112 {
113 if (m_rgLabelStats == null)
114 return new Dictionary<int, ulong>();
115
116 return m_rgLabelStats.GetCounts(); ;
117 }
118
124 public void SetQueryLabelCount(int nLabel, int nBoost)
125 {
126 if (m_rgLabelStats != null)
127 {
128 m_rgLabelStats.UpdateLabel(nLabel);
129 m_rgLabelStats.UpdateBoost(nBoost);
130 }
131 }
132
138 {
139 if (m_rgLabelStats == null)
140 return "n/a";
141
142 return m_rgLabelStats.GetQueryBoostHitPercentsAsText();
143 }
144
150 {
151 if (m_rgLabelStats == null)
152 return "n/a";
153
154 return m_rgLabelStats.GetQueryLabelHitPercentsAsText();
155 }
156
162 {
163 if (m_rgLabelStats == null)
164 return "n/a";
165
166 return m_rgLabelStats.GetQueryLabelEpochAsText();
167 }
168
169
174 public List<LabelDescriptor> GetLabels()
175 {
176 List<LabelDescriptor> rgLabels = new List<LabelDescriptor>();
177
178 foreach (LabelSet ls in m_rgLabelSet)
179 {
180 rgLabels.Add(new LabelDescriptor(ls.Label));
181 }
182
183 return rgLabels;
184 }
185
191 public string GetLabelName(int nLabel)
192 {
193 foreach (LabelSet ls in m_rgLabelSet)
194 {
195 if (ls.Label.Label == nLabel)
196 return ls.Label.Name;
197 }
198
199 return nLabel.ToString();
200 }
201
207 {
208 foreach (SimpleDatum sd in m_rgImages)
209 {
210 sd.SetLabel(col.MapLabel(sd.OriginalLabel, sd.Boost));
211 }
212
214 }
215
221 {
222 ImageSet imgSet = new db.image.ImageSet();
223
224 imgSet.m_src = new SourceDescriptor(m_src);
225 imgSet.m_factory = new db.image.DatasetFactory(m_factory);
226
227 foreach (LabelSet ls in m_rgLabelSet)
228 {
229 imgSet.m_rgLabelSet.Add(new db.image.LabelSet(ls.Label, m_random));
230 }
231
232 List<SimpleDatum> rgSd = new List<basecode.SimpleDatum>();
233
234 foreach (SimpleDatum sd in m_rgImages)
235 {
236 if (sd != null)
237 rgSd.Add(new SimpleDatum(sd));
238 else
239 rgSd.Add(null);
240 }
241
242 foreach (SimpleDatum sd in m_rgImagesLimitLoaded)
243 {
244 if (sd != null)
245 imgSet.m_rgImagesLimitLoaded.Add(sd);
246 else
247 imgSet.m_rgImagesLimitLoaded.Add(null);
248 }
249
250 imgSet.m_rgImages = rgSd.ToArray();
251 imgSet.m_imgMean = new SimpleDatum(m_imgMean);
252 imgSet.ReloadLabelSets();
253
254 return imgSet;
255 }
256
263 public int FindImageIndex(DateTime dt, string strDesc)
264 {
265 SimpleDatum[] rgImages = m_rgImages;
266
267 if (m_rgImagesLimitLoaded.Count > 0)
268 rgImages = m_rgImagesLimitLoaded.ToArray();
269
270 for (int i = m_nLastFindIdx; i < rgImages.Length; i++)
271 {
272 if (rgImages[i].TimeStamp == dt && rgImages[i].Description == strDesc)
273 {
274 m_nLastFindIdx = i;
275 return i;
276 }
277 }
278
279 for (int i = 0; i < m_nLastFindIdx; i++)
280 {
281 if (rgImages[i].TimeStamp == dt && rgImages[i].Description == strDesc)
282 {
283 m_nLastFindIdx = i;
284 return i;
285 }
286 }
287
288 return -1;
289 }
290
294 public void Reset()
295 {
296 m_rgImagesLimitLoaded = new List<SimpleDatum>();
297 m_rgIndexes = new List<int>();
298 m_rgLabelStats.Reset();
299 }
300
307 public bool Add(int nIdx, SimpleDatum d)
308 {
309 if (m_nLoadLimit > 0 && m_rgImagesLimitLoaded.Count == m_nLoadLimit)
310 return false;
311
312 m_rgImages[nIdx] = d;
313 m_nLoadedCount++;
314
315 if (m_nLoadLimit > 0)
316 m_rgImagesLimitLoaded.Add(d);
317
318 bool bAdded = false;
319
320 foreach (LabelSet ls in m_rgLabelSet)
321 {
322 if (ls.Label.ActiveLabel == d.Label)
323 {
324 ls.Add(d);
325 bAdded = true;
326 break;
327 }
328 }
329
330 if (!bAdded)
331 {
332 LabelSet ls = new LabelSet(new LabelDescriptor(d.Label, d.Label, "label #" + d.Label.ToString(), 0), m_random);
333 ls.Add(d);
334 m_rgLabelSet.Add(ls);
335 }
336
337 return true;
338 }
339
343 public void ReloadLabelSets()
344 {
345 lock (m_syncObj)
346 {
347 SimpleDatum[] rgImages = m_rgImages;
348
349 if (m_rgImagesLimitLoaded.Count > 0)
350 rgImages = m_rgImagesLimitLoaded.ToArray();
351
352 foreach (LabelSet ls in m_rgLabelSet)
353 {
354 ls.Clear();
355 }
356
357 foreach (SimpleDatum d in rgImages)
358 {
359 foreach (LabelSet ls in m_rgLabelSet)
360 {
361 if (d != null && ls.Label.ActiveLabel == d.Label)
362 {
363 ls.Add(d);
364 break;
365 }
366 }
367 }
368
369 CompleteLoad(0);
370 }
371 }
372
377 public void CompleteLoad(int nLastImageIdx)
378 {
379 m_rgLabelSetWithData = new List<LabelSet>();
380
381 foreach (LabelSet ls in m_rgLabelSet)
382 {
383 if (ls.Count > 0)
384 m_rgLabelSetWithData.Add(ls);
385 }
386
387 m_nLastImageIdxFromLoad = nLastImageIdx;
388 }
389
394 {
395 get { return m_src; }
396 }
397
401 public int SourceID
402 {
403 get { return m_src.ID; }
404 }
405
409 public string SourceName
410 {
411 get { return m_src.Name.Trim(); }
412 }
413
417 public bool IsRealData
418 {
419 get { return m_src.IsRealData; }
420 }
421
425 public int Count
426 {
427 get { return m_rgImages.Length; }
428 }
429
434 {
435 get { return m_rgImages; }
436 }
437
438 private IEnumerable<SimpleDatum> getQuery(bool bSuperboostOnly, string strFilterVal = null, int? nBoostVal = null)
439 {
440 IEnumerable<SimpleDatum> iQuery = m_rgImages.Where(p => p != null);
441
442 if (bSuperboostOnly)
443 {
444 if (nBoostVal.HasValue)
445 {
446 int nVal = nBoostVal.Value;
447
448 if (nVal < 0)
449 {
450 nVal = Math.Abs(nVal);
451 iQuery = iQuery.Where(p => p.Boost == nVal);
452 }
453 else
454 {
455 iQuery = iQuery.Where(p => p.Boost >= nVal);
456 }
457 }
458 else
459 {
460 iQuery = iQuery.Where(p => p.Boost > 0);
461 }
462 }
463
464 if (!string.IsNullOrEmpty(strFilterVal))
465 iQuery = iQuery.Where(p => p.Description == strFilterVal);
466
467 return iQuery;
468 }
469
479 public int GetCount(bool bSuperboostOnly, string strFilterVal = null, int? nBoostVal = null)
480 {
481 IEnumerable<SimpleDatum> iQuery = getQuery(bSuperboostOnly, strFilterVal, nBoostVal);
482 return iQuery.Count();
483 }
484
496 public List<SimpleDatum> GetImages(bool bSuperboostOnly, string strFilterVal = null, int? nBoostVal = null, int nStartIdx = 0, int nQueryCount = int.MaxValue)
497 {
498 IEnumerable<SimpleDatum> iQuery = getQuery(bSuperboostOnly, strFilterVal, nBoostVal);
499
500 if (nStartIdx != 0 || nQueryCount != int.MaxValue)
501 iQuery = iQuery.Where(p => p.Index >= nStartIdx && p.Index < nStartIdx + nQueryCount);
502
503 return iQuery.ToList();
504 }
505
516 public List<SimpleDatum> GetImages(bool bSuperboostOnly, string strFilterVal, int? nBoostVal, int[] rgIdx)
517 {
518 IEnumerable<SimpleDatum> iQuery = getQuery(bSuperboostOnly, strFilterVal, nBoostVal);
519
520 iQuery = iQuery.Where(p => rgIdx.Contains(p.Index));
521
522 return iQuery.ToList();
523 }
524
535 public SimpleDatum GetImage(int nIdx, DB_LABEL_SELECTION_METHOD labelSelectionMethod, DB_ITEM_SELECTION_METHOD imageSelectionMethod, Log log, bool bLoadDataCriteria = false, bool bLoadDebugData = false)
536 {
537 lock (m_syncObj)
538 {
539 SimpleDatum[] rgImages = m_rgImages;
540
541 if (m_nLoadLimit > 0 && m_rgImagesLimitLoaded.Count == m_nLoadLimit)
542 rgImages = m_rgImagesLimitLoaded.ToArray();
543
544 if (rgImages.Length == 0)
545 throw new Exception("There are no images in the dataset '" + m_src.Name + "' to select from!");
546
547 SimpleDatum sd = null;
548
549 if ((labelSelectionMethod & DB_LABEL_SELECTION_METHOD.RANDOM) == DB_LABEL_SELECTION_METHOD.RANDOM)
550 {
551 if (m_rgLabelSet.Count == 0)
552 throw new Exception("There are no label specified in the Labels table for the dataset '" + m_src.Name + "'!");
553
554 LabelSet labelSet = getLabelSet(labelSelectionMethod);
555 if (labelSet != null)
556 sd = labelSet.GetImage(nIdx, imageSelectionMethod);
557 }
558
559 int nImageIdx = 0;
560
561 if (sd == null)
562 {
563 sd = LabelSet.GetImage(rgImages, m_rgIndexes, rgImages.Length, nIdx, m_random, imageSelectionMethod, ref m_nLastIdx, ref m_nFixedIndex, out nImageIdx);
564 }
565
566
567 //-----------------------------------------
568 // Handle dynamic loading of the image.
569 //-----------------------------------------
570
571 bool bRawDataLoaded = false;
572
573 if (sd == null)
574 {
575 int nRetries = 1;
576
577 if ((imageSelectionMethod & DB_ITEM_SELECTION_METHOD.RANDOM) == DB_ITEM_SELECTION_METHOD.RANDOM)
578 nRetries = 5;
579
580 for (int i = 0; i < nRetries; i++)
581 {
582 sd = m_factory.LoadImageAt(nImageIdx, bLoadDataCriteria, bLoadDebugData);
583 if (sd != null)
584 {
585 bRawDataLoaded = true;
586 Add(nImageIdx, sd);
587 break;
588 }
589
590 if (i < nRetries - 1)
591 nImageIdx = m_random.Next(rgImages.Length);
592 }
593
594 if (sd == null)
595 log.WriteLine("WARNING! The dataset needs to be re-indexed. Could not find the image at index " + nImageIdx.ToString() + " - attempting several random queries to get an image.");
596 }
597
598 if (!bRawDataLoaded)
599 m_factory.LoadRawData(sd, bLoadDebugData, bLoadDataCriteria);
600
601 return sd;
602 }
603 }
604
610 public SimpleDatum GetImage(int nImageID)
611 {
612 lock (m_syncObj)
613 {
614 List<SimpleDatum> rgSd = m_rgImages.Where(p => p != null && p.ImageID == nImageID).ToList();
615 if (rgSd.Count > 0)
616 return rgSd[0];
617
618 SimpleDatum sd = m_factory.LoadImage(nImageID);
619 if (sd != null)
620 Add(sd.Index, sd);
621
622 return sd;
623 }
624 }
625
631 public LabelSet GetLabelSet(int nLabel)
632 {
633 foreach (LabelSet ls in m_rgLabelSet)
634 {
635 if (ls.Label.ActiveLabel == nLabel)
636 return ls;
637 }
638
639 return null;
640 }
641
642 private LabelSet getLabelSet(DB_LABEL_SELECTION_METHOD labelSelectionMethod)
643 {
644 double dfBoostTotal = m_dfLabelBoostTotal;
645 Dictionary<int, double> rgBoosts = m_rgLabelBoosts;
646 int nIdx;
647
648 if ((labelSelectionMethod & DB_LABEL_SELECTION_METHOD.BOOST) != DB_LABEL_SELECTION_METHOD.BOOST)
649 {
650 if (m_rgLabelSetWithData.Count == 0)
651 return null;
652
653 if (m_rgLabelIndexes.Count == 0)
654 {
655 for (int i = 0; i < m_rgLabelSetWithData.Count; i++)
656 {
657 m_rgLabelIndexes.Add(i);
658 }
659 }
660
661 nIdx = m_random.Next(m_rgLabelIndexes.Count);
662 nIdx = m_rgLabelIndexes[nIdx];
663 m_rgLabelIndexes.Remove(nIdx);
664
665 return m_rgLabelSetWithData[nIdx];
666 }
667
668
669 //---------------------------------------------
670 // Handle Label Sets with label boost.
671 //---------------------------------------------
672 else
673 {
674 double dfVal = m_random.NextDouble() * dfBoostTotal;
675 double dfTotal = 0;
676
677 nIdx = m_rgLabelSet.Count - 1;
678
679 for (int i = 0; i < m_rgLabelSet.Count; i++)
680 {
681 int nLabel = m_rgLabelSet[i].Label.ActiveLabel;
682
683 if (rgBoosts != null && rgBoosts.ContainsKey(nLabel))
684 dfTotal += (double)rgBoosts[nLabel];
685 else
686 dfTotal += 1;
687
688 if (dfTotal >= dfVal)
689 {
690 nIdx = i;
691 break;
692 }
693 }
694
695 return m_rgLabelSet[nIdx];
696 }
697 }
698
704 {
705 m_imgMean = d;
706 }
707
714 public SimpleDatum GetImageMean(Log log, WaitHandle[] rgAbort)
715 {
716 if (m_imgMean != null)
717 return m_imgMean;
718
719 if (m_rgImages.Length == 0)
720 {
721 if (log != null)
722 log.WriteLine("WARNING: Cannot create image mean with no images!");
723 return null;
724 }
725
726 if (m_loadMethod != DB_LOAD_METHOD.LOAD_ALL)
727 throw new Exception("Can only create image mean when using LOAD_ALL.");
728
729 if (m_nLoadLimit != 0)
730 throw new Exception("Can only create image mean when LoadLimit = 0.");
731
732 if (OnCalculateImageMean != null)
733 {
734 CalculateImageMeanArgs args = new CalculateImageMeanArgs(m_rgImages);
735 OnCalculateImageMean(this, args);
736
737 if (args.Cancelled)
738 return null;
739
740 m_imgMean = args.ImageMean;
741 return m_imgMean;
742 }
743
744 m_imgMean = SimpleDatum.CalculateMean(log, m_rgImages, rgAbort);
745 m_imgMean.SetLabel(0);
746
747 return m_imgMean;
748 }
749
754 public void UpdateLabelBoosts(int nProjectId)
755 {
756 List<LabelBoostDescriptor> rgBoosts = m_factory.GetLabelBoosts(nProjectId, m_src.ID);
757 m_rgLabelBoosts = new Dictionary<int, double>();
758
759 m_dfLabelBoostTotal = 0;
760
761 foreach (LabelBoostDescriptor boost in rgBoosts)
762 {
763 m_dfLabelBoostTotal += (double)boost.Boost;
764
765 int nLabel = boost.Label;
766 double dfBoost = (double)boost.Boost;
767
768 if (!m_rgLabelBoosts.ContainsKey(nLabel))
769 m_rgLabelBoosts.Add(nLabel, dfBoost);
770 else
771 m_rgLabelBoosts[nLabel] = dfBoost;
772 }
773 }
774
780 {
781 m_factory.SetLabelMapping(map, m_src.ID);
782 }
783
789 public void UpdateLabelMapping(int nNewLabel, List<int> rgOriginalLabels)
790 {
791 m_factory.UpdateLabelMapping(nNewLabel, rgOriginalLabels, m_src.ID);
792 }
793
798 public void ResetLabels(int nProjectId)
799 {
800 m_factory.ResetLabels(nProjectId, m_src.ID);
801 }
802
807 public void DeleteLabelBoosts(int nProjectId)
808 {
809 m_factory.DeleteLabelBoosts(nProjectId, m_src.ID);
810 }
811
818 public void AddLabelBoost(int nProjectId, int nLabel, double dfBoost)
819 {
820 m_factory.AddLabelBoost(nProjectId, nLabel, dfBoost, m_src.ID);
821 }
822
828 public string GetLabelBoostsAsText(int nProjectId)
829 {
830 return m_factory.GetLabelBoostsAsText(nProjectId, m_src.ID);
831 }
832
837 public Dictionary<int, int> LoadLabelCounts()
838 {
839 return m_factory.LoadLabelCounts(m_src.ID);
840 }
841
846 public void UpdateLabelCounts(int nProjectId)
847 {
848 m_factory.UpdateLabelCounts(m_src.ID, nProjectId);
849 }
850
855 public string GetLabelCountsAsText()
856 {
857 return m_factory.GetLabelCountsAsText(m_src.ID);
858 }
859
863 public void Unload()
864 {
865 lock (m_syncObj)
866 {
867 for (int i = 0; i < m_rgImages.Length; i++)
868 {
869 m_rgImages[i] = null;
870 }
871
872 foreach (LabelSet ls in m_rgLabelSet)
873 {
874 ls.Unload();
875 }
876
877 m_nLoadedCount = 0;
878 }
879 }
880
885 public int GetLoadedCount()
886 {
887 return m_nLoadedCount;
888 }
889
894 public int GetTotalCount()
895 {
896 return m_rgImages.Length;
897 }
898
902 public void ResetAllBoosts()
903 {
904 foreach (SimpleDatum sd in m_rgImages)
905 {
906 sd.ResetBoost();
907 }
908 }
909
918 public List<SimpleDatum> GetImages(DateTime dt, int nImageCount, string strFilterVal = null)
919 {
920 if (string.IsNullOrEmpty(strFilterVal))
921 return m_rgImages.Where(p => p.TimeStamp >= dt).Take(nImageCount).ToList();
922 else
923 return m_rgImages.Where(p => p.Description == strFilterVal && p.TimeStamp >= dt).Take(nImageCount).ToList();
924 }
925
932 public bool Sort(IMGDB_SORT method)
933 {
934 if (method == IMGDB_SORT.BYID)
935 m_rgImages = m_rgImages.OrderBy(p => p.ImageID).ToArray();
936 else if (method == IMGDB_SORT.BYID_DESC)
937 m_rgImages = m_rgImages.OrderByDescending(p => p.ImageID).ToArray();
938 else if (method == IMGDB_SORT.BYIDX)
939 m_rgImages = m_rgImages.OrderBy(p => p.Index).ToArray();
940 else if (method == IMGDB_SORT.BYDESC)
941 m_rgImages = m_rgImages.OrderBy(p => p.Description).ToArray();
942 else if (method == IMGDB_SORT.BYTIME)
943 m_rgImages = m_rgImages.OrderBy(p => p.TimeStamp).ToArray();
944 else if ((method & (IMGDB_SORT.BYDESC | IMGDB_SORT.BYTIME)) == (IMGDB_SORT.BYDESC | IMGDB_SORT.BYTIME))
945 m_rgImages = m_rgImages.OrderBy(p => p.Description).ThenBy(p => p.TimeStamp).ToArray();
946 else
947 return false;
948
949 return true;
950 }
951 }
952}
The CalculateImageMeanArgs is passed as an argument to the MyCaffeImageDatabase::OnCalculateImageMean...
Definition: EventArgs.cs:136
SimpleDatum ImageMean
Get/set the image mean calculated from the Images.
Definition: EventArgs.cs:162
bool Cancelled
Get/set a flag indicating to cancel the operation.
Definition: EventArgs.cs:171
The CryptoRandom is a random number generator that can use either the standard .Net Random objec or t...
Definition: CryptoRandom.cs:14
int Next(int nMinVal, int nMaxVal, bool bMaxInclusive=true)
Returns a random int within the range
double NextDouble()
Returns a random double within the range .
Definition: CryptoRandom.cs:83
The LabelMappingCollection manages a collection of LabelMapping's.
Definition: LabelMapping.cs:15
The LabelMapping class represents a single label mapping.
The Log class provides general output in text form.
Definition: Log.cs:13
void WriteLine(string str, bool bOverrideEnabled=false, bool bHeader=false, bool bError=false, bool bDisable=false)
Write a line of output.
Definition: Log.cs:80
The SimpleDatum class holds a data input within host memory.
Definition: SimpleDatum.cs:161
int OriginalLabel
Get/set the original known label of the data.
static SimpleDatum CalculateMean(Log log, SimpleDatum[] rgImg, WaitHandle[] rgAbort)
Calculate the mean of an array of SimpleDatum and return the mean as a new SimpleDatum.
void ResetBoost()
Reset the boost to the original boost.
void SetLabel(int nLabel)
Sets the label.
SimpleDatum Add(SimpleDatum d)
Creates a new SimpleDatum and adds another SimpleDatum to it.
int Boost
Get/set the boost for this data.
int Index
Returns the index of the SimpleDatum.
int Label
Return the known label of the data.
int ID
Get/set the database ID of the item.
string Name
Get/set the name of the item.
The LabelDescriptor class describes a single label.
int ImageCount
Specifies the number of images under this label.
int ActiveLabel
Specifies the active label (used during training).
int Label
Specifies the original label
string Name
Specifies the label name.
The SourceDescriptor class contains all information describing a data source.
bool IsRealData
Returns whether or not the each data point represents a real or integer number. Integer numbers are u...
List< LabelDescriptor > Labels
Get/set the list of LabelDescriptors that describe the labels used by the data items.
int ImageCount
Returns the number of images within this data source.
The DatasetFactory manages the connection to the Database object.
void AddLabelBoost(int nProjectId, int nLabel, double dfBoost, int nSrcId=0)
Add a label boost to the database for a given project.
void ResetLabels(int nProjectId=0, int nSrcId=0)
Resets all labels back to their original labels for a project.
void UpdateLabelCounts(Dictionary< int, int > rgCounts)
Updates the label counts in the database for the open data source.
SimpleDatum LoadImage(int nImageId, int nSrcId=0)
Returns the image at a given image ID.
string GetLabelCountsAsText(int nSrcId)
Returns the label counts for a given data source.
DatasetFactory()
The DatasetFactory constructor.
void UpdateLabelMapping(int nNewLabel, List< int > rgOriginalLabels, int nSrcId=0)
Update a label mapping in the database for a data source.
SimpleDatum LoadImageAt(int nIdx, bool? bLoadDataCriteria=null, bool? bLoadDebugData=null, int nSrcId=0, int nPadW=0, int nPadH=0)
Load an image at a given index.
void LoadRawData(SimpleDatum sd, bool bLoadDataCriteria, bool bLoadDebugData)
Load the data criteria and/or debug data.
void Close()
Close the current data source used.
void SetLabelMapping(LabelMapping map, int nSrcId=0)
Saves a label mapping in the database for a data source.
Dictionary< int, int > LoadLabelCounts(int nSrcId=0)
Load the label counts from the database for a data source.
void Dispose()
Releases all resources used.
void DeleteLabelBoosts(int nProjectId, int nSrcId=0)
Delete all label boosts for a project.
string GetLabelBoostsAsText(int nProjectId, int nSrcId=0, bool bSort=true)
Returns the Label boosts as a string.
List< LabelBoostDescriptor > GetLabelBoosts(int nProjectId, int nSrcId=0)
Returns a list of all label boosts set on a project.
void Open(SourceDescriptor src, int nCacheMax=500, ConnectInfo ci=null)
Open a given data source.
The ImageSet class contains the list of image for a data source as well as a list of LabelSets that m...
Definition: Imageset.cs:17
string GetQueryBoostHitPrecentsAsText()
Get the queried boost hit percents as a string.
Definition: Imageset.cs:137
int FindImageIndex(DateTime dt, string strDesc)
Searches for an image index based on its time-stamp and description.
Definition: Imageset.cs:263
EventHandler< CalculateImageMeanArgs > OnCalculateImageMean
The OnCalculateImageMean event fires when the ImageSet needs to calculate the image mean for the imag...
Definition: Imageset.cs:43
Dictionary< int, int > LoadLabelCounts()
Returns the label counts as a dictionary of item pairs (int nLabel, int nCount).
Definition: Imageset.cs:837
SimpleDatum GetImage(int nImageID)
Returns the SimpleDatum of the image at a given ID.
Definition: Imageset.cs:610
List< SimpleDatum > GetImages(DateTime dt, int nImageCount, string strFilterVal=null)
Get a set of images, listed in chronological order starting at the next date greater than or equal to...
Definition: Imageset.cs:918
Dictionary< int, ulong > GetQueryLabelCounts()
Retrieves the label counts.
Definition: Imageset.cs:111
string GetLabelCountsAsText()
Returns the label counts for the ImageList as text.
Definition: Imageset.cs:855
List< SimpleDatum > GetImages(bool bSuperboostOnly, string strFilterVal, int? nBoostVal, int[] rgIdx)
Returns the array of images in the image set, possibly filtered with the filtering parameters.
Definition: Imageset.cs:516
ImageSet Clone()
Returns a copy of the ImageSet.
Definition: Imageset.cs:220
string SourceName
Returns the data source name of the image set.
Definition: Imageset.cs:410
int GetCount(bool bSuperboostOnly, string strFilterVal=null, int? nBoostVal=null)
Returns the number of images in the image set, optionally with super-boost only.
Definition: Imageset.cs:479
void DeleteLabelBoosts(int nProjectId)
Deletes the label boosts for a project.
Definition: Imageset.cs:807
virtual void Dispose(bool bDisposing)
Releases the resouces used.
Definition: Imageset.cs:89
int GetLoadedCount()
Returns the number of images loaded.
Definition: Imageset.cs:885
void SetQueryLabelCount(int nLabel, int nBoost)
Increase the query label count for a specific label.
Definition: Imageset.cs:124
void UpdateLabelCounts(int nProjectId)
Updates the label counts for a project.
Definition: Imageset.cs:846
SimpleDatum GetImage(int nIdx, DB_LABEL_SELECTION_METHOD labelSelectionMethod, DB_ITEM_SELECTION_METHOD imageSelectionMethod, Log log, bool bLoadDataCriteria=false, bool bLoadDebugData=false)
Returns the image based on its label and image selection method.
Definition: Imageset.cs:535
int SourceID
Returns the data source ID of the image set.
Definition: Imageset.cs:402
void Relabel(LabelMappingCollection col)
Applies the label mapping to the image set.
Definition: Imageset.cs:206
void CompleteLoad(int nLastImageIdx)
Complete the image loading process.
Definition: Imageset.cs:377
void UpdateLabelBoosts(int nProjectId)
Update the label boosts for a project.
Definition: Imageset.cs:754
bool Sort(IMGDB_SORT method)
Sort the internal images.
Definition: Imageset.cs:932
void SetImageMean(SimpleDatum d)
Set the image mean on for the ImageSet.
Definition: Imageset.cs:703
List< SimpleDatum > GetImages(bool bSuperboostOnly, string strFilterVal=null, int? nBoostVal=null, int nStartIdx=0, int nQueryCount=int.MaxValue)
Returns the array of images in the image set, possibly filtered with the filtering parameters.
Definition: Imageset.cs:496
void Reset()
Resets the indexes and limited loaded images (if used).
Definition: Imageset.cs:294
string GetQueryLabelEpocsAsText()
Get the queried label epoc per label as a text string.
Definition: Imageset.cs:161
ImageSet(DatasetFactory factory, SourceDescriptor src, DB_LOAD_METHOD loadMethod, int nLoadLimit, CryptoRandom random)
The ImageSet constructor.
Definition: Imageset.cs:53
void UpdateLabelMapping(int nNewLabel, List< int > rgOriginalLabels)
Update the label mapping on the ImageSet.
Definition: Imageset.cs:789
string GetLabelName(int nLabel)
Returns the label name of a label.
Definition: Imageset.cs:191
bool Add(int nIdx, SimpleDatum d)
Adds a new image to the image set.
Definition: Imageset.cs:307
int Count
Returns the number of images in the image set.
Definition: Imageset.cs:426
SourceDescriptor Source
Returns the data source of the image set.
Definition: Imageset.cs:394
void Dispose()
Releases the resouces used.
Definition: Imageset.cs:102
void ResetAllBoosts()
Resets all image boosts to the original boost loaded from the physical database.
Definition: Imageset.cs:902
void AddLabelBoost(int nProjectId, int nLabel, double dfBoost)
Adds a label boost for a project.
Definition: Imageset.cs:818
void ReloadLabelSets()
Reload the label sets.
Definition: Imageset.cs:343
void SetLabelMapping(LabelMapping map)
Set the label mapping of the ImageSet.
Definition: Imageset.cs:779
SimpleDatum GetImageMean(Log log, WaitHandle[] rgAbort)
Returns the image mean for the ImageSet.
Definition: Imageset.cs:714
void ResetLabels(int nProjectId)
Resets the labels for a project.
Definition: Imageset.cs:798
ImageSet()
The Imageset constructor.
Definition: Imageset.cs:80
void Unload()
Unload all images in the image set.
Definition: Imageset.cs:863
string GetQueryLabelHitPrecentsAsText()
Get the queried label hit percents as a string.
Definition: Imageset.cs:149
bool IsRealData
Returns whether or not the image set contains real or byte based data.
Definition: Imageset.cs:418
int GetTotalCount()
Returns the total number of images.
Definition: Imageset.cs:894
string GetLabelBoostsAsText(int nProjectId)
Returns the label boosts as text.
Definition: Imageset.cs:828
SimpleDatum[] Images
Get the array of images.
Definition: Imageset.cs:434
LabelSet GetLabelSet(int nLabel)
Retuns the LabelSet corresponding to a label.
Definition: Imageset.cs:631
List< LabelDescriptor > GetLabels()
Returns a list of label descriptors used by the image set.
Definition: Imageset.cs:174
The LabelBoostDescriptor class describes a label boost.
The LabelSet 'points' into the main image list via references objects that are already created in the...
Definition: Labelset.cs:15
void Add(SimpleDatum s)
Adds an image to the current index and then advances the internal index.
Definition: Labelset.cs:88
SimpleDatum GetImage(int nIdx, DB_ITEM_SELECTION_METHOD selectionMethod)
Returns an image from the LabelSet using the image selection method.
Definition: Labelset.cs:103
int Count
Returns the number of images in the label set.
Definition: Labelset.cs:47
void Unload()
Unload all images from the label set.
Definition: Labelset.cs:213
LabelDescriptor Label
Get/set the label of the LabelSet.
Definition: Labelset.cs:38
void Clear()
Clears the list of images.
Definition: Labelset.cs:54
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
DB_ITEM_SELECTION_METHOD
Defines the item (e.g., image or temporal item) selection method.
Definition: Interfaces.cs:278
DB_LOAD_METHOD
Defines how to laod the items into the in-memory database.
Definition: Interfaces.cs:154
IMGDB_SORT
Defines the sorting method.
Definition: Interfaces.cs:358
DB_LABEL_SELECTION_METHOD
Defines the label selection method.
Definition: Interfaces.cs:333
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