4using System.Collections.Generic;
8using System.Threading.Tasks;
22 List<WaitHandle> m_rgAbort =
new List<WaitHandle>();
23 ManualResetEvent m_evtCancel =
new ManualResetEvent(
false);
62 m_loadMethod = loadMethod;
65 m_rgAbort.Add(m_evtCancel);
66 if (rgAbort.Length > 0)
67 m_rgAbort.AddRange(rgAbort);
74 protected override void Dispose(
bool bDisposing)
78 if (m_masterIdx !=
null)
84 if (m_masterList !=
null)
102 public QueryState Initialize(
bool bSilentLoad,
bool bUseUniqueLabelIndexes =
true,
bool bUseUniqueImageIndexes =
true,
int nMaxLoadCount = 0,
bool bVerify =
false)
104 if (m_masterList ==
null)
112 m_masterList.
Load(bSilentLoad);
115 if (m_masterIdx ==
null || m_masterIdx.
LoadLimit != nMaxLoadCount)
125 m_masterList.
Verify(m_masterIdx);
146 get {
return m_loadMethod; }
190 get {
return m_type; }
199 return m_masterList.
Load();
208 m_masterList.
Unload(bReload);
220 return new QueryState(m_masterIdx, bUseUniqueLabelIndexes, bUseUniqueImageIndexes, sort);
250 return m_masterList.
GetImageMean(log, rgAbort, bQueryOnly);
260 m_masterIdx.
Reload(rgItems);
271 m_masterIdx.
Reload(rgItems);
282 List<DbItem> rgItems = m_masterList.
Relabel(col);
283 m_masterIdx.
Reload(rgItems);
294 m_masterIdx.
Reload(rgItems);
320 return nLabel.ToString();
342 if (rgItems.Count == 0)
379 int? nIdx = state.
GetNextImage(imageSelectionMethod, nLabel, nDirectIdx);
381 if (!nIdx.HasValue || nIdx.Value < 0)
383 nIdx = state.
GetNextImage(imageSelectionMethod, nLabel, nDirectIdx);
384 if (!nIdx.HasValue || nIdx.Value < 0)
387 string strLabel = (nLabel.HasValue) ?
" for label '" + nLabel.Value.ToString() +
"'." :
".";
388 throw new Exception(
"Failed to find the image index! The data source '" +
m_src.
Name +
"' has no " + strBoosted +
" images" + strLabel +
". You may need to re-index the dataset.");
392 SimpleDatum sd = m_masterList.
GetImage(nIdx.Value, bLoadDataCriteria, bLoadDebugData, m_loadMethod);
408 public int GetCount(
QueryState state,
string strFilterVal =
null,
int? nBoostVal =
null,
bool bBoostValIsExact =
false)
410 return m_masterList.
GetCount(state, strFilterVal, nBoostVal, bBoostValIsExact);
426 public List<SimpleDatum>
GetImages(
QueryState state,
int nStartIdx,
int nQueryCount =
int.MaxValue,
string strFilterVal =
null,
int? nBoostVal =
null,
bool bBoostValIsExact =
false,
bool bAttemptDirectLoad =
false)
428 return m_masterList.
GetImages(state, nStartIdx, nQueryCount, strFilterVal, nBoostVal, bBoostValIsExact, bAttemptDirectLoad);
443 public List<SimpleDatum>
GetImages(
QueryState state, DateTime dtStart,
int nQueryCount =
int.MaxValue,
string strFilterVal =
null,
int? nBoostVal =
null,
bool bBoostValIsExact =
false)
445 return m_masterList.
GetImages(state, dtStart, nQueryCount, strFilterVal, nBoostVal, bBoostValIsExact);
458 public List<SimpleDatum>
GetImages(
bool bSuperboostOnly,
string strFilterVal,
int? nBoostVal,
int[] rgIdx)
460 return m_masterList.
GetImages(bSuperboostOnly, strFilterVal, nBoostVal, rgIdx);
The CryptoRandom is a random number generator that can use either the standard .Net Random objec or t...
The LabelMappingCollection manages a collection of LabelMapping's.
The Log class provides general output in text form.
The SimpleDatum class holds a data input within host memory.
int ID
Get/set the database ID of the item.
string Name
Get/set the name of the item.
The LabelDescriptor class describes a single label.
int ActiveLabel
Specifies the active label (used during training).
string Name
Specifies the label name.
The SourceDescriptor class contains all information describing a data source.
List< LabelDescriptor > Labels
Get/set the list of LabelDescriptors that describe the labels used by the data items.
The DatasetFactory manages the connection to the Database object.
List< SimpleResult > QueryAllResults(int nSrcID, bool bRequireExtraData=false, int nMax=-1)
Load all results for a given data source.
[V2 Image Database] The ImageSet2 manages the data source data including the master list of images,...
int GetLoadedCount()
Get the total number of images already loaded in the image set.
QueryState CreateQueryState(bool bUseUniqueLabelIndexes=true, bool bUseUniqueImageIndexes=true, IMGDB_SORT sort=IMGDB_SORT.NONE)
Create a new QueryState and optionally sort the results.
ImageSet2(TYPE type, Log log, DatasetFactory factory, SourceDescriptor src, DB_LOAD_METHOD loadMethod, CryptoRandom random, WaitHandle[] rgAbort)
The ImageSet2 constructor.
override void Dispose(bool bDisposing)
Releases the resouces used.
bool WaitForRefreshToComplete(int nWait=int.MaxValue)
Wait for the image refresh to complete loading.
SimpleDatum GetImage(int nImageId)
Get the image at a given image ID.
DB_LOAD_METHOD LoadMethod
Get the image load method used on initialization.
List< DbItem > ResetLabels()
Reset all labels of the image set to the original labels.
bool StartRefresh(double dfReplacementPct=0.25)
Start the refresh process which only valid when initialized with LoadLimit > 0.
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.
void Unload(bool bReload)
Unload all images from the master list (freeing memory) and optionally reload the dataset.
bool Load()
Starts loading the image set on the background thread if it is not already loading.
List< LabelDescriptor > GetLabels()
Returns a list of all labels used by the data source.
void SetImageMean(SimpleDatum sd, bool bSave=false)
Sets the data source image mean.
SimpleDatum GetImageMean(Log log, WaitHandle[] rgAbort, bool bQueryOnly)
Get the image mean for the iamge set, or create one if it does not exist.
bool WaitForLoadingToComplete(int nWait=int.MaxValue)
Wait for the image set to complete loading.
SimpleDatum GetImage(QueryState state, DB_LABEL_SELECTION_METHOD labelSelectionMethod, DB_ITEM_SELECTION_METHOD imageSelectionMethod, Log log, int? nLabel=null, int nDirectIdx=-1, bool bLoadDataCriteria=false, bool bLoadDebugData=false)
Returns the image based on its label and image selection method.
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.
int GetTotalCount()
Get the total number of images in the image set whether loaded or not.
string GetLabelName(int nLabel)
Return the label name of a given label.
List< SimpleDatum > GetImages(QueryState state, 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 FindImageIndex(DateTime dt, string strDesc)
Find the index of an image with the tiven date and (optionally) description.
EventHandler< CalculateImageMeanArgs > OnCalculateImageMean
The OnCalculateImageMean event fires when the ImageSet needs to calculate the image mean for the imag...
bool IsRefreshRunning
Returns whether or not the refresh is running.
List< SimpleResult > GetAllResults(bool bRequireExtraData, int nMax)
Returns all results from the RawImageResults table.
List< SimpleDatum > GetImages(bool bSuperboostOnly, string strFilterVal, int? nBoostVal, int[] rgIdx)
Returns the array of images in the image set, possibly filtered with the filtering parameters.
List< DbItem > ResetAllBoosts()
Reset all boosts to their original settings.
QueryState Initialize(bool bSilentLoad, bool bUseUniqueLabelIndexes=true, bool bUseUniqueImageIndexes=true, int nMaxLoadCount=0, bool bVerify=false)
Initialize the ImageSet by creating the master list of images, starting its background image loading ...
TYPE
Defines the type of image set.
TYPE ImageSetType
Returns the type of use for the ImageSet.
List< DbItem > Relabel(LabelMappingCollection col)
Reset the image set based on the LabelMappingCollection.
List< DbItem > ReloadIndexing()
Reload the indexing for the image set.
void StopRefresh()
Abort any refresh currently running.
The ImageSetBase class contains the list of image for a data source as well as a list of LabelSets th...
DatasetFactory m_factory
Specifies the DatasetFactory used to work with the underlying database.
SourceDescriptor m_src
Specifies the data source used with this Image Set.
The MasterIndexes stores the indexes that define the index structure of the data source data.
void Dispose()
Release all resources used.
void Reload(List< DbItem > rgItems)
Reload all images by re-loading the master index list.
int LoadLimit
Returns the load limit set during initialization.
List< DbItem > FindImageIndexes(DateTime dt)
Returns all DbItems that point to images iwth a given date.
The MasterList is responsible for loading and managing access to the master list of images for a data...
bool Load(bool bSilent=false)
Start loading the dataset.
List< DbItem > ResetAllBoosts()
Reset all image boosts.
int FindImageIndex(List< DbItem > rgItems, string strDesc)
Find the image index based by searching the rgItems for an image that contains the description specif...
SimpleDatum FindImage(int nImageId)
Find an image based on its image ID (e.g. the image ID in the database).
bool IsRefreshRunning
Returns true if the refresh is running, false otherwise.
SimpleDatum GetImageMean(Log log, WaitHandle[] rgAbort, bool bQueryOnly)
Returns the image mean for the ImageSet.
bool WaitForRefreshToComplete(List< WaitHandle > rgAbort, int nWait)
Wait for the refres to complete.
void StopRefresh()
Stop the refresh thread if running.
List< DbItem > ReloadIndexing()
Reload the image indexing.
void Dispose()
Release all resources used.
bool WaitForLoadingToComplete(List< WaitHandle > rgAbort, int nWait=int.MaxValue)
Wait for the image loading to complete - this is used when performing LOAD_ALL.
EventHandler< CalculateImageMeanArgs > OnCalculateImageMean
The OnCalculateImageMean event fires when the ImageSet needs to calculate the image mean for the imag...
bool StartRefresh(double dfReplacementPct=0.25)
Start the refresh thread which will run if the number of images stored in memory is less than the tot...
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-boosted values only.
int GetTotalCount()
Return the total number of images whether loaded or not, in the data source.
List< DbItem > Relabel(LabelMappingCollection col)
Relabel the images based on the LabelMappingCollection.
void Unload(bool bReLoad)
Unload the data source images.
SimpleDatum GetImage(int nIdx, bool bLoadDataCriteria, bool bLoadDebugData, DB_LOAD_METHOD loadMethod)
Get the image with a specific image index.
void Verify(MasterIndexes idx)
Verify the loaded images against the master indexes.
List< DbItem > ResetLabels()
Reset the labels of all images 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.
void SetImageMean(SimpleDatum d, bool bSave=false)
Set the image mean.
int GetLoadedCount()
Return the currently loaded images in the data source.
Initially the QueryState is copied from the MasterIndexes and during each query is altered by removin...
int? GetNextImage(DB_ITEM_SELECTION_METHOD imgSel, int? nLabel, int nDirectIdx)
Returns the next image in the Index set based on the selection criteria.
void UpdateStats(SimpleDatum sd)
Update the label stats.
int? GetNextLabel(DB_LABEL_SELECTION_METHOD lblSel)
Returns the next label in the Index set selected based on the selection criteria.
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.
@ TEST
Run a testing phase.
@ TRAIN
Run a training phase.
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-...