2using System.Collections.Generic;
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;
46 bool m_bSkipMeanCheck =
false;
66 m_userGuid = Guid.NewGuid();
68 InitializeComponent();
72 log.WriteLine(
"INFO: Using MyCaffe Image Database VERSION 1.");
83 InitializeComponent();
96 private void init(
string strId =
"",
int nSeed = 0)
98 int nProcessID = Process.GetCurrentProcess().Id;
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());
108 private void dispose()
112 if (m_evtInitialized !=
null)
114 m_evtInitialized.Dispose();
115 m_evtInitialized =
null;
118 if (m_evtInitializing !=
null)
120 m_evtInitializing.Dispose();
121 m_evtInitializing =
null;
124 if (m_evtAbortInitialization !=
null)
126 m_evtAbortInitialization.Dispose();
127 m_evtAbortInitialization =
null;
130 if (m_random !=
null)
142 get {
return m_log; }
143 set { m_log = value; }
184 return new Tuple<DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD>(labelSelectionMethod, imageSelectionMethod);
213 return new Tuple<DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD>(labelSelectionMethod, imageSelectionMethod);
222 return new Tuple<DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD>(m_labelSelectionMethod, m_imageSelectionMethod);
233 m_labelSelectionMethod = lbl.Value;
236 m_imageSelectionMethod = img.Value;
260 get {
return m_colDatasets[m_nStrIDHashCode].UseTrainingSourcesForTesting; }
261 set { m_colDatasets[m_nStrIDHashCode].EnableUsingTrainingSourcesForTesting(value); }
269 get {
return m_dfSuperBoostProbability; }
270 set { m_dfSuperBoostProbability = value; }
280 if (m_dfSuperBoostProbability > 0)
284 if (dfRandom <= m_dfSuperBoostProbability)
297 get {
return m_bEnabled; }
306 m_bEnabled = bEnable;
314 get {
return m_evtInitialized.WaitOne(0); }
340 string strDsName = ds.
Name;
342 if (String.IsNullOrEmpty(strDsName))
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!");
366 Tuple<DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD> selMethod =
GetSelectionMethod(s);
370 m_labelSelectionMethod = selMethod.Item1;
371 m_imageSelectionMethod = selMethod.Item2;
380 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtInitialized, m_evtInitializing, m_evtAbortInitialization }, 0);
384 if (nWait != WaitHandle.WaitTimeout)
388 if (m_colDatasets.ContainsKey(m_nStrIDHashCode))
393 m_log.
WriteLine(
"The MyCaffe Image Database is already initialized.");
411 m_evtInitializing.Set();
417 throw new Exception(
"Could not find dataset with ID = " + nDataSetID.ToString());
419 List<WaitHandle> rgAbort =
new List<WaitHandle>() { m_evtAbortInitialization };
422 if (strEvtCancel !=
null)
425 rgAbort.AddRange(evtCancel.
Handles);
430 if (m_colDatasets.ContainsKey(m_nStrIDHashCode))
431 col = m_colDatasets[m_nStrIDHashCode];
435 if (m_evtAbortInitialization.WaitOne(0))
449 if (!ds0.
Initialize(ds, rgAbort.ToArray(), nPadW, nPadH, m_log, m_loadMethod, m_nLoadLimit, m_bSkipMeanCheck))
460 if (!m_colDatasets.ContainsKey(m_nStrIDHashCode))
461 m_colDatasets.Add(m_nStrIDHashCode, col);
469 m_evtInitialized.Set();
470 m_evtInitializing.Reset();
480 public void CleanUp(
int nDsId = 0,
bool bForce =
false)
484 if (m_evtInitializing.WaitOne(0))
486 m_evtAbortInitialization.Set();
490 List<int> rgRemove =
new List<int>();
492 foreach (KeyValuePair<int, DatasetExCollection> col
in m_colDatasets)
498 rgRemove.
Add(col.Key);
503 foreach (
int nKey
in rgRemove)
505 m_colDatasets.Remove(nKey);
508 if (m_colDatasets.Count == 0)
510 if (m_evtInitialized.WaitOne(0))
511 m_evtInitialized.Reset();
523 if (m_nLoadLimit == 0)
528 if (!m_evtInitialized.WaitOne(0))
531 List<WaitHandle> rgAbort =
new List<WaitHandle>() { m_evtAbortInitialization };
534 if (strEvtCancel !=
null)
537 rgAbort.AddRange(evtCancel.
Handles);
540 if (!m_colDatasets.ContainsKey(m_nStrIDHashCode))
548 if (m_evtAbortInitialization.WaitOne(0))
554 if (!ds.
Initialize(
null, rgAbort.ToArray(), m_nPadW, m_nPadH, m_log, m_loadMethod, m_nLoadLimit))
572 m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcID).UpdateLabelBoosts(nProjectID);
582 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
587 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).Count;
600 public int GetItemCount(
int nSrcId,
string strFilterVal =
null,
int? nBoostVal =
null,
bool bBoostValIsExact =
false)
602 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
607 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetCount(nBoostVal.HasValue, strFilterVal, nBoostVal);
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)
625 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
629 if (bAttemptDirectLoad)
630 throw new Exception(
"Direct load attempts are not supported by the Image Database V1.");
632 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetImages(nBoostVal.HasValue, strFilterVal, nBoostVal, nStartIdx, nQueryCount);
647 public List<SimpleDatum>
GetItemsFromTime(
int nSrcId, DateTime dtStart,
int nQueryCount =
int.MaxValue,
string strFilterVal =
null,
int? nBoostVal =
null,
bool bBoostValIsExact =
false)
649 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
653 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetImages(dtStart, nQueryCount, strFilterVal);
667 public List<SimpleDatum>
GetItems(
int nSrcId,
int[] rgIdx,
string strFilterVal =
null,
int? nBoostVal =
null,
bool bBoostValIsExact =
false)
669 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
673 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetImages(nBoostVal.HasValue, strFilterVal, nBoostVal, rgIdx);
684 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
689 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).Sort(method);
699 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
706 foreach (
DatasetEx ds1
in m_colDatasets[m_nStrIDHashCode])
712 DatasetEx ds = m_colDatasets[m_nStrIDHashCode].FindDataset(nDsId);
715 m_colDatasets[m_nStrIDHashCode].Add(dsNew);
728 throw new Exception(
"The dataset specified is not a dynamic dataset.");
730 DatasetEx ds = m_colDatasets[m_nStrIDHashCode].FindDataset(nDsId);
734 return m_colDatasets[m_nStrIDHashCode].RemoveDataset(ds);
742 m_colDatasets[m_nStrIDHashCode].RemoveCreatedDatasets();
758 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
766 if (labelSelectionOverride.HasValue)
767 labelSelectionMethod = labelSelectionOverride.Value;
769 if (imageSelectionOverride.HasValue)
770 imageSelectionMethod = imageSelectionOverride.Value;
775 ImageSet imgSet = m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId);
782 sd = lblSet.
GetImage(0, imageSelectionMethod);
786 throw new Exception(
"PAIR selection is not supported whith the LOAD_ON_DEMAND loading method.");
790 sd = imgSet.
GetImage(nIdx, labelSelectionMethod, imageSelectionMethod, m_log, bLoadDataCriteria, bLoadDebugData);
793 Exception err =
new Exception(
"Could not acquire an image - re-index the dataset.");
800 while (sd.
Label != nLabel.Value)
837 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
842 foreach (
int nSrcId
in rgSrcId)
844 ImageSet imgSet = m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId);
863 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
867 ImageSet imgSet = m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId);
878 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetLabels();
889 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetLabelName(nLabel);
899 DatasetEx ds = m_colDatasets[m_nStrIDHashCode].FindDataset(nDsId);
910 DatasetEx ds = m_colDatasets[m_nStrIDHashCode].FindDataset(strDs);
949 ImageSet imgSet = m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId);
963 ImageSet imgSet = m_colDatasets[m_nStrIDHashCode].FindImageset(strSrc);
1011 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).FindImageIndex(dt, strDescription);
1021 if (m_evtAbortInitialization.WaitOne(0))
1024 if (!m_evtInitialized.WaitOne(0))
1026 if (m_rgMeanCache.Keys.Contains(nSrcId))
1027 return m_rgMeanCache[nSrcId];
1030 SimpleDatum sd = m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetImageMean(
null,
null);
1032 if (!m_rgMeanCache.ContainsKey(nSrcId))
1033 m_rgMeanCache.
Add(nSrcId, sd);
1035 m_rgMeanCache[nSrcId] = sd;
1047 int nWait = WaitHandle.WaitAny(
new WaitHandle[] { m_evtAbortInitialization, m_evtInitialized });
1052 m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).SetImageMean(d);
1062 DatasetEx ds = m_colDatasets[m_nStrIDHashCode].FindDataset(nDatasetId);
1099 if (m_colDatasets.ContainsKey(m_nStrIDHashCode))
1100 m_colDatasets[m_nStrIDHashCode].SaveImageMean(nSrcId, d, bUpdate);
1110 if (!m_colDatasets.ContainsKey(m_nStrIDHashCode))
1113 return m_colDatasets[m_nStrIDHashCode].QueryImageMean(nSrcId);
1125 List<Source> rgSrc = entities.Sources.Where(p => p.ID == nSrcId).ToList();
1126 if (rgSrc.Count == 0)
1129 IQueryable<RawImageMean> iQuery = entities.RawImageMeans.Where(p => p.SourceID == nSrcId);
1132 List<RawImageMean> rgMean = iQuery.ToList();
1133 if (rgMean.Count > 0)
1148 m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).SetLabelMapping(map);
1159 m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).UpdateLabelMapping(nNewLabel, rgOriginalLabels);
1169 m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).ResetLabels(nProjectId);
1179 m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).DeleteLabelBoosts(nProjectId);
1189 public void AddLabelBoost(
int nProjectID,
int nSrcId,
int nLabel,
double dfBoost)
1191 m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).AddLabelBoost(nProjectID, nLabel, dfBoost);
1202 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetLabelBoostsAsText(nProjectId);
1212 m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).UpdateLabelCounts(nProjectID);
1222 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).LoadLabelCounts();
1232 return m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcId).GetLabelCountsAsText();
1242 return m_colDatasets[m_nStrIDHashCode].FindImageset(strSource).GetLabelCountsAsText();
1252 return m_colDatasets[m_nStrIDHashCode].FindImageset(strSource).GetQueryLabelHitPrecentsAsText();
1262 return m_colDatasets[m_nStrIDHashCode].FindImageset(strSource).GetQueryLabelEpocsAsText();
1272 return m_colDatasets[m_nStrIDHashCode].FindImageset(strSource).GetQueryBoostHitPrecentsAsText();
1304 if (!m_evtInitialized.WaitOne(0))
1305 throw new Exception(
"The image database must be initialized first before a secondary dataset can be loaded.");
1307 if (m_evtInitializing.WaitOne(0))
1308 throw new Exception(
"The image database is in the process of being initialized.");
1310 DatasetEx ds = m_colDatasets[m_nStrIDHashCode].FindDataset(nDsId);
1316 throw new Exception(
"Could not find dataset with ID = " + nDsId.ToString());
1318 if (!m_colDatasets.ContainsKey(m_nStrIDHashCode))
1319 throw new Exception(
"The image database was not initialized properly.");
1331 List<WaitHandle> rgAbort =
new List<WaitHandle>(evtCancel.
Handles);
1333 if (!ds0.
Initialize(desc, rgAbort.ToArray(), 0, 0, m_log, m_loadMethod, m_nLoadLimit))
1354 DatasetEx ds = m_colDatasets[m_nStrIDHashCode].FindDataset(nDsId);
1371 ImageSet imgset = m_colDatasets[m_nStrIDHashCode].FindImageset(nSrcID);
1388 bool bRemoved =
false;
1392 if (m_colDatasets.ContainsKey(m_nStrIDHashCode))
1419 bool bRemoved =
false;
1423 if (m_colDatasets.ContainsKey(m_nStrIDHashCode))
1431 if (ds.
DatasetID == nDataSetID || nDataSetID == -1)
1461 if (!m_colDatasets.ContainsKey(m_nStrIDHashCode))
1485 if (!m_colDatasets.ContainsKey(m_nStrIDHashCode))
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...
string Database
Get/set the database.
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.
void WriteError(Exception e)
Write an error as 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,...
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.
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...
int DatasetID
Returns the dataset ID of the dataset managesd by the DatasetEx object.
void ReloadLabelSets()
Reloads bot the training and testing label sets.
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.
DatasetEx Clone(bool bReOrganizeByTime=false)
Copy the DatasetEx and its contents.
string DatasetName
Returns the dataset name of the dataset managesd by the DatasetEx object.
int OriginalDatasetID
Returns the original DatsetID if this is a cloned re-organized dataset, otherwise 0 is returned.
void Unload()
Unload the images of the training and testing image sets.
DatasetDescriptor Descriptor
Returns the dataset descriptor of the dataset managesd by the DatasetEx object.
EventHandler< CalculateImageMeanArgs > OnCalculateImageMean
The OnCalculateImageMean event is passed to each image set and fires each time the Image set need to ...
int AddUser(Guid user)
Adds a user of the dataset.
double GetPercentageLoaded(out double dfTraining, out double dfTesting)
Returns the total percentage of images loaded for testing, training and combined.
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...
void SetQueryLabelCount(int nLabel, int nBoost)
Increase the query label count for a specific label.
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.
void Reset()
Resets the indexes and limited loaded images (if used).
SourceDescriptor Source
Returns the data source of the image set.
void ResetAllBoosts()
Resets all image boosts to the original boost loaded from the physical database.
void ReloadLabelSets()
Reload the label sets.
LabelSet GetLabelSet(int nLabel)
Retuns the LabelSet corresponding to a label.
The LabelSet 'points' into the main image list via references objects that are already created in the...
void Add(SimpleDatum s)
Adds an image to the current index and then advances the internal index.
SimpleDatum GetImage(int nIdx, DB_ITEM_SELECTION_METHOD selectionMethod)
Returns an image from the LabelSet using the image selection method.
bool IsLoaded
Returns whether or not the label set is fully loaded or not (which is the case when first using LOAD_...
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.
Log OutputLog
Get/set the output log.
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...
The IXImageDatabase interface defines the eneral interface to the in-memory image database.
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-...