MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
MyCaffeImageDatabase.cs
1using System;
2using System.Collections.Generic;
4using System.Diagnostics;
5using System.Linq;
6using System.Text;
7using System.Drawing;
8using System.Threading;
9using MyCaffe.basecode;
11
15namespace MyCaffe.db.image
16{
27 {
28 CryptoRandom m_random = null;
29 DatasetFactory m_factory;
30 string m_strID = "";
31 int m_nStrIDHashCode = 0;
32 EventWaitHandle m_evtInitializing = null;
33 EventWaitHandle m_evtInitialized = null;
34 EventWaitHandle m_evtAbortInitialization = null;
35 bool m_bEnabled = false;
36 static object m_syncObject = new object();
37 static Dictionary<int, DatasetExCollection> m_colDatasets = new Dictionary<int, DatasetExCollection>();
38 static Dictionary<int, LabelMappingCollection> m_rgLabelMappings = new Dictionary<int, LabelMappingCollection>();
39 Dictionary<int, SimpleDatum> m_rgMeanCache = new Dictionary<int, SimpleDatum>();
40 double m_dfSuperBoostProbability = 0;
41 DB_ITEM_SELECTION_METHOD m_imageSelectionMethod = DB_ITEM_SELECTION_METHOD.RANDOM;
42 DB_LABEL_SELECTION_METHOD m_labelSelectionMethod = DB_LABEL_SELECTION_METHOD.RANDOM;
43 Log m_log;
44 DB_LOAD_METHOD m_loadMethod = DB_LOAD_METHOD.LOAD_ON_DEMAND;
45 int m_nLoadLimit = 0;
46 bool m_bSkipMeanCheck = false;
47 int m_nPadW = 0;
48 int m_nPadH = 0;
49 Guid m_userGuid;
50
51
55 public event EventHandler<CalculateImageMeanArgs> OnCalculateImageMean;
56
63 public MyCaffeImageDatabase(Log log = null, string strId = "default", int nSeed = 0)
64 {
65 m_factory = new DatasetFactory();
66 m_userGuid = Guid.NewGuid();
67 m_log = log;
68 InitializeComponent();
69 init(strId, nSeed);
70
71 if (log != null)
72 log.WriteLine("INFO: Using MyCaffe Image Database VERSION 1.");
73 }
74
79 public MyCaffeImageDatabase(IContainer container)
80 {
81 container.Add(this);
82
83 InitializeComponent();
84 init();
85 }
86
92 {
93 return DB_VERSION.IMG_V1;
94 }
95
96 private void init(string strId = "", int nSeed = 0)
97 {
98 int nProcessID = Process.GetCurrentProcess().Id;
99
100 m_random = new CryptoRandom(CryptoRandom.METHOD.DEFAULT, nSeed);
101 m_strID = strId;
102 m_nStrIDHashCode = strId.GetHashCode();
103 m_evtInitializing = new EventWaitHandle(false, EventResetMode.ManualReset, "__CAFFE_IMAGEDATABASE__INITIALIZING__" + nProcessID.ToString());
104 m_evtInitialized = new EventWaitHandle(false, EventResetMode.ManualReset, "__CAFFE_IMAGEDATABASE__INITIALIZED__" + nProcessID.ToString());
105 m_evtAbortInitialization = new EventWaitHandle(false, EventResetMode.ManualReset, "__CAFFE_IMAGEDATABASE__ABORT_INITIALIZE__" + nProcessID.ToString());
106 }
107
108 private void dispose()
109 {
110 CleanUp();
111
112 if (m_evtInitialized != null)
113 {
114 m_evtInitialized.Dispose();
115 m_evtInitialized = null;
116 }
117
118 if (m_evtInitializing != null)
119 {
120 m_evtInitializing.Dispose();
121 m_evtInitializing = null;
122 }
123
124 if (m_evtAbortInitialization != null)
125 {
126 m_evtAbortInitialization.Dispose();
127 m_evtAbortInitialization = null;
128 }
129
130 if (m_random != null)
131 {
132 m_random.Dispose();
133 m_random = null;
134 }
135 }
136
141 {
142 get { return m_log; }
143 set { m_log = value; }
144 }
145
151 {
153 }
154
160 public static Tuple<DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD> GetSelectionMethod(SettingsCaffe s)
161 {
162 DB_ITEM_SELECTION_METHOD imageSelectionMethod = DB_ITEM_SELECTION_METHOD.NONE;
163 DB_LABEL_SELECTION_METHOD labelSelectionMethod = DB_LABEL_SELECTION_METHOD.NONE;
164
166 imageSelectionMethod |= DB_ITEM_SELECTION_METHOD.RANDOM;
167
168 if (s.SuperBoostProbability > 0)
169 imageSelectionMethod |= DB_ITEM_SELECTION_METHOD.BOOST;
170
172 {
173 labelSelectionMethod |= DB_LABEL_SELECTION_METHOD.RANDOM;
174
176 labelSelectionMethod |= DB_LABEL_SELECTION_METHOD.BOOST;
177 }
178 else
179 {
181 imageSelectionMethod |= DB_ITEM_SELECTION_METHOD.PAIR;
182 }
183
184 return new Tuple<DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD>(labelSelectionMethod, imageSelectionMethod);
185 }
186
192 public static Tuple<DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD> GetSelectionMethod(ProjectEx p)
193 {
194 DB_ITEM_SELECTION_METHOD imageSelectionMethod = DB_ITEM_SELECTION_METHOD.NONE;
195 DB_LABEL_SELECTION_METHOD labelSelectionMethod = DB_LABEL_SELECTION_METHOD.NONE;
196
198 imageSelectionMethod |= DB_ITEM_SELECTION_METHOD.RANDOM;
199
201 {
202 labelSelectionMethod |= DB_LABEL_SELECTION_METHOD.RANDOM;
203
205 labelSelectionMethod |= DB_LABEL_SELECTION_METHOD.BOOST;
206 }
207 else
208 {
210 imageSelectionMethod |= DB_ITEM_SELECTION_METHOD.PAIR;
211 }
212
213 return new Tuple<DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD>(labelSelectionMethod, imageSelectionMethod);
214 }
215
220 public Tuple<DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD> GetSelectionMethod()
221 {
222 return new Tuple<DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD>(m_labelSelectionMethod, m_imageSelectionMethod);
223 }
224
231 {
232 if (lbl.HasValue)
233 m_labelSelectionMethod = lbl.Value;
234
235 if (img.HasValue)
236 m_imageSelectionMethod = img.Value;
237 }
238
243 {
244 return m_factory.LoadDataCriteria;
245 }
246
251 {
252 return m_factory.LoadDebugData;
253 }
254
259 {
260 get { return m_colDatasets[m_nStrIDHashCode].UseTrainingSourcesForTesting; }
261 set { m_colDatasets[m_nStrIDHashCode].EnableUsingTrainingSourcesForTesting(value); }
262 }
263
268 {
269 get { return m_dfSuperBoostProbability; }
270 set { m_dfSuperBoostProbability = value; }
271 }
272
277 {
278 get
279 {
280 if (m_dfSuperBoostProbability > 0)
281 {
282 double dfRandom = m_random.NextDouble(0, 1);
283
284 if (dfRandom <= m_dfSuperBoostProbability)
285 return true;
286 }
287
288 return false;
289 }
290 }
291
295 public bool IsEnabled
296 {
297 get { return m_bEnabled; }
298 }
299
304 public void Enable(bool bEnable)
305 {
306 m_bEnabled = bEnable;
307 }
308
312 public bool IsInitialized
313 {
314 get { return m_evtInitialized.WaitOne(0); }
315 }
316
325 public bool InitializeWithDsName1(SettingsCaffe s, string strDs, string strEvtCancel = null, PropertySet prop = null)
326 {
327 return InitializeWithDs1(s, new DatasetDescriptor(strDs), strEvtCancel);
328 }
329
338 public bool InitializeWithDs1(SettingsCaffe s, DatasetDescriptor ds, string strEvtCancel = null, PropertySet prop = null)
339 {
340 string strDsName = ds.Name;
341
342 if (String.IsNullOrEmpty(strDsName))
343 {
345 if (strDsName == null)
346 throw new Exception("Could not find the dataset! You must specify either the Datast name or at least the training or testing source name!");
347 }
348
349 int nDsId = m_factory.GetDatasetID(strDsName);
350
351 return InitializeWithDsId1(s, nDsId, strEvtCancel);
352 }
353
364 public bool InitializeWithDsId1(SettingsCaffe s, int nDataSetID, string strEvtCancel = null, int nPadW = 0, int nPadH = 0, PropertySet prop = null)
365 {
366 Tuple<DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD> selMethod = GetSelectionMethod(s);
367
368 m_nPadW = nPadW;
369 m_nPadH = nPadH;
370 m_labelSelectionMethod = selMethod.Item1;
371 m_imageSelectionMethod = selMethod.Item2;
372 m_dfSuperBoostProbability = s.SuperBoostProbability;
373 m_loadMethod = s.DbLoadMethod;
374 m_nLoadLimit = s.DbLoadLimit;
375 m_bSkipMeanCheck = s.SkipMeanCheck;
376
377 if (m_loadMethod == DB_LOAD_METHOD.LOAD_EXTERNAL)
378 m_loadMethod = DB_LOAD_METHOD.LOAD_ON_DEMAND;
379
380 int nWait = WaitHandle.WaitAny(new WaitHandle[] { m_evtInitialized, m_evtInitializing, m_evtAbortInitialization }, 0);
381
382 lock (m_syncObject)
383 {
384 if (nWait != WaitHandle.WaitTimeout)
385 {
386 if (nWait == 0) // already initialized.
387 {
388 if (m_colDatasets.ContainsKey(m_nStrIDHashCode))
389 {
390 DatasetExCollection col = m_colDatasets[m_nStrIDHashCode];
391
392 if (m_log != null)
393 m_log.WriteLine("The MyCaffe Image Database is already initialized.");
394
395 DatasetEx ds = col.FindDataset(nDataSetID);
396 if (ds != null)
397 {
398 ds.AddUser(m_userGuid);
399 return true;
400 }
401 }
402 }
403 else
404 {
405 return false;
406 }
407 }
408
409 try
410 {
411 m_evtInitializing.Set();
412
414
415 DatasetDescriptor ds = m_factory.LoadDataset(nDataSetID);
416 if (ds == null)
417 throw new Exception("Could not find dataset with ID = " + nDataSetID.ToString());
418
419 List<WaitHandle> rgAbort = new List<WaitHandle>() { m_evtAbortInitialization };
420 CancelEvent evtCancel;
421
422 if (strEvtCancel != null)
423 {
424 evtCancel = new CancelEvent(strEvtCancel);
425 rgAbort.AddRange(evtCancel.Handles);
426 }
427
428 DatasetExCollection col = null;
429
430 if (m_colDatasets.ContainsKey(m_nStrIDHashCode))
431 col = m_colDatasets[m_nStrIDHashCode];
432 else
433 col = new DatasetExCollection();
434
435 if (m_evtAbortInitialization.WaitOne(0))
436 {
437 col.Dispose();
438 return false;
439 }
440
441 DatasetEx ds0 = new DatasetEx(m_userGuid, m_factory, m_random);
442
443 if (OnCalculateImageMean != null)
445
446 if (m_log != null)
447 m_log.WriteLine("Loading dataset '" + ds.Name + "'...");
448
449 if (!ds0.Initialize(ds, rgAbort.ToArray(), nPadW, nPadH, m_log, m_loadMethod, m_nLoadLimit, m_bSkipMeanCheck))
450 {
451 col.Dispose();
452 return false;
453 }
454
455 if (m_log != null)
456 m_log.WriteLine("Dataset '" + ds.Name + "' loaded.");
457
458 col.Add(ds0);
459
460 if (!m_colDatasets.ContainsKey(m_nStrIDHashCode))
461 m_colDatasets.Add(m_nStrIDHashCode, col);
462
464
465 return true;
466 }
467 finally
468 {
469 m_evtInitialized.Set();
470 m_evtInitializing.Reset();
471 }
472 }
473 }
474
480 public void CleanUp(int nDsId = 0, bool bForce = false)
481 {
482 lock (m_syncObject)
483 {
484 if (m_evtInitializing.WaitOne(0))
485 {
486 m_evtAbortInitialization.Set();
487 return;
488 }
489
490 List<int> rgRemove = new List<int>();
491
492 foreach (KeyValuePair<int, DatasetExCollection> col in m_colDatasets)
493 {
494 DatasetExCollection colDs = col.Value;
495
496 if (colDs.RemoveUser(m_userGuid) || bForce)
497 {
498 rgRemove.Add(col.Key);
499 colDs.Dispose();
500 }
501 }
502
503 foreach (int nKey in rgRemove)
504 {
505 m_colDatasets.Remove(nKey);
506 }
507
508 if (m_colDatasets.Count == 0)
509 {
510 if (m_evtInitialized.WaitOne(0))
511 m_evtInitialized.Reset();
512 }
513 }
514 }
515
521 public bool LoadNextSet(string strEvtCancel)
522 {
523 if (m_nLoadLimit == 0)
524 return false;
525
526 lock (m_syncObject)
527 {
528 if (!m_evtInitialized.WaitOne(0))
529 return false;
530
531 List<WaitHandle> rgAbort = new List<WaitHandle>() { m_evtAbortInitialization };
532 CancelEvent evtCancel;
533
534 if (strEvtCancel != null)
535 {
536 evtCancel = new CancelEvent(strEvtCancel);
537 rgAbort.AddRange(evtCancel.Handles);
538 }
539
540 if (!m_colDatasets.ContainsKey(m_nStrIDHashCode))
541 return false;
542
543 DatasetExCollection col = m_colDatasets[m_nStrIDHashCode];
544 col.Reset();
545
546 foreach (DatasetEx ds in col)
547 {
548 if (m_evtAbortInitialization.WaitOne(0))
549 return false;
550
551 if (m_log != null)
552 m_log.WriteLine("Loading next limited image set for dataset '" + ds.DatasetName + "'...");
553
554 if (!ds.Initialize(null, rgAbort.ToArray(), m_nPadW, m_nPadH, m_log, m_loadMethod, m_nLoadLimit))
555 return false;
556
557 if (m_log != null)
558 m_log.WriteLine("Dataset '" + ds.DatasetName + "' re-loaded.");
559 }
560
561 return true;
562 }
563 }
564
570 public void UpdateLabelBoosts(int nProjectID, int nSrcID)
571 {
572 m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcID).UpdateLabelBoosts(nProjectID);
573 }
574
580 public int ImageCount(int nSrcId)
581 {
582 int nWait = WaitHandle.WaitAny(new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
583
584 if (nWait == 0)
585 return 0;
586
587 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).Count;
588 }
589
600 public int GetItemCount(int nSrcId, string strFilterVal = null, int? nBoostVal = null, bool bBoostValIsExact = false)
601 {
602 int nWait = WaitHandle.WaitAny(new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
603
604 if (nWait == 0)
605 return 0;
606
607 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetCount(nBoostVal.HasValue, strFilterVal, nBoostVal);
608 }
609
623 public List<SimpleDatum> GetItemsFromIndex(int nSrcId, int nStartIdx, int nQueryCount = int.MaxValue, string strFilterVal = null, int? nBoostVal = null, bool bBoostValIsExact = false, bool bAttemptDirectLoad = false)
624 {
625 int nWait = WaitHandle.WaitAny(new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
626 if (nWait == 0)
627 return null;
628
629 if (bAttemptDirectLoad)
630 throw new Exception("Direct load attempts are not supported by the Image Database V1.");
631
632 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetImages(nBoostVal.HasValue, strFilterVal, nBoostVal, nStartIdx, nQueryCount);
633 }
634
647 public List<SimpleDatum> GetItemsFromTime(int nSrcId, DateTime dtStart, int nQueryCount = int.MaxValue, string strFilterVal = null, int? nBoostVal = null, bool bBoostValIsExact = false)
648 {
649 int nWait = WaitHandle.WaitAny(new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
650 if (nWait == 0)
651 return null;
652
653 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetImages(dtStart, nQueryCount, strFilterVal);
654 }
655
667 public List<SimpleDatum> GetItems(int nSrcId, int[] rgIdx, string strFilterVal = null, int? nBoostVal = null, bool bBoostValIsExact = false)
668 {
669 int nWait = WaitHandle.WaitAny(new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
670 if (nWait == 0)
671 return null;
672
673 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetImages(nBoostVal.HasValue, strFilterVal, nBoostVal, rgIdx);
674 }
675
682 public bool Sort(int nSrcId, IMGDB_SORT method)
683 {
684 int nWait = WaitHandle.WaitAny(new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
685
686 if (nWait == 0)
687 return false;
688
689 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).Sort(method);
690 }
691
697 public int CreateDatasetOranizedByTime(int nDsId)
698 {
699 int nWait = WaitHandle.WaitAny(new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
700
701 if (nWait == 0)
702 return 0;
703
704 // If we have already created a re-organized dataset,
705 // return its DatasetID.
706 foreach (DatasetEx ds1 in m_colDatasets[m_nStrIDHashCode])
707 {
708 if (ds1.OriginalDatasetID == nDsId)
709 return ds1.DatasetID;
710 }
711
712 DatasetEx ds = m_colDatasets[m_nStrIDHashCode].FindDataset(nDsId);
713 DatasetEx dsNew = ds.Clone(true);
714
715 m_colDatasets[m_nStrIDHashCode].Add(dsNew);
716
717 return dsNew.Descriptor.ID;
718 }
719
725 public bool DeleteCreatedDataset(int nDsId)
726 {
727 if (nDsId >= 0)
728 throw new Exception("The dataset specified is not a dynamic dataset.");
729
730 DatasetEx ds = m_colDatasets[m_nStrIDHashCode].FindDataset(nDsId);
731 if (ds == null)
732 return false;
733
734 return m_colDatasets[m_nStrIDHashCode].RemoveDataset(ds);
735 }
736
741 {
742 m_colDatasets[m_nStrIDHashCode].RemoveCreatedDatasets();
743 }
744
756 public SimpleDatum QueryItem(int nSrcId, int nIdx, DB_LABEL_SELECTION_METHOD? labelSelectionOverride = null, DB_ITEM_SELECTION_METHOD? imageSelectionOverride = null, int? nLabel = null, bool bLoadDataCriteria = false, bool bLoadDebugData = false)
757 {
758 int nWait = WaitHandle.WaitAny(new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
759
760 if (nWait == 0)
761 return null;
762
763 DB_LABEL_SELECTION_METHOD labelSelectionMethod = m_labelSelectionMethod;
764 DB_ITEM_SELECTION_METHOD imageSelectionMethod = m_imageSelectionMethod;
765
766 if (labelSelectionOverride.HasValue)
767 labelSelectionMethod = labelSelectionOverride.Value;
768
769 if (imageSelectionOverride.HasValue)
770 imageSelectionMethod = imageSelectionOverride.Value;
771 else if (SelectFromBoostOnly)
772 imageSelectionMethod |= DB_ITEM_SELECTION_METHOD.BOOST;
773
774 SimpleDatum sd = null;
775 ImageSet imgSet = m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId);
776 LabelSet lblSet = null;
777
778 if (nLabel.HasValue)
779 {
780 lblSet = imgSet.GetLabelSet(nLabel.Value);
781 if (lblSet.IsLoaded)
782 sd = lblSet.GetImage(0, imageSelectionMethod);
783 }
784
785 if ((m_loadMethod == DB_LOAD_METHOD.LOAD_ON_DEMAND || m_loadMethod == DB_LOAD_METHOD.LOAD_ON_DEMAND_NOCACHE) && (imageSelectionMethod & DB_ITEM_SELECTION_METHOD.PAIR) == DB_ITEM_SELECTION_METHOD.PAIR)
786 throw new Exception("PAIR selection is not supported whith the LOAD_ON_DEMAND loading method.");
787
788 if (sd == null)
789 {
790 sd = imgSet.GetImage(nIdx, labelSelectionMethod, imageSelectionMethod, m_log, bLoadDataCriteria, bLoadDebugData);
791 if (sd == null)
792 {
793 Exception err = new Exception("Could not acquire an image - re-index the dataset.");
794 m_log.WriteError(err);
795 throw err;
796 }
797
798 if (nLabel.HasValue)
799 {
800 while (sd.Label != nLabel.Value)
801 {
802 sd = imgSet.GetImage(nIdx, labelSelectionMethod, DB_ITEM_SELECTION_METHOD.RANDOM, m_log, bLoadDataCriteria, bLoadDebugData);
803 }
804
805 lblSet.Add(sd);
806 }
807 }
808
809 imgSet.SetQueryLabelCount(sd.Label, sd.Boost);
810
811 return sd;
812 }
813
818 public void ResetQuery(int nDsID)
819 {
821
822 ImageSet imgSetTrain = m_colDatasets[m_nStrIDHashCode].FindImageset(ds.TrainingSource.ID);
823 imgSetTrain.Reset();
824
825 ImageSet imgSetTest = m_colDatasets[m_nStrIDHashCode].FindImageset(ds.TestingSource.ID);
826 imgSetTest.Reset();
827 }
828
835 public SimpleDatum GetItem(int nImageID, params int[] rgSrcId)
836 {
837 int nWait = WaitHandle.WaitAny(new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
838
839 if (nWait == 0)
840 return null;
841
842 foreach (int nSrcId in rgSrcId)
843 {
844 ImageSet imgSet = m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId);
845 SimpleDatum sd = imgSet.GetImage(nImageID);
846
847 if (sd != null)
848 return sd;
849 }
850
851 return null;
852 }
853
861 public void ResetAllBoosts(int nSrcId)
862 {
863 int nWait = WaitHandle.WaitAny(new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
864 if (nWait == 0)
865 return;
866
867 ImageSet imgSet = m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId);
868 imgSet.ResetAllBoosts();
869 }
870
876 public List<LabelDescriptor> GetLabels(int nSrcId)
877 {
878 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetLabels();
879 }
880
887 public string GetLabelName(int nSrcId, int nLabel)
888 {
889 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetLabelName(nLabel);
890 }
891
898 {
899 DatasetEx ds = m_colDatasets[m_nStrIDHashCode].FindDataset(nDsId);
900 return ds.Descriptor;
901 }
902
909 {
910 DatasetEx ds = m_colDatasets[m_nStrIDHashCode].FindDataset(strDs);
911 return ds.Descriptor;
912 }
913
919 public int GetDatasetID(string strDs)
920 {
922 if (ds == null)
923 return 0;
924
925 return ds.ID;
926 }
927
933 public string GetDatasetName(int nDsId)
934 {
936 if (ds == null)
937 return null;
938
939 return ds.Name;
940 }
941
948 {
949 ImageSet imgSet = m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId);
950 if (imgSet != null)
951 return imgSet.Source;
952
953 return null;
954 }
955
961 public SourceDescriptor GetSourceByName(string strSrc)
962 {
963 ImageSet imgSet = m_colDatasets[m_nStrIDHashCode].FindImageset(strSrc);
964 if (imgSet != null)
965 return imgSet.Source;
966
967 return null;
968 }
969
975 public int GetSourceID(string strSrc)
976 {
977 SourceDescriptor desc = GetSourceByName(strSrc);
978 if (desc == null)
979 return 0;
980
981 return desc.ID;
982 }
983
989 public string GetSourceName(int nSrcId)
990 {
991 SourceDescriptor desc = GetSourceById(nSrcId);
992 if (desc == null)
993 return null;
994
995 return desc.Name;
996 }
997
1009 public int FindItemIndex(int nSrcId, DateTime dt, string strDescription)
1010 {
1011 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).FindImageIndex(dt, strDescription);
1012 }
1013
1019 public SimpleDatum GetItemMean(int nSrcId)
1020 {
1021 if (m_evtAbortInitialization.WaitOne(0))
1022 return null;
1023
1024 if (!m_evtInitialized.WaitOne(0))
1025 {
1026 if (m_rgMeanCache.Keys.Contains(nSrcId))
1027 return m_rgMeanCache[nSrcId];
1028 }
1029
1030 SimpleDatum sd = m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetImageMean(null, null);
1031
1032 if (!m_rgMeanCache.ContainsKey(nSrcId))
1033 m_rgMeanCache.Add(nSrcId, sd);
1034 else
1035 m_rgMeanCache[nSrcId] = sd;
1036
1037 return sd;
1038 }
1039
1045 public void SetImageMean(int nSrcId, SimpleDatum d)
1046 {
1047 int nWait = WaitHandle.WaitAny(new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
1048
1049 if (nWait == 0)
1050 return;
1051
1052 m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).SetImageMean(d);
1053 }
1054
1061 {
1062 DatasetEx ds = m_colDatasets[m_nStrIDHashCode].FindDataset(nDatasetId);
1063 if (ds == null)
1064 return null;
1065
1067 }
1068
1079 {
1080 SimpleDatum sd = QueryItemMean(nSrcId);
1081
1082 if (sd != null)
1083 return sd;
1084
1085 sd = GetItemMean(nSrcId);
1086 SaveImageMean(nSrcId, sd, false);
1087
1088 return sd;
1089 }
1090
1097 public void SaveImageMean(int nSrcId, SimpleDatum d, bool bUpdate)
1098 {
1099 if (m_colDatasets.ContainsKey(m_nStrIDHashCode))
1100 m_colDatasets[m_nStrIDHashCode].SaveImageMean(nSrcId, d, bUpdate);
1101 }
1102
1108 public SimpleDatum QueryItemMean(int nSrcId)
1109 {
1110 if (!m_colDatasets.ContainsKey(m_nStrIDHashCode))
1111 return null;
1112
1113 return m_colDatasets[m_nStrIDHashCode].QueryImageMean(nSrcId);
1114 }
1115
1121 public bool DoesImageMeanExists(int nSrcId)
1122 {
1123 using (DNNEntities entities = EntitiesConnection.CreateEntities())
1124 {
1125 List<Source> rgSrc = entities.Sources.Where(p => p.ID == nSrcId).ToList();
1126 if (rgSrc.Count == 0)
1127 return false;
1128
1129 IQueryable<RawImageMean> iQuery = entities.RawImageMeans.Where(p => p.SourceID == nSrcId);
1130 if (iQuery != null)
1131 {
1132 List<RawImageMean> rgMean = iQuery.ToList();
1133 if (rgMean.Count > 0)
1134 return true;
1135 }
1136
1137 return false;
1138 }
1139 }
1140
1146 public void SetLabelMapping(int nSrcId, LabelMapping map)
1147 {
1148 m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).SetLabelMapping(map);
1149 }
1150
1157 public void UpdateLabelMapping(int nSrcId, int nNewLabel, List<int> rgOriginalLabels)
1158 {
1159 m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).UpdateLabelMapping(nNewLabel, rgOriginalLabels);
1160 }
1161
1167 public void ResetLabels(int nProjectId, int nSrcId)
1168 {
1169 m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).ResetLabels(nProjectId);
1170 }
1171
1177 public void DeleteLabelBoosts(int nProjectId, int nSrcId)
1178 {
1179 m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).DeleteLabelBoosts(nProjectId);
1180 }
1181
1189 public void AddLabelBoost(int nProjectID, int nSrcId, int nLabel, double dfBoost)
1190 {
1191 m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).AddLabelBoost(nProjectID, nLabel, dfBoost);
1192 }
1193
1200 public string GetLabelBoostsAsTextFromProject(int nProjectId, int nSrcId)
1201 {
1202 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetLabelBoostsAsText(nProjectId);
1203 }
1204
1210 public void UpdateLabelCounts(int nProjectID, int nSrcId)
1211 {
1212 m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).UpdateLabelCounts(nProjectID);
1213 }
1214
1220 public Dictionary<int, int> LoadLabelCounts(int nSrcId)
1221 {
1222 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).LoadLabelCounts();
1223 }
1224
1230 public string GetLabelCountsAsTextFromSourceId(int nSrcId)
1231 {
1232 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetLabelCountsAsText();
1233 }
1234
1240 public string GetLabelCountsAsTextFromSourceName(string strSource)
1241 {
1242 return m_colDatasets[m_nStrIDHashCode].FindImageset(strSource).GetLabelCountsAsText();
1243 }
1244
1250 public string GetLabelQueryHitPercentsAsTextFromSourceName(string strSource)
1251 {
1252 return m_colDatasets[m_nStrIDHashCode].FindImageset(strSource).GetQueryLabelHitPrecentsAsText();
1253 }
1254
1260 public string GetLabelQueryEpocsAsTextFromSourceName(string strSource)
1261 {
1262 return m_colDatasets[m_nStrIDHashCode].FindImageset(strSource).GetQueryLabelEpocsAsText();
1263 }
1264
1270 public string GetBoostQueryHitPercentsAsTextFromSourceName(string strSource)
1271 {
1272 return m_colDatasets[m_nStrIDHashCode].FindImageset(strSource).GetQueryBoostHitPrecentsAsText();
1273 }
1274
1285 public bool LoadDatasetByName1(string strDs, string strEvtCancel = null)
1286 {
1287 int nDsId = m_factory.GetDatasetID(strDs);
1288 return LoadDatasetByID1(nDsId, strEvtCancel);
1289 }
1290
1291
1302 public bool LoadDatasetByID1(int nDsId, string strEvtCancel = null)
1303 {
1304 if (!m_evtInitialized.WaitOne(0))
1305 throw new Exception("The image database must be initialized first before a secondary dataset can be loaded.");
1306
1307 if (m_evtInitializing.WaitOne(0))
1308 throw new Exception("The image database is in the process of being initialized.");
1309
1310 DatasetEx ds = m_colDatasets[m_nStrIDHashCode].FindDataset(nDsId);
1311 if (ds != null)
1312 return false;
1313
1314 DatasetDescriptor desc = m_factory.LoadDataset(nDsId);
1315 if (desc == null)
1316 throw new Exception("Could not find dataset with ID = " + nDsId.ToString());
1317
1318 if (!m_colDatasets.ContainsKey(m_nStrIDHashCode))
1319 throw new Exception("The image database was not initialized properly.");
1320
1321 DatasetExCollection col = m_colDatasets[m_nStrIDHashCode];
1322 DatasetEx ds0 = new DatasetEx(m_userGuid, m_factory, m_random);
1323
1324 if (OnCalculateImageMean != null)
1326
1327 if (m_log != null)
1328 m_log.WriteLine("Loading dataset '" + desc.Name + "'...");
1329
1330 CancelEvent evtCancel = new CancelEvent(strEvtCancel);
1331 List<WaitHandle> rgAbort = new List<WaitHandle>(evtCancel.Handles);
1332
1333 if (!ds0.Initialize(desc, rgAbort.ToArray(), 0, 0, m_log, m_loadMethod, m_nLoadLimit))
1334 {
1335 col.Dispose();
1336 return false;
1337 }
1338
1339 if (m_log != null)
1340 m_log.WriteLine("Dataset '" + desc.Name + "' loaded.");
1341
1342 col.Add(ds0);
1343
1344 return true;
1345 }
1346
1352 public bool ReloadDataset(int nDsId)
1353 {
1354 DatasetEx ds = m_colDatasets[m_nStrIDHashCode].FindDataset(nDsId);
1355 if (ds != null)
1356 {
1357 ds.ReloadLabelSets();
1358 return true;
1359 }
1360
1361 return false;
1362 }
1363
1369 public bool ReloadImageSet(int nSrcID)
1370 {
1371 ImageSet imgset = m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcID);
1372 if (imgset != null)
1373 {
1374 imgset.ReloadLabelSets();
1375 return true;
1376 }
1377
1378 return false;
1379 }
1380
1386 public bool UnloadDatasetByName(string strDataset)
1387 {
1388 bool bRemoved = false;
1389
1390 lock (m_syncObject)
1391 {
1392 if (m_colDatasets.ContainsKey(m_nStrIDHashCode))
1393 {
1394 DatasetExCollection col = m_colDatasets[m_nStrIDHashCode];
1395 DatasetEx ds = col.FindDataset(strDataset);
1396 if (ds != null)
1397 {
1398 if (m_log != null)
1399 m_log.WriteLine("Unloading dataset '" + ds.DatasetName + "'.");
1400
1401 ds.Unload();
1402 GC.Collect();
1403 bRemoved = true;
1404 }
1405 }
1406 }
1407
1408 return bRemoved;
1409 }
1410
1417 public bool UnloadDatasetById(int nDataSetID)
1418 {
1419 bool bRemoved = false;
1420
1421 lock (m_syncObject)
1422 {
1423 if (m_colDatasets.ContainsKey(m_nStrIDHashCode))
1424 {
1425 DatasetExCollection col = m_colDatasets[m_nStrIDHashCode];
1426
1427 foreach (DatasetEx ds in col)
1428 {
1429 if (ds != null)
1430 {
1431 if (ds.DatasetID == nDataSetID || nDataSetID == -1)
1432 {
1433 if (m_log != null)
1434 m_log.WriteLine("Unloading dataset '" + ds.DatasetName + "'.");
1435
1436 ds.Unload();
1437 GC.Collect();
1438 bRemoved = true;
1439 }
1440 }
1441 }
1442 }
1443 }
1444
1445 return bRemoved;
1446 }
1447
1448
1456 public double GetDatasetLoadedPercentByName(string strDataset, out double dfTraining, out double dfTesting)
1457 {
1458 dfTraining = 0;
1459 dfTesting = 0;
1460
1461 if (!m_colDatasets.ContainsKey(m_nStrIDHashCode))
1462 return 0;
1463
1464 DatasetExCollection col = m_colDatasets[m_nStrIDHashCode];
1465 DatasetEx ds = col.FindDataset(strDataset);
1466
1467 if (ds == null)
1468 return 0;
1469
1470 return ds.GetPercentageLoaded(out dfTraining, out dfTesting);
1471 }
1472
1480 public double GetDatasetLoadedPercentById(int nDatasetID, out double dfTraining, out double dfTesting)
1481 {
1482 dfTraining = 0;
1483 dfTesting = 0;
1484
1485 if (!m_colDatasets.ContainsKey(m_nStrIDHashCode))
1486 return 0;
1487
1488 DatasetExCollection col = m_colDatasets[m_nStrIDHashCode];
1489 DatasetEx ds = col.FindDataset(nDatasetID);
1490
1491 if (ds == null)
1492 return 0;
1493
1494 return ds.GetPercentageLoaded(out dfTraining, out dfTesting);
1495 }
1496
1502 public static void CreateDatabase(string strName, string strPath)
1503 {
1505
1507 Exception excpt = dbMgr.CreateDatabase();
1508
1509 if (excpt != null)
1510 throw excpt;
1511 }
1512 }
1513}
The CancelEvent provides an extension to the manual cancel event that allows for overriding the manua...
Definition: CancelEvent.cs:17
WaitHandle[] Handles
Returns the internal wait handle of the CancelEvent.
Definition: CancelEvent.cs:302
The ConnectInfo class specifies the server, database and username/password used to connect to a datab...
Definition: ConnectInfo.cs:14
string Database
Get/set the database.
Definition: ConnectInfo.cs:136
The CryptoRandom is a random number generator that can use either the standard .Net Random objec or t...
Definition: CryptoRandom.cs:14
METHOD
Defines the random number generation method to use.
Definition: CryptoRandom.cs:25
double NextDouble()
Returns a random double within the range .
Definition: CryptoRandom.cs:83
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
void WriteError(Exception e)
Write an error as output.
Definition: Log.cs:130
The ProjectEx class manages a project containing the solver description, model description,...
Definition: ProjectEx.cs:15
bool EnableRandomSelection
Returns whether or not random image selection is enabled. When enabled, images are randomly selected ...
Definition: ProjectEx.cs:648
bool EnablePairSelection
Returns whether or not pair selection is enabled. When using pair selection, images are queried in pa...
Definition: ProjectEx.cs:658
bool EnableLabelBalancing
Returns whether or not label balancing is enabled. When enabled, first the label set is randomly sele...
Definition: ProjectEx.cs:630
bool EnableLabelBoosting
Returns whether or not label boosting is enabled. When using Label boosting, images are selected from...
Definition: ProjectEx.cs:639
Specifies a key-value pair of properties.
Definition: PropertySet.cs:16
The SettingsCaffe defines the settings used by the MyCaffe CaffeControl.
bool EnableRandomInputSelection
Get/set random image selection. When enabled, images are randomly selected from the entire set,...
int DbLoadLimit
Get/set the image database load limit.
bool EnableLabelBoosting
DEPRECIATED: Get/set label boosting. When using Label boosting, images are selected from boosted labe...
double SuperBoostProbability
Get/set the superboost probability used when selecting boosted images.
DB_LOAD_METHOD DbLoadMethod
Get/set the image database loading method.
bool UseTrainingSourceForTesting
Get/set whether or not to use the training datasource when testing.
bool EnablePairInputSelection
Get/set pair image selection. When using pair selection, images are queried in pairs where the first ...
bool ItemDbLoadDebugData
Specifies whether or not to load the debug data from file (default = false).
bool ItemDbLoadDataCriteria
Specifies whether or not to load the image criteria data from file (default = false).
bool SkipMeanCheck
Skip checking for the mean of the dataset - this is not recommended for if the mean does not exist,...
bool EnableLabelBalancing
Get/set label balancing. When enabled, first the label set is randomly selected and then the image is...
The SimpleDatum class holds a data input within host memory.
Definition: SimpleDatum.cs:161
SimpleDatum Add(SimpleDatum d)
Creates a new SimpleDatum and adds another SimpleDatum to it.
int Boost
Get/set the boost for this data.
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 DatasetDescriptor class describes a dataset which contains both a training data source and testin...
SourceDescriptor TrainingSource
Get/set the training data source.
string? TrainingSourceName
Returns the training source name, or null if not specifies.
SourceDescriptor TestingSource
Get/set the testing data source.
string? TestingSourceName
Returns the testing source name or null if not specified.
The SourceDescriptor class contains all information describing a data source.
The DNNEntities class defines the entities used to connecto the database via Entity Frameworks.
The DatabaseManagement class is used to create the image database.
Exception CreateDatabase(bool bUpdateDatabase=false)
The CreateDatabae creates a new instance of the database in Microsoft SQL.
The DatasetExCollection contains a list of DatasetEx objects.
void Add(DatasetEx ds)
Adds a DatasetEx to the collection.
DatasetEx FindDataset(int nDatasetID)
Searches for the dataset with a dataset ID.
bool RemoveUser(Guid user)
Removes a user from the list of users using the DatasetExCollection.
virtual void Dispose(bool bDisposing)
Releases all resources used by the collection.
void Reset()
Resets the last image set used to null, thus clearing it.
The DatasetEx class provides the in-memory dataset functionality that is used by the image database t...
Definition: DatasetEx.cs:17
int DatasetID
Returns the dataset ID of the dataset managesd by the DatasetEx object.
Definition: DatasetEx.cs:536
void ReloadLabelSets()
Reloads bot the training and testing label sets.
Definition: DatasetEx.cs:205
bool Initialize(DatasetDescriptor ds, WaitHandle[] rgAbort, int nPadW=0, int nPadH=0, Log log=null, DB_LOAD_METHOD loadMethod=DB_LOAD_METHOD.LOAD_ALL, int nImageDbLoadLimit=0, bool bSkipMeanCheck=false)
Initialize the DatasetEx by loading the training and testing data sources into memory.
Definition: DatasetEx.cs:94
DatasetEx Clone(bool bReOrganizeByTime=false)
Copy the DatasetEx and its contents.
Definition: DatasetEx.cs:135
string DatasetName
Returns the dataset name of the dataset managesd by the DatasetEx object.
Definition: DatasetEx.cs:553
int OriginalDatasetID
Returns the original DatsetID if this is a cloned re-organized dataset, otherwise 0 is returned.
Definition: DatasetEx.cs:545
void Unload()
Unload the images of the training and testing image sets.
Definition: DatasetEx.cs:412
DatasetDescriptor Descriptor
Returns the dataset descriptor of the dataset managesd by the DatasetEx object.
Definition: DatasetEx.cs:528
EventHandler< CalculateImageMeanArgs > OnCalculateImageMean
The OnCalculateImageMean event is passed to each image set and fires each time the Image set need to ...
Definition: DatasetEx.cs:33
int AddUser(Guid user)
Adds a user of the dataset.
Definition: DatasetEx.cs:65
double GetPercentageLoaded(out double dfTraining, out double dfTesting)
Returns the total percentage of images loaded for testing, training and combined.
Definition: DatasetEx.cs:427
The DatasetFactory manages the connection to the Database object.
void SetLoadingParameters(bool bLoadDataCriteria, bool bLoadDebugData)
Sets the loading parameters that are used to determine which data to load with each image.
DatasetDescriptor LoadDataset(string strDataset, ConnectInfo ci=null)
Load a dataset descriptor from a dataset name.
bool LoadDebugData
Returns whether or not the image debug data is to be loaded when loading each image.
int GetDatasetID(string strDsName, ConnectInfo ci=null)
Returns a datasets ID given its name.
bool LoadDataCriteria
Returns whether or not the image data criteria is to be loaded when loading each image.
string FindDatasetNameFromSourceName(string strTrainSrc, string strTestSrc)
Searches for the data set name based on the training and testing source names.
The EntitiesConnection class defines how to connect to the database via Entity Frameworks.
static DNNEntities CreateEntities(ConnectInfo ci=null)
Returns the DNNEntities to use.
static ConnectInfo GlobalDatabaseConnectInfo
Get/set the global database connection info.
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
void SetQueryLabelCount(int nLabel, int nBoost)
Increase the query label count for a specific label.
Definition: Imageset.cs:124
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
void Reset()
Resets the indexes and limited loaded images (if used).
Definition: Imageset.cs:294
SourceDescriptor Source
Returns the data source of the image set.
Definition: Imageset.cs:394
void ResetAllBoosts()
Resets all image boosts to the original boost loaded from the physical database.
Definition: Imageset.cs:902
void ReloadLabelSets()
Reload the label sets.
Definition: Imageset.cs:343
LabelSet GetLabelSet(int nLabel)
Retuns the LabelSet corresponding to a label.
Definition: Imageset.cs:631
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
bool IsLoaded
Returns whether or not the label set is fully loaded or not (which is the case when first using LOAD_...
Definition: Labelset.cs:75
The MyCaffeImageDatabase provides an enhanced in-memory image database used for quick image retrieval...
EventHandler< CalculateImageMeanArgs > OnCalculateImageMean
The OnCalculateImageMean event fires each time the MyCaffeImageDatabase wants to access the image mea...
bool ReloadImageSet(int nSrcID)
Reloads the images of a data source.
Dictionary< int, int > LoadLabelCounts(int nSrcId)
Returns a label lookup of counts for a given data source.
double GetDatasetLoadedPercentByName(string strDataset, out double dfTraining, out double dfTesting)
Returns the percentage that a dataset is loaded into memory.
bool IsEnabled
Returns whether or not the image database is enabled.
void DeleteLabelBoosts(int nProjectId, int nSrcId)
Delete all label boosts for a given data source associated with a given project.
void SetConnection(ConnectInfo ci)
Set the database connection to use.
bool GetLoadItemDataCriteria()
Returns whether or not the image data criteria is loaded with each image.
void SaveImageMean(int nSrcId, SimpleDatum d, bool bUpdate)
Saves the image mean to a data source on the database on disk.
void CleanUp(int nDsId=0, bool bForce=false)
Releases the image database, and if this is the last instance using the in-memory database,...
SimpleDatum QueryItem(int nSrcId, int nIdx, DB_LABEL_SELECTION_METHOD? labelSelectionOverride=null, DB_ITEM_SELECTION_METHOD? imageSelectionOverride=null, int? nLabel=null, bool bLoadDataCriteria=false, bool bLoadDebugData=false)
Query an image in a given data source.
SimpleDatum QueryItemMeanFromDataset(int nDatasetId)
Returns the image mean for the Training data source of a given data set.
MyCaffeImageDatabase(Log log=null, string strId="default", int nSeed=0)
The MyCaffeImageDatabase constructor.
bool IsInitialized
Returns whether or not the image database is initialized.
void UpdateLabelMapping(int nSrcId, int nNewLabel, List< int > rgOriginalLabels)
Updates the label mapping in the database for a given data source.
string GetLabelCountsAsTextFromSourceId(int nSrcId)
Returns a string with all label counts for a data source.
string GetLabelBoostsAsTextFromProject(int nProjectId, int nSrcId)
Returns the label boosts as a text string for all boosted labels within a data source associated with...
void SetSelectionMethod(DB_LABEL_SELECTION_METHOD? lbl, DB_ITEM_SELECTION_METHOD? img)
Sets the label and image selection methods.
bool DeleteCreatedDataset(int nDsId)
Delete a dataset created with CreateDatasetOrganizedByTime.
DB_VERSION GetVersion()
Returns the version of the MyCaffe Image Database being used.
List< LabelDescriptor > GetLabels(int nSrcId)
Returns a list of LabelDescriptors associated with the labels within a data source.
bool UnloadDatasetByName(string strDataset)
The UnloadDataset method removes the dataset specified from memory.
SimpleDatum QueryItemMeanFromDb(int nSrcId)
Queries the image mean for a data source from the database on disk.
SourceDescriptor GetSourceByName(string strSrc)
Returns the SourceDescriptor for a given data source name.
bool LoadDatasetByName1(string strDs, string strEvtCancel=null)
Load another 'secondary' dataset.
SimpleDatum GetItemMean(int nSrcId)
Returns the image mean for a data source.
string GetSourceName(int nSrcId)
Returns a data source name given its ID.
void ResetQuery(int nDsID)
Reset the query for the given data set ID.
List< SimpleDatum > GetItems(int nSrcId, int[] rgIdx, string strFilterVal=null, int? nBoostVal=null, bool bBoostValIsExact=false)
Returns the array of images in the image set, possibly filtered with the filtering parameters.
int GetItemCount(int nSrcId, string strFilterVal=null, int? nBoostVal=null, bool bBoostValIsExact=false)
Returns the number of images in a given data source.
double GetDatasetLoadedPercentById(int nDatasetID, out double dfTraining, out double dfTesting)
Returns the percentage that a dataset is loaded into memory.
int CreateDatasetOranizedByTime(int nDsId)
Create a dynamic dataset organized by time from a pre-existing dataset.
int GetDatasetID(string strDs)
Returns a data set ID given its name.
string GetLabelName(int nSrcId, int nLabel)
Returns the text name of a given label within a data source.
bool UseTrainingImagesForTesting
Get/set whether or not to use training images for the test set (default = false).
static Tuple< DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD > GetSelectionMethod(ProjectEx p)
Returns the label/image selection methods based on the ProjectEx settings.
string GetLabelQueryHitPercentsAsTextFromSourceName(string strSource)
Returns a string with the query hit percent for each label (e.g. the percentage that each label has b...
bool SelectFromBoostOnly
Returns whether or not to select ONLY from boosted images.
bool InitializeWithDsId1(SettingsCaffe s, int nDataSetID, string strEvtCancel=null, int nPadW=0, int nPadH=0, PropertySet prop=null)
Initializes the image database.
void ResetLabels(int nProjectId, int nSrcId)
Resets all labels within a data source, used by a project, to their original labels.
void SetLabelMapping(int nSrcId, LabelMapping map)
Sets the label mapping to the database for a given data source.
SimpleDatum QueryItemMean(int nSrcId)
Query the image mean for a data source and mask out (set to 0) all of the image except for the last c...
DatasetDescriptor GetDatasetById(int nDsId)
Returns the DatasetDescriptor for a given data set ID.
DatasetDescriptor GetDatasetByName(string strDs)
Returns the DatasetDescriptor for a given data set name.
void UpdateLabelCounts(int nProjectID, int nSrcId)
Updates the number of images of each label within a data source.
bool Sort(int nSrcId, IMGDB_SORT method)
Sort the internal images.
bool InitializeWithDs1(SettingsCaffe s, DatasetDescriptor ds, string strEvtCancel=null, PropertySet prop=null)
Initializes the image database.
string GetDatasetName(int nDsId)
Returns a data set name given its ID.
double SuperBoostProbability
Get/set the super-boost probability which increases/decreases the probability of selecting a boosted ...
bool LoadDatasetByID1(int nDsId, string strEvtCancel=null)
Load another 'secondary' dataset.
string GetLabelQueryEpocsAsTextFromSourceName(string strSource)
Returns a string with the query epoch counts for each label (e.g. the number of times all images with...
void Enable(bool bEnable)
Sets whether or not the image database is enabled.
int FindItemIndex(int nSrcId, DateTime dt, string strDescription)
Searches fro the image index of an image within a data source matching a DateTime/description pattern...
SourceDescriptor GetSourceById(int nSrcId)
Returns the SourceDescriptor for a given data source ID.
bool UnloadDatasetById(int nDataSetID)
The UnloadDataset method removes the dataset specified from memory.
List< SimpleDatum > GetItemsFromIndex(int nSrcId, int nStartIdx, int nQueryCount=int.MaxValue, string strFilterVal=null, int? nBoostVal=null, bool bBoostValIsExact=false, bool bAttemptDirectLoad=false)
Returns the array of images in the image set, possibly filtered with the filtering parameters.
void AddLabelBoost(int nProjectID, int nSrcId, int nLabel, double dfBoost)
Add a label boost for a data source associated with a given project.
void UpdateLabelBoosts(int nProjectID, int nSrcID)
Updates the label boosts for the images based on the label boosts set for the given project.
static Tuple< DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD > GetSelectionMethod(SettingsCaffe s)
Returns the label/image selection methods based on the SettingsCaffe settings.
string GetLabelCountsAsTextFromSourceName(string strSource)
Returns a string with all label counts for a data source.
bool ReloadDataset(int nDsId)
Reload a data set.
bool GetLoadItemDebugData()
Returns whether or not the image debug data is loaded with each image.
static void CreateDatabase(string strName, string strPath)
Create the database used by the MyCaffeImageDatabase.
string GetBoostQueryHitPercentsAsTextFromSourceName(string strSource)
Returns the percentage of boosted images queried as text.
bool LoadNextSet(string strEvtCancel)
When using a Load Limit that is greater than 0, this function loads the next set of images.
void DeleteAllCreatedDatasets()
Delete all datasets created with CreateDatasetOrganizedByTime
void ResetAllBoosts(int nSrcId)
Reset all in-memory image boosts.
MyCaffeImageDatabase(IContainer container)
The MyCaffeImageDatabase constructor.
bool DoesImageMeanExists(int nSrcId)
Returns whether or not the image mean exists in the disk-based database for a given data source.
Tuple< DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD > GetSelectionMethod()
Returns the label and image selection method used.
List< SimpleDatum > GetItemsFromTime(int nSrcId, DateTime dtStart, int nQueryCount=int.MaxValue, string strFilterVal=null, int? nBoostVal=null, bool bBoostValIsExact=false)
Returns the array of images in the image set, possibly filtered with the filtering parameters.
int GetSourceID(string strSrc)
Returns a data source ID given its name.
bool InitializeWithDsName1(SettingsCaffe s, string strDs, string strEvtCancel=null, PropertySet prop=null)
Initializes the image database.
SimpleDatum GetItem(int nImageID, params int[] rgSrcId)
Returns the image with a given Raw Image ID.
int ImageCount(int nSrcId)
Returns the number of images in a given data source.
void SetImageMean(int nSrcId, SimpleDatum d)
Sets the image mean for a data source.
The Component class is a standard Microsoft.NET class that implements the IComponent interface and is...
Definition: Component.cs:18
The IXImageDatabase interface defines the eneral interface to the in-memory image database.
Definition: Interfaces.cs:1004
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
DB_VERSION
Defines the image database version to use.
Definition: Interfaces.cs:397
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