2using System.Collections.Generic;
32 int m_nStrIDHashCode = 0;
33 EventWaitHandle m_evtInitializing =
null;
34 EventWaitHandle m_evtInitialized =
null;
35 EventWaitHandle m_evtAbortInitialization =
null;
36 bool m_bEnabled =
false;
37 static object m_syncObject =
new object();
38 static Dictionary<int, DatasetExCollection2> m_colDatasets =
new Dictionary<int, DatasetExCollection2>();
39 static Dictionary<int, LabelMappingCollection> m_rgLabelMappings =
new Dictionary<int, LabelMappingCollection>();
40 Dictionary<int, SimpleDatum> m_rgMeanCache =
new Dictionary<int, SimpleDatum>();
41 double m_dfSuperBoostProbability = 0;
47 bool m_bSkipMeanCheck =
false;
67 m_userGuid = Guid.NewGuid();
69 InitializeComponent();
73 log.WriteLine(
"INFO: Using MyCaffe Image Database VERSION 2.");
84 InitializeComponent();
97 #region Initialization and Cleanup
129 string strDsName = ds.
Name;
131 if (String.IsNullOrEmpty(strDsName))
134 if (strDsName ==
null)
135 throw new Exception(
"Could not find the dataset! You must specify either the Datast name or at least the training or testing source name!");
154 Tuple<DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD> selMethod =
GetSelectionMethod(s);
158 m_labelSelectionMethod = selMethod.Item1;
159 m_imageSelectionMethod = selMethod.Item2;
168 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtInitialized, m_evtInitializing, m_evtAbortInitialization }, 0);
172 if (nWait != WaitHandle.WaitTimeout)
176 if (m_colDatasets.ContainsKey(m_nStrIDHashCode))
181 m_log.
WriteLine(
"The MyCaffe Image Database is already initialized.");
199 m_evtInitializing.Set();
205 throw new Exception(
"Could not find dataset with ID = " + nDataSetID.ToString());
207 List<WaitHandle> rgAbort =
new List<WaitHandle>() { m_evtAbortInitialization };
210 if (strEvtCancel !=
null)
213 rgAbort.AddRange(evtCancel.
Handles);
218 if (m_colDatasets.ContainsKey(m_nStrIDHashCode))
219 col = m_colDatasets[m_nStrIDHashCode];
223 if (m_evtAbortInitialization.WaitOne(0))
235 m_log.
WriteLine(
"Loading dataset '" + ds.
Name +
"'...",
true);
237 long lQueryHandle = ds0.
Initialize(ds, rgAbort.ToArray(), nPadW, nPadH, m_log, m_loadMethod, m_bSkipMeanCheck, m_nLoadLimit, s.
DbAutoRefreshScheduledUpdateInMs, s.
DbAutoRefreshScheduledReplacementPercent, s.
VeriyDatasetOnLoad);
238 if (lQueryHandle == 0)
249 if (!m_colDatasets.ContainsKey(m_nStrIDHashCode))
250 m_colDatasets.Add(m_nStrIDHashCode, col);
258 m_evtInitialized.Set();
259 m_evtInitializing.Reset();
317 private void init(
string strId =
"",
int nSeed = 0)
319 int nProcessID = Process.GetCurrentProcess().Id;
323 m_nStrIDHashCode = strId.GetHashCode();
324 m_evtInitializing =
new EventWaitHandle(
false, EventResetMode.ManualReset,
"__CAFFE_IMAGEDATABASE__INITIALIZING__" + nProcessID.ToString());
325 m_evtInitialized =
new EventWaitHandle(
false, EventResetMode.ManualReset,
"__CAFFE_IMAGEDATABASE__INITIALIZED__" + nProcessID.ToString());
326 m_evtAbortInitialization =
new EventWaitHandle(
false, EventResetMode.ManualReset,
"__CAFFE_IMAGEDATABASE__ABORT_INITIALIZE__" + nProcessID.ToString());
334 public void CleanUp(
int nDsId = 0,
bool bForce =
false)
338 if (m_evtInitializing !=
null && m_evtInitializing.WaitOne(0))
340 m_evtAbortInitialization.Set();
344 List<int> rgRemove =
new List<int>();
346 foreach (KeyValuePair<int, DatasetExCollection2> col
in m_colDatasets)
352 rgRemove.
Add(col.Key);
357 foreach (
int nKey
in rgRemove)
359 m_colDatasets.Remove(nKey);
362 if (m_colDatasets.Count == 0)
364 if (m_evtInitialized.WaitOne(0))
365 m_evtInitialized.Reset();
370 private void dispose()
374 if (m_evtInitialized !=
null)
376 m_evtInitialized.Dispose();
377 m_evtInitialized =
null;
380 if (m_evtInitializing !=
null)
382 m_evtInitializing.Dispose();
383 m_evtInitializing =
null;
386 if (m_evtAbortInitialization !=
null)
388 m_evtAbortInitialization.Dispose();
389 m_evtAbortInitialization =
null;
392 if (m_random !=
null)
409 int nWait1 = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
413 return m_colDatasets[m_nStrIDHashCode].WaitForDatasetToLoad(nDsId, bTraining, bTesting, nWait);
426 int nWait1 = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
430 return m_colDatasets[m_nStrIDHashCode].WaitForDatasetToLoad(strDs, bTraining, bTesting, nWait);
440 int nWait1 = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
444 m_colDatasets[m_nStrIDHashCode].ReloadIndexing(nDsId);
455 int nWait1 = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
459 m_colDatasets[m_nStrIDHashCode].ReloadIndexing(strDs);
494 int nWait1 = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
498 return m_colDatasets[m_nStrIDHashCode].WaitForDatasetToRefresh(nDsId, bTraining, bTesting, nWait);
511 int nWait1 = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
515 return m_colDatasets[m_nStrIDHashCode].WaitForDatasetToRefresh(strDs, bTraining, bTesting, nWait);
527 int nWait1 = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
531 return m_colDatasets[m_nStrIDHashCode].IsRefreshRunning(nDsId, bTraining, bTesting);
543 int nWait1 = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
547 return m_colDatasets[m_nStrIDHashCode].IsRefreshRunning(strDs, bTraining, bTesting);
561 public bool StartRefresh(
string strDs,
bool bTraining,
bool bTesting,
double dfReplacementPct)
563 int nWait1 = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
567 return m_colDatasets[m_nStrIDHashCode].StartRefresh(strDs, bTraining, bTesting, dfReplacementPct);
580 public bool StopRefresh(
string strDs,
bool bTraining,
bool bTesting)
582 int nWait1 = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
586 return m_colDatasets[m_nStrIDHashCode].StopRefresh(strDs, bTraining, bTesting);
600 public bool StartRefresh(
int nDsID,
bool bTraining,
bool bTesting,
double dfReplacementPct)
602 int nWait1 = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
606 return m_colDatasets[m_nStrIDHashCode].StartRefresh(nDsID, bTraining, bTesting, dfReplacementPct);
621 int nWait1 = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
625 return m_colDatasets[m_nStrIDHashCode].StopRefresh(nDsID, bTraining, bTesting);
639 int nWait1 = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
643 if (nPeriodInMs <= 0 || dfReplacementPct <= 0)
646 return m_colDatasets[m_nStrIDHashCode].StartAutomaticRefreshSchedule(strDs, bTraining, bTesting, nPeriodInMs, dfReplacementPct);
658 int nWait1 = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
662 return m_colDatasets[m_nStrIDHashCode].StopAutomaticRefreshSchedule(strDs, bTraining, bTesting);
677 dfReplacementPct = 0;
678 nTrainingRefreshCount = 0;
679 nTestingRefreshCount = 0;
681 int nWait1 = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
685 return m_colDatasets[m_nStrIDHashCode].GetScheduledAutoRefreshInformation(strDs, out nPeriodInMs, out dfReplacementPct, out nTrainingRefreshCount, out nTestingRefreshCount);
699 int nWait1 = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
703 if (nPeriodInMs <= 0 || dfReplacementPct <= 0)
706 return m_colDatasets[m_nStrIDHashCode].StartAutomaticRefreshSchedule(nDsID, bTraining, bTesting, nPeriodInMs, dfReplacementPct);
718 int nWait1 = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
722 return m_colDatasets[m_nStrIDHashCode].StopAutomaticRefreshSchedule(nDsID, bTraining, bTesting);
737 dfReplacementPct = 0;
738 nTrainingRefreshCount = 0;
739 nTestingRefreshCount = 0;
741 int nWait1 = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
745 return m_colDatasets[m_nStrIDHashCode].GetScheduledAutoRefreshInformation(nDsID, out nPeriodInMs, out dfReplacementPct, out nTrainingRefreshCount, out nTestingRefreshCount);
762 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
766 return m_colDatasets[m_nStrIDHashCode].CreateQueryState(nDsId, bUseUniqueLabelIndexes, bUseUniqueImageIndexes, sort);
779 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
783 return m_colDatasets[m_nStrIDHashCode].CreateQueryState(strDs, bUseUniqueLabelIndexes, bUseUniqueImageIndexes, sort);
794 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
798 return m_colDatasets[m_nStrIDHashCode].SetDefaultQueryState(nDsId, lQueryState);
809 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
813 return m_colDatasets[m_nStrIDHashCode].SetDefaultQueryState(strDs, lQueryState);
824 return m_colDatasets[m_nStrIDHashCode].FreeQueryState(nDsId, lHandle);
835 return m_colDatasets[m_nStrIDHashCode].FreeQueryState(strDs, lHandle);
846 return m_colDatasets[m_nStrIDHashCode].FindQueryState(lQueryState, strSource).GetQueryBoostHitPercentsAsText();
857 return m_colDatasets[m_nStrIDHashCode].FindQueryState(lQueryState, strSource).GetQueryLabelHitPercentsAsText();
868 return m_colDatasets[m_nStrIDHashCode].FindQueryState(lQueryState, strSource).GetQueryLabelEpochsAsText();
910 get {
return m_log; }
911 set { m_log = value; }
937 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
942 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetTotalCount();
955 public int GetItemCount(
int nSrcId,
string strFilterVal =
null,
int? nBoostVal =
null,
bool bBoostValIsExact =
false)
957 return GetImageCount(0, nSrcId, strFilterVal, nBoostVal, bBoostValIsExact);
971 public int GetImageCount(
long lQueryState,
int nSrcId,
string strFilterVal =
null,
int? nBoostVal =
null,
bool bBoostValIsExact =
false)
973 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
977 QueryState qstate = m_colDatasets[m_nStrIDHashCode].FindQueryState(lQueryState, nSrcId);
978 ImageSet2 imgSet = m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId);
980 return imgSet.
GetCount(qstate, strFilterVal, nBoostVal, bBoostValIsExact);
1012 return new Tuple<DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD>(labelSelectionMethod, imageSelectionMethod);
1041 return new Tuple<DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD>(labelSelectionMethod, imageSelectionMethod);
1050 return new Tuple<DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD>(m_labelSelectionMethod, m_imageSelectionMethod);
1061 m_labelSelectionMethod = lbl.Value;
1064 m_imageSelectionMethod = img.Value;
1072 get {
return m_colDatasets[m_nStrIDHashCode].UseTrainingSourcesForTesting; }
1073 set { m_colDatasets[m_nStrIDHashCode].EnableUsingTrainingSourcesForTesting(value); }
1081 get {
return m_dfSuperBoostProbability; }
1082 set { m_dfSuperBoostProbability = value; }
1092 if (m_dfSuperBoostProbability > 0)
1096 if (dfRandom <= m_dfSuperBoostProbability)
1109 get {
return m_bEnabled; }
1118 m_bEnabled = bEnable;
1126 get {
return m_evtInitialized.WaitOne(0); }
1131 #region Image Acquisition
1146 public List<SimpleDatum>
GetItemsFromIndex(
int nSrcId,
int nStartIdx,
int nQueryCount =
int.MaxValue,
string strFilterVal =
null,
int? nBoostVal =
null,
bool bBoostValIsExact =
false,
bool bAttemptDirectLoad =
false)
1148 return GetImagesFromIndex(0, nSrcId, nStartIdx, nQueryCount, strFilterVal, nBoostVal, bBoostValIsExact, bAttemptDirectLoad);
1163 public List<SimpleDatum>
GetItemsFromTime(
int nSrcId, DateTime dtStart,
int nQueryCount =
int.MaxValue,
string strFilterVal =
null,
int? nBoostVal =
null,
bool bBoostValIsExact =
false)
1165 return GetImagesFromTime(0, nSrcId, dtStart, nQueryCount, strFilterVal, nBoostVal, bBoostValIsExact);
1182 public List<SimpleDatum>
GetImagesFromIndex(
long lQueryState,
int nSrcId,
int nStartIdx,
int nQueryCount =
int.MaxValue,
string strFilterVal =
null,
int? nBoostVal =
null,
bool bBoostValIsExact =
false,
bool bAttemptDirectLoad =
false)
1184 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
1188 QueryState qstate = m_colDatasets[m_nStrIDHashCode].FindQueryState(lQueryState, nSrcId);
1189 ImageSet2 imgSet = m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId);
1191 return imgSet.
GetImages(qstate, nStartIdx, nQueryCount, strFilterVal, nBoostVal, bBoostValIsExact, bAttemptDirectLoad);
1207 public List<SimpleDatum>
GetImagesFromTime(
long lQueryState,
int nSrcId, DateTime dtStart,
int nQueryCount =
int.MaxValue,
string strFilterVal =
null,
int? nBoostVal =
null,
bool bBoostValIsExact =
false)
1209 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
1213 QueryState qstate = m_colDatasets[m_nStrIDHashCode].FindQueryState(lQueryState, nSrcId);
1214 ImageSet2 imgSet = m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId);
1216 return imgSet.
GetImages(qstate, dtStart, nQueryCount, strFilterVal, nBoostVal, bBoostValIsExact);
1230 public List<SimpleDatum>
GetItems(
int nSrcId,
int[] rgIdx,
string strFilterVal,
int? nBoostVal,
bool bBoostValIsExact =
false)
1232 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
1236 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetImages(nBoostVal.HasValue, strFilterVal, nBoostVal, rgIdx);
1253 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
1260 if (labelSelectionOverride.HasValue)
1261 labelSelectionMethod = labelSelectionOverride.Value;
1263 if (imageSelectionOverride.HasValue)
1264 imageSelectionMethod = imageSelectionOverride.Value;
1269 QueryState qstate = m_colDatasets[m_nStrIDHashCode].FindQueryState(lQueryState, nSrcId);
1270 ImageSet2 imgSet = m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId);
1272 return imgSet.
GetImage(qstate, labelSelectionMethod, imageSelectionMethod, m_log, nLabel, nIdx, bLoadDataCriteria, bLoadDataCriteria);
1288 return QueryImage(0, nSrcId, nIdx, labelSelectionOverride, imageSelectionOverride, nLabel, bLoadDataCriteria, bLoadDebugData);
1299 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
1304 foreach (
int nSrcId
in rgSrcId)
1306 ImageSet2 imgSet = m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId);
1329 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).FindImageIndex(dt, strDescription);
1343 if (m_evtAbortInitialization.WaitOne(0))
1346 if (!m_evtInitialized.WaitOne(0))
1348 if (m_rgMeanCache.Keys.Contains(nSrcId))
1349 return m_rgMeanCache[nSrcId];
1352 SimpleDatum sd = m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetImageMean(
null,
null,
true);
1354 if (!m_rgMeanCache.ContainsKey(nSrcId))
1355 m_rgMeanCache.
Add(nSrcId, sd);
1357 m_rgMeanCache[nSrcId] = sd;
1369 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
1374 m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).SetImageMean(d);
1384 DatasetEx2 ds = m_colDatasets[m_nStrIDHashCode].FindDataset(nDatasetId);
1421 if (m_colDatasets.ContainsKey(m_nStrIDHashCode))
1422 m_colDatasets[m_nStrIDHashCode].SaveImageMean(nSrcId, d, bUpdate);
1432 if (!m_colDatasets.ContainsKey(m_nStrIDHashCode))
1435 return m_colDatasets[m_nStrIDHashCode].QueryImageMean(nSrcId);
1447 List<Source> rgSrc = entities.Sources.Where(p => p.ID == nSrcId).ToList();
1448 if (rgSrc.Count == 0)
1451 IQueryable<RawImageMean> iQuery = entities.RawImageMeans.Where(p => p.SourceID == nSrcId);
1454 List<RawImageMean> rgMean = iQuery.ToList();
1455 if (rgMean.Count > 0)
1495 if (!m_evtInitialized.WaitOne(0))
1496 throw new Exception(
"The image database must be initialized first before a secondary dataset can be loaded.");
1498 if (m_evtInitializing.WaitOne(0))
1499 throw new Exception(
"The image database is in the process of being initialized.");
1501 DatasetEx2 ds = m_colDatasets[m_nStrIDHashCode].FindDataset(nDsId);
1507 throw new Exception(
"Could not find dataset with ID = " + nDsId.ToString());
1509 if (!m_colDatasets.ContainsKey(m_nStrIDHashCode))
1510 throw new Exception(
"The image database was not initialized properly.");
1522 List<WaitHandle> rgAbort =
new List<WaitHandle>(evtCancel.
Handles);
1524 long lQueryState = ds0.
Initialize(desc, rgAbort.ToArray(), 0, 0, m_log, m_loadMethod,
false, m_nLoadLimit);
1525 if (lQueryState == 0)
1584 DatasetEx2 ds = m_colDatasets[m_nStrIDHashCode].FindDataset(nDsId);
1601 bool bRemoved =
false;
1605 if (m_colDatasets.ContainsKey(m_nStrIDHashCode))
1632 bool bRemoved =
false;
1636 if (m_colDatasets.ContainsKey(m_nStrIDHashCode))
1644 if (ds.
DatasetID == nDataSetID || nDataSetID == -1)
1673 if (!m_colDatasets.ContainsKey(m_nStrIDHashCode))
1697 if (!m_colDatasets.ContainsKey(m_nStrIDHashCode))
1716 DatasetEx2 ds = m_colDatasets[m_nStrIDHashCode].FindDataset(nDsId);
1727 DatasetEx2 ds = m_colDatasets[m_nStrIDHashCode].FindDataset(strDs);
1766 ImageSet2 imgset = m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcID);
1787 ImageSet2 imgSet = m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId);
1801 ImageSet2 imgSet = m_colDatasets[m_nStrIDHashCode].FindImageset(strSrc);
1847 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetLabels();
1858 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetLabelName(nLabel);
1868 m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).SetLabelMapping(map);
1879 m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).UpdateLabelMapping(nNewLabel, rgOriginalLabels);
1889 m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).ResetLabels(nProjectId);
1899 m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).UpdateLabelCounts(nProjectID);
1909 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).LoadLabelCounts();
1919 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetLabelCountsAsText();
1929 return m_colDatasets[m_nStrIDHashCode].FindImageset(strSource).GetLabelCountsAsText();
1945 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
1949 DatasetEx2 ds = m_colDatasets[m_nStrIDHashCode].FindDatasetFromSource(nSrcId);
1964 public List<SimpleResult>
GetAllResults(
string strSource,
bool bRequireExtraData,
int nMax = -1)
1966 return m_colDatasets[m_nStrIDHashCode].FindImageset(strSource).GetAllResults(bRequireExtraData, nMax);
The CancelEvent provides an extension to the manual cancel event that allows for overriding the manua...
WaitHandle[] Handles
Returns the internal wait handle of the CancelEvent.
The ConnectInfo class specifies the server, database and username/password used to connect to a datab...
The CryptoRandom is a random number generator that can use either the standard .Net Random objec or t...
METHOD
Defines the random number generation method to use.
double NextDouble()
Returns a random double within the range .
The LabelMapping class represents a single label mapping.
The Log class provides general output in text form.
void WriteLine(string str, bool bOverrideEnabled=false, bool bHeader=false, bool bError=false, bool bDisable=false)
Write a line of output.
The ProjectEx class manages a project containing the solver description, model description,...
bool EnableRandomSelection
Returns whether or not random image selection is enabled. When enabled, images are randomly selected ...
bool EnablePairSelection
Returns whether or not pair selection is enabled. When using pair selection, images are queried in pa...
bool EnableLabelBalancing
Returns whether or not label balancing is enabled. When enabled, first the label set is randomly sele...
bool EnableLabelBoosting
Returns whether or not label boosting is enabled. When using Label boosting, images are selected from...
Specifies a key-value pair of properties.
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,...
double DbAutoRefreshScheduledReplacementPercent
Get/set the automatic refresh scheduled update replacement percentage used on refresh (default = 0....
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).
int DbAutoRefreshScheduledUpdateInMs
Get/set the automatic refresh scheduled udpate period (default = 10000, only applies when ImageDbLoad...
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 VeriyDatasetOnLoad
Get/set whether or not to verify the dataset on load (only applies when using the LOAD_ALL loading me...
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.
SimpleDatum Add(SimpleDatum d)
Creates a new SimpleDatum and adds another SimpleDatum to it.
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.
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.
[V2 Image Database] The DatasetEx2 class provides the in-memory dataset functionality that is used by...
int? DatasetID
Returns the dataset ID of the dataset managesd by the DatasetEx object.
void Unload(bool bReload)
Unload the images of the training and testing image sets.
void ResetLabels()
Resets the labels to their original labels.
int AddUser(Guid user)
Adds a user of the dataset.
long Initialize(DatasetDescriptor ds, WaitHandle[] rgAbort, int nPadW=0, int nPadH=0, Log log=null, DB_LOAD_METHOD loadMethod=DB_LOAD_METHOD.LOAD_ALL, bool bSkipMeanCheck=false, int nImageDbLoadLimit=0, int nImageDbAutoRefreshScheduledUpdateInMs=0, double dfImageDbAutoRefreshScheduledReplacementPct=0, bool bVerify=false)
Initialize the DatasetEx by loading the training and testing data sources into memory.
long DefaultQueryState
Returns the default query state created when first initializing the dataset.
DatasetDescriptor Descriptor
Returns the dataset descriptor of the dataset managesd by the DatasetEx object.
void ResetAllBoosts()
Reset all boosts for both the testing and training image sets.
EventHandler< CalculateImageMeanArgs > OnCalculateImageMean
The OnCalculateImageMean event is passed to each image set and fires each time the Image set need to ...
double GetPercentageLoaded(out double dfTraining, out double dfTesting)
Returns the total percentage of images loaded for testing, training and combined.
string DatasetName
Returns the dataset name of the dataset managesd by the DatasetEx object.
[V2 Image Database] The DatasetExCollection2 contains a list of DatasetEx2 objects.
DatasetEx2 FindDataset(int nDatasetID)
Searches for the dataset with a dataset ID.
virtual void Dispose(bool bDisposing)
Releases all resources used by the collection.
bool RemoveUser(Guid user)
Removes a user from the list of users using the DatasetExCollection.
void Add(DatasetEx2 ds)
Adds a DatasetEx to the collection.
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.
[V2 Image Database] The ImageSet2 manages the data source data including the master list of images,...
SimpleDatum GetImage(int nImageId)
Get the image at a given image ID.
List< DbItem > ResetLabels()
Reset all labels of the image set to the original labels.
List< SimpleDatum > GetImages(QueryState state, 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.
int GetCount(QueryState state, string strFilterVal=null, int? nBoostVal=null, bool bBoostValIsExact=false)
Returns the number of images in the image set, optionally with super-boost only.
SourceDescriptor Source
Returns the data source of the image set.
[V2 Image Database] The MyCaffeImageDatabase2 provides an enhanced in-memory image database used for ...
bool IsRefreshRunning(int nDsId, bool bTraining, bool bTesting)
Returns true if the refresh operation running.
Log OutputLog
Get/set the output log.
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.
bool GetLoadItemDebugData()
Returns whether or not the image debug data is loaded with each image.
SimpleDatum QueryItemMeanFromDataset(int nDatasetId)
Returns the image mean for the Training data source of a given data set.
bool DoesImageMeanExists(int nSrcId)
Returns whether or not the image mean exists in the disk-based database for a given data source.
void SetConnection(ConnectInfo ci)
Set the database connection to use.
int GetDatasetID(string strDs)
Returns a data set ID given its name.
bool UnloadDatasetById(int nDataSetID)
The UnloadDataset method removes the dataset specified from memory.
List< SimpleDatum > GetImagesFromIndex(long lQueryState, 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.
bool UseTrainingImagesForTesting
Get/set whether or not to use training images for the test set (default = false).
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.
int GetSourceID(string strSrc)
Returns a data source ID given its name.
double SuperBoostProbability
Get/set the super-boost probability which increases/decreases the probability of selecting a boosted ...
bool InitializeWithDsName1(SettingsCaffe s, string strDs, string strEvtCancel=null, PropertySet prop=null)
Initializes the image database.
bool WaitForDatasetToRefresh(string strDs, bool bTraining, bool bTesting, int nWait=int.MaxValue)
Wait for the dataset refreshing to complete.
string GetLabelQueryHitPercentsAsTextFromSourceName(long lQueryState, string strSource)
Returns a string with the query hit percent for each label (e.g. the percentage that each label has b...
void SetSelectionMethod(DB_LABEL_SELECTION_METHOD? lbl, DB_ITEM_SELECTION_METHOD? img)
Sets the label and image selection methods.
SourceDescriptor GetSourceById(int nSrcId)
Returns the SourceDescriptor for a given data source ID.
DB_VERSION GetVersion()
Returns the version of the MyCaffe Image Database being used.
string GetBoostQueryHitPercentsAsTextFromSourceName(long lQueryState, string strSource)
Returns the percentage of boosted images queried as text.
bool IsInitialized
Returns whether or not the image database is initialized.
bool WaitForDatasetToRefresh(int nDsId, bool bTraining, bool bTesting, int nWait=int.MaxValue)
Wait for the dataset refreshing to complete.
string GetLabelQueryEpocsAsTextFromSourceName(long lQueryState, string strSource)
Returns a string with the query epoch counts for each label (e.g. the number of times all images with...
bool StopAutomaticRefreshSchedule(int nDsID, bool bTraining, bool bTesting)
Stop the automatic refresh schedule running on a dataset.
EventHandler< CalculateImageMeanArgs > OnCalculateImageMean
The OnCalculateImageMean event fires each time the MyCaffeImageDatabase wants to access the image mea...
bool StartRefresh(int nDsID, bool bTraining, bool bTesting, double dfReplacementPct)
Start a refresh on the dataset by replacing a specified percentage of the images with images from the...
DatasetDescriptor GetDatasetById(int nDsId)
Returns the DatasetDescriptor for a given data set ID.
SimpleDatum GetItemMean(int nSrcId)
Returns the image mean for a data source.
bool FreeQueryState(string strDs, long lHandle)
Frees a query state from a given dataset.
bool StartRefresh(string strDs, bool bTraining, bool bTesting, double dfReplacementPct)
Start a refresh on the dataset by replacing a specified percentage of the images with images from the...
bool InitializeWithDs1(SettingsCaffe s, DatasetDescriptor ds, string strEvtCancel=null, PropertySet prop=null)
Initializes the image database.
long LoadDatasetByID(int nDsId, string strEvtCancel=null)
Load another 'secondary' dataset.
bool FreeQueryState(int nDsId, long lHandle)
Frees a query state from a given dataset.
List< LabelDescriptor > GetLabels(int nSrcId)
Returns a list of LabelDescriptors associated with the labels within a data source.
bool WaitForDatasetToLoad(string strDs, bool bTraining, bool bTesting, int nWait=int.MaxValue)
Wait for the dataset loading to complete.
bool LoadDatasetByName1(string strDs, string strEvtCancel=null)
Load another, 'secondary' dataset.
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...
string GetLabelCountsAsTextFromSourceName(string strSource)
Returns a string with all label counts for a data source.
bool IsRefreshRunning(string strDs, bool bTraining, bool bTesting)
Returns true if the refresh operation running.
bool StopRefresh(string strDs, bool bTraining, bool bTesting)
Stop a refresh operation running on the dataset.
SimpleDatum GetItem(int nImageID, params int[] rgSrcId)
Returns the image with a given Raw Image ID.
SourceDescriptor GetSourceByName(string strSrc)
Returns the SourceDescriptor for a given data source name.
void CleanUp(int nDsId=0, bool bForce=false)
Releases the image database, and if this is the last instance using the in-memory database,...
long CreateQueryState(string strDs, bool bUseUniqueLabelIndexes=true, bool bUseUniqueImageIndexes=true, IMGDB_SORT sort=IMGDB_SORT.NONE)
Create a query state for a data set, optionally using a specific sorting method.
int GetImageCount(int nSrcId)
Returns the number of images in a given data source.
long InitializeWithDsId(SettingsCaffe s, int nDataSetID, string strEvtCancel=null, int nPadW=0, int nPadH=0)
Initializes the image database.
void SaveImageMean(int nSrcId, SimpleDatum d, bool bUpdate)
Saves the image mean to a data source on the database on disk.
MyCaffeImageDatabase2(IContainer container)
The MyCaffeImageDatabase constructor.
double GetDatasetLoadedPercentByName(string strDataset, out double dfTraining, out double dfTesting)
Returns the percentage that a dataset is loaded into memory.
int GetImageCount(long lQueryState, int nSrcId, string strFilterVal=null, int? nBoostVal=null, bool bBoostValIsExact=false)
Returns the number of images in a given data source, optionally only counting the boosted images.
static Tuple< DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD > GetSelectionMethod(SettingsCaffe s)
Returns the label/image selection methods based on the SettingsCaffe settings.
static Tuple< DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD > GetSelectionMethod(ProjectEx p)
Returns the label/image selection methods based on the ProjectEx settings.
List< SimpleDatum > GetImagesFromTime(long lQueryState, 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.
bool IsEnabled
Returns whether or not the image database is enabled.
string GetLabelCountsAsTextFromSourceId(int nSrcId)
Returns a string with all label counts for a data source.
string GetLabelQueryEpocsAsTextFromSourceName(string strSource)
Returns a string with the query epoch counts for each label (e.g. the number of times all images with...
bool StartAutomaticRefreshSchedule(int nDsID, bool bTraining, bool bTesting, int nPeriodInMs, double dfReplacementPct)
Start the automatic refresh cycle to occur on specified period increments.
void SetLabelMapping(int nSrcId, LabelMapping map)
Sets the label mapping to the database for a given data source.
int GetItemCount(int nSrcId, string strFilterVal=null, int? nBoostVal=null, bool bBoostValIsExact=false)
Returns the number of images in a given data source, optionally only counting the boosted images.
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 InitializeWithDsId1(SettingsCaffe s, int nDataSetID, string strEvtCancel=null, int nPadW=0, int nPadH=0, PropertySet prop=null)
Initializes the image database.
SimpleDatum QueryImage(long lQueryState, 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.
bool GetScheduledAutoRefreshInformation(int nDsID, out int nPeriodInMs, out double dfReplacementPct, out int nTrainingRefreshCount, out int nTestingRefreshCount)
Returns whether or not a scheduled refresh is running and if so at what period and replacement percen...
MyCaffeImageDatabase2(Log log=null, string strId="default", int nSeed=0)
The MyCaffeImageDatabase2 constructor.
string GetLabelName(int nSrcId, int nLabel)
Returns the text name of a given label within a data source.
void UpdateLabelMapping(int nSrcId, int nNewLabel, List< int > rgOriginalLabels)
Updates the label mapping in the database for a given data source.
bool StopRefresh(int nDsID, bool bTraining, bool bTesting)
Stop a refresh operation running on the dataset.
bool ReloadIndexing(int nDsId)
Reload the indexing for a data set.
bool StartAutomaticRefreshSchedule(string strDs, bool bTraining, bool bTesting, int nPeriodInMs, double dfReplacementPct)
Start the automatic refresh cycle to occur on specified period increments.
bool SetDefaultQueryState(string strDs, long lQueryState)
Set the default query state to the query state specified for the dataset specified.
void ResetAllBoosts(int nSrcId)
Reset all in-memory image boosts.
bool GetScheduledAutoRefreshInformation(string strDs, out int nPeriodInMs, out double dfReplacementPct, out int nTrainingRefreshCount, out int nTestingRefreshCount)
Returns whether or not a scheduled refresh is running and if so at what period and replacement percen...
long InitializeWithDs(SettingsCaffe s, DatasetDescriptor ds, string strEvtCancel=null)
Initializes the image database.
List< SimpleDatum > GetItems(int nSrcId, int[] rgIdx, string strFilterVal, int? nBoostVal, bool bBoostValIsExact=false)
Returns the array of images in the image set, possibly filtered with the filtering parameters.
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.
bool WaitForDatasetToLoad(int nDsId, bool bTraining, bool bTesting, int nWait=int.MaxValue)
Wait for the dataset loading to complete.
DatasetDescriptor GetDatasetByName(string strDs)
Returns the DatasetDescriptor for a given data set name.
void Enable(bool bEnable)
Sets whether or not the image database is enabled.
bool GetLoadItemDataCriteria()
Returns whether or not the image data criteria is loaded with each image.
bool LoadDatasetByID1(int nDsId, string strEvtCancel=null)
Load another, 'secondary' dataset.
long InitializeWithDsName(SettingsCaffe s, string strDs, string strEvtCancel=null)
Initializes the image database.
string GetDatasetName(int nDsId)
Returns a data set name given its ID.
bool StopAutomaticRefreshSchedule(string strDs, bool bTraining, bool bTesting)
Stop the automatic refresh schedule running on a dataset.
void SetImageMean(int nSrcId, SimpleDatum d)
Sets the image mean for a data source.
void UpdateLabelCounts(int nProjectID, int nSrcId)
Updates the number of images of each label within a data source.
bool SetDefaultQueryState(int nDsId, long lQueryState)
Set the default query state to the query state specified for the dataset specified.
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.
bool SelectFromBoostOnly
Returns whether or not to select ONLY from boosted images.
long CreateQueryState(int nDsId, bool bUseUniqueLabelIndexes=true, bool bUseUniqueImageIndexes=true, IMGDB_SORT sort=IMGDB_SORT.NONE)
Create a query state for a data set, optionally using a specific sorting method.
string GetBoostQueryHitPercentsAsTextFromSourceName(string strSource)
Returns a string with the query hit percent for each boost (e.g. the percentage that each boost value...
bool ReloadIndexing(string strDs)
Reload the indexing for a data set.
double GetDatasetLoadedPercentById(int nDatasetID, out double dfTraining, out double dfTesting)
Returns the percentage that a dataset is loaded into memory.
static void CreateDatabase(ConnectInfo ci, string strPath)
Create the database used by the MyCaffeImageDatabase.
List< SimpleResult > GetAllResults(string strSource, bool bRequireExtraData, int nMax=-1)
Query all results for a given data source.
long LoadDatasetByName(string strDs, string strEvtCancel=null)
Load another 'secondary' dataset.
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...
Tuple< DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD > GetSelectionMethod()
Returns the label and image selection method used.
bool ReloadDataset(int nDsId)
Reload a data set.
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.
string GetSourceName(int nSrcId)
Returns a data source name given its ID.
void ResetLabels(int nProjectId, int nSrcId)
Resets all labels within a data source, used by a project, to their original labels.
Initially the QueryState is copied from the MasterIndexes and during each query is altered by removin...
The Component class is a standard Microsoft.NET class that implements the IComponent interface and is...
The IXImageDatabase2 interface defines the general interface to the in-memory image database (v2).
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.
DB_ITEM_SELECTION_METHOD
Defines the item (e.g., image or temporal item) selection method.
DB_LOAD_METHOD
Defines how to laod the items into the in-memory database.
DB_VERSION
Defines the image database version to use.
IMGDB_SORT
Defines the sorting method.
DB_LABEL_SELECTION_METHOD
Defines the label selection method.
The MyCaffe.db.image namespace contains all image database related classes.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...