4using System.Collections.Generic;
 
    9using System.Threading.Tasks;
 
   22        RefreshManager m_refreshManager = 
null;
 
   23        LoadSequence m_loadSequence = 
null;
 
   24        List<WaitHandle> m_rgAbort = 
new List<WaitHandle>();
 
   25        ManualResetEvent m_evtCancel = 
new ManualResetEvent(
false);
 
   26        ManualResetEvent m_evtDone = 
new ManualResetEvent(
false);
 
   27        ManualResetEvent m_evtRunning = 
new ManualResetEvent(
false);
 
   28        ManualResetEvent m_evtRefreshCancel = 
new ManualResetEvent(
false);
 
   29        ManualResetEvent m_evtRefreshRunning = 
new ManualResetEvent(
false);
 
   30        ManualResetEvent m_evtRefreshDone = 
new ManualResetEvent(
false);
 
   31        Thread m_dataLoadThread;
 
   32        Thread m_dataRefreshThread;
 
   35        int m_nLoadedCount = 0;
 
   36        bool m_bSilent = 
false;
 
   38        int m_nReplacementBatch = 100;
 
   39        object m_syncObj = 
new object();
 
   62            m_rgAbort.Add(m_evtCancel);
 
   63            if (rgAbort.Count > 0)
 
   64                m_rgAbort.AddRange(rgAbort);
 
   68            m_nLoadCount = nMaxLoadCount;
 
   69            if (m_nLoadCount == 0 || m_nLoadCount > m_src.
ImageCount)
 
   76                m_refreshManager = 
new RefreshManager(random, m_src, m_factory);
 
   85            if (m_evtRunning.WaitOne(0))
 
   88            m_evtRefreshCancel.Set();
 
   89            if (m_evtRefreshRunning.WaitOne(0))
 
   90                m_evtRefreshDone.WaitOne();
 
  100                throw new Exception(
"The index count should match the image count!");
 
  102            List<int> rgObservedIdx = 
new List<int>();
 
  103            for (
int i = 0; i < m_rgImages.Length; i++)
 
  105                if (rgObservedIdx.Contains(m_rgImages[i].
Index))
 
  106                    throw new Exception(
"Duplicate image index found!  Your dataset may be corrupt.");
 
  109                    throw new Exception(
"The image indexs do not match!  You may need to re-index the image list.");
 
  111                rgObservedIdx.Add(m_rgImages[i].Index);
 
  122                if (m_refreshManager != 
null)
 
  145        public bool Load(
bool bSilent = 
false)
 
  149                if (m_evtRunning.WaitOne(0))
 
  155                m_dataLoadThread = 
new Thread(
new ThreadStart(dataLoadThread));
 
  156                m_dataLoadThread.Priority = ThreadPriority.AboveNormal;
 
  157                m_dataLoadThread.Start();
 
  158                m_evtRunning.WaitOne(1000);
 
  172                if (m_evtRunning.WaitOne(0))
 
  180                m_evtRunning.Reset();
 
  187                m_loadSequence = 
new LoadSequence(m_random, m_rgImages.Length, m_src.
ImageCount, m_refreshManager);
 
  203                if (m_evtRefreshRunning.WaitOne(0))
 
  209                int nMaxRefresh = (int)(m_nLoadCount * dfReplacementPct);
 
  210                if (nMaxRefresh == 0)
 
  213                m_nReplacementBatch = nMaxRefresh;
 
  214                m_evtRefreshCancel.Reset();
 
  215                m_evtRefreshDone.Reset();
 
  216                m_dataRefreshThread = 
new Thread(
new ThreadStart(dataRefreshThread));
 
  217                m_dataRefreshThread.Start();
 
  218                m_evtRefreshRunning.WaitOne();
 
  232            if (!m_evtRefreshRunning.WaitOne(0))
 
  235            List<WaitHandle> rgWait = 
new List<WaitHandle>();
 
  236            rgWait.Add(m_evtRefreshDone);
 
  237            rgWait.AddRange(rgAbort);
 
  239            int nRes = WaitHandle.WaitAny(rgWait.ToArray(), nWait);
 
  253                if (m_evtRefreshDone.WaitOne(0) || !m_evtRefreshRunning.WaitOne(0))
 
  267                return m_evtRefreshRunning.WaitOne(0);
 
  276            if (!m_evtRefreshRunning.WaitOne(0))
 
  279            m_evtRefreshCancel.Set();
 
  280            m_evtRefreshDone.WaitOne();
 
  304                return m_rgImages.Length;
 
  314            return m_nLoadedCount;
 
  326            if (m_imgMean != 
null || bQueryOnly)
 
  332            if (nLoadedCount < nTotalCount)
 
  334                double dfPct = (double)nLoadedCount / (
double)nTotalCount;
 
  337                    log.
WriteLine(
"WARNING: Cannot create the image mean until all images have loaded - the data is currently " + dfPct.ToString(
"P") + 
" loaded.");
 
  355            if (m_imgMean != 
null)
 
  357                m_imgMean = m_factory.
LoadDatum(imgMean);
 
  377            return m_rgImages.Select(p => 
new DbItem { 
id = p.ImageID, virtualid = p.
VirtualID, index = p.Index, label = p.Label, boost = p.Boost, time = p.TimeStamp, desc = p.Description, originalsrcid = p.OriginalSourceID, active = 
true }).ToList();
 
  387                throw new Exception(
"Relabeling only supported on fully loaded data sets.");
 
  406                throw new Exception(
"Relabeling only supported on fully loaded data sets.");
 
  424                throw new Exception(
"Relabeling only supported on fully loaded data sets.");
 
  443            List<int?> rgIdx = rgItems.Select(p => p.index).ToList();
 
  444            List<SimpleDatum> rgSd;
 
  448                if (m_rgImages == 
null)
 
  451                rgSd = m_rgImages.Where(p => p != 
null && rgIdx.Contains(p.Index)).ToList();
 
  457            rgSd = rgSd.Where(p => p.Description == strDesc).ToList();
 
  461            return rgSd[0].
Index;
 
  471            List<SimpleDatum> rgSd;
 
  475                rgSd = m_rgImages.Where(p => p != 
null && p.ImageID == nImageId).ToList();
 
  484        private IEnumerable<SimpleDatum> getQuery(
bool bSuperboostOnly, 
string strFilterVal = 
null, 
int? nBoostVal = 
null)
 
  486            IEnumerable<SimpleDatum> iQuery = m_rgImages.Where(p => p != 
null);
 
  490                if (nBoostVal.HasValue)
 
  492                    int nVal = nBoostVal.Value;
 
  496                        nVal = Math.Abs(nVal);
 
  497                        iQuery = iQuery.Where(p => p.Boost == nVal);
 
  501                        iQuery = iQuery.Where(p => p.Boost >= nVal);
 
  506                    iQuery = iQuery.Where(p => p.Boost > 0);
 
  510            if (!
string.IsNullOrEmpty(strFilterVal))
 
  511                iQuery = iQuery.Where(p => p.Description == strFilterVal);
 
  530                if (m_refreshManager != 
null)
 
  532                    while (nIdx > 0 && m_rgImages[nIdx] == 
null)
 
  537                    sd = m_rgImages[nIdx];
 
  540                        throw new Exception(
"No images should be null when using LoadLimit loading!");
 
  547                    sd = directLoadImage(nIdx);
 
  549                        throw new Exception(
"The image is still null yet should have loaded!");
 
  552                        m_rgImages[nIdx] = sd;
 
  557            if (bLoadDataCriteria || bLoadDebugData)
 
  558                m_factory.
LoadRawData(sd, bLoadDataCriteria, bLoadDebugData);
 
  573        public int GetCount(
QueryState state, 
string strFilterVal = 
null, 
int? nBoostVal = 
null, 
bool bBoostValIsExact = 
false)
 
  575            List<int> rgIdx = state.
GetIndexes(0, 
int.MaxValue, strFilterVal, nBoostVal, bBoostValIsExact);
 
  576            return rgIdx.Count();
 
  592        public List<SimpleDatum> 
GetImages(
QueryState state, 
int nStartIdx, 
int nQueryCount = 
int.MaxValue, 
string strFilterVal = 
null, 
int? nBoostVal = 
null, 
bool bBoostValIsExact = 
false, 
bool bAttemptDirectLoad = 
false)
 
  594            List<int> rgIdx = state.
GetIndexes(nStartIdx, nQueryCount, strFilterVal, nBoostVal, bBoostValIsExact);
 
  595            List<SimpleDatum> rgSd;
 
  599                rgSd = m_rgImages.Where(p => p != 
null && rgIdx.Contains(p.Index)).ToList();
 
  602            if (bAttemptDirectLoad)
 
  607                        rgIdx.Remove(sd.
Index);
 
  610                for (
int i = 0; i < rgIdx.Count; i++)
 
  612                    rgSd.
Add(directLoadImage(rgIdx[i]));
 
  615                rgSd = rgSd.OrderBy(p => p.Index).ToList();
 
  633        public List<SimpleDatum> 
GetImages(
QueryState state, DateTime dtStart, 
int nQueryCount = 
int.MaxValue, 
string strFilterVal = 
null, 
int? nBoostVal = 
null, 
bool bBoostValIsExact = 
false)
 
  635            List<int> rgIdx = state.
GetIndexes(dtStart, nQueryCount, strFilterVal, nBoostVal, bBoostValIsExact);
 
  639                return m_rgImages.Where(p => p != 
null && rgIdx.Contains(p.Index)).ToList();
 
  653        public List<SimpleDatum> 
GetImages(
bool bSuperboostOnly, 
string strFilterVal, 
int? nBoostVal, 
int[] rgIdx)
 
  657                IEnumerable<SimpleDatum> iQuery = getQuery(bSuperboostOnly, strFilterVal, nBoostVal);
 
  659                iQuery = iQuery.Where(p => p != 
null && rgIdx.Contains(p.Index));
 
  661                return iQuery.ToList();
 
  677                if (nLoadCount == 0 && !m_evtRunning.WaitOne(0))
 
  681            List<WaitHandle> rgWait = 
new List<WaitHandle>();
 
  682            rgWait.Add(m_evtDone);
 
  683            rgWait.AddRange(rgAbort);
 
  685            int nRes = WaitHandle.WaitAny(rgWait.ToArray(), nWait);
 
  694            int nBatchSize = 20000;
 
  697            if (nImageSize > 60000)
 
  699            else if (nImageSize > 20000)
 
  701            else if (nImageSize > 3000)
 
  704            if (nBatchSize > m_nLoadCount)
 
  705                nBatchSize = m_nLoadCount;
 
  723        private void dataLoadThread()
 
  726            DatasetFactory factory = 
new DatasetFactory(m_factory);
 
  727            int? nNextIdx = m_loadSequence.GetNext();
 
  728            Stopwatch sw = 
new Stopwatch();
 
  730            if (m_refreshManager != 
null)
 
  731                m_refreshManager.Reset();
 
  737                List<int> rgIdxBatch = 
new List<int>();
 
  738                int nBatchSize = getBatchSize(m_src);
 
  740                if (m_nLoadedCount > 0)
 
  741                    throw new Exception(
"The loaded count is > 0!");
 
  745                m_log.
WriteLine(m_src.
Name + 
" loading " + m_loadSequence.Count.ToString(
"N0") + 
" items...", 
true);
 
  747                while (nNextIdx.HasValue || rgIdxBatch.Count > 0)
 
  749                    if (nNextIdx.HasValue)
 
  750                        rgIdxBatch.Add(nNextIdx.Value);
 
  752                    if (rgIdxBatch.Count >= nBatchSize || !nNextIdx.HasValue)
 
  754                        List<RawImage> rgImg;
 
  756                        if (m_refreshManager == 
null)
 
  757                            rgImg = factory.GetRawImagesAt(rgIdxBatch[0], rgIdxBatch.Count);
 
  759                            rgImg = factory.GetRawImagesAt(rgIdxBatch, m_evtCancel);
 
  764                        for (
int j = 0; j < rgImg.Count; j++)
 
  768                            if (m_refreshManager != 
null)
 
  769                                m_refreshManager.AddLoaded(sd);
 
  771                            m_rgImages[m_nLoadedCount] = sd;
 
  774                            if (sw.Elapsed.TotalMilliseconds > 1000)
 
  776                                if (m_log != 
null && !m_bSilent)
 
  778                                    double dfPct = m_nLoadedCount / (double)m_rgImages.Length;
 
  780                                    m_log.
WriteLine(
"Loading '" + m_src.
Name + 
"' at " + dfPct.ToString(
"P") + 
" (" + m_nLoadedCount.ToString(
"N0") + 
" of " + m_rgImages.Length.
ToString(
"N0") + 
")...", 
true);
 
  783                                int nWait = WaitHandle.WaitAny(m_rgAbort.ToArray(), 0);
 
  784                                if (nWait != WaitHandle.WaitTimeout)
 
  791                        rgIdxBatch = 
new List<int>();
 
  794                    nNextIdx = m_loadSequence.GetNext();
 
  797                if (rgIdxBatch.Count > 0)
 
  798                    m_log.
FAIL(
"Not all images were loaded!");
 
  804                m_evtRunning.Reset();
 
  809        private void dataRefreshThread()
 
  811            m_evtRefreshRunning.Set();
 
  812            DatasetFactory factory = 
new DatasetFactory(m_factory);
 
  813            Stopwatch sw = 
new Stopwatch();
 
  819                m_log.
WriteLine(
"Starting refresh of " + m_nReplacementBatch.ToString(
"N0") + 
" items...", 
true);
 
  821                List<Tuple<int, SimpleDatum>> rgReplace = 
new List<Tuple<int, SimpleDatum>>();
 
  822                List<Tuple<int, DbItem>> rgItems = 
new List<Tuple<int, DbItem>>();
 
  823                List<DbItem> rgDbItems = 
new List<DbItem>();
 
  826                for (
int i = 0; i < m_nReplacementBatch; i++)
 
  828                    int nIdx = m_random.
Next(m_rgImages.Length);
 
  831                    if (m_rgImages[nIdx] != 
null)
 
  832                        nLabel = m_rgImages[nIdx].
Label;
 
  834                    DbItem img = m_refreshManager.GetNextImageId(nLabel);
 
  835                    rgItems.Add(
new Tuple<int, DbItem>(nIdx, img));
 
  838                    if (sw.Elapsed.TotalMilliseconds > 1000)
 
  840                        if (m_evtRefreshCancel.WaitOne(0))
 
  848                List<SimpleDatum> rgImg = m_factory.
GetImagesAt(rgDbItems, m_evtCancel);
 
  852                rgImg = rgImg.OrderBy(p => p.ImageID).ToList();
 
  853                rgItems = rgItems.OrderBy(p => p.Item2.ID).ToList();
 
  855                if (rgImg.Count != rgItems.Count)
 
  857                    List<Tuple<int, DbItem>> rgItems1 = 
new List<Tuple<int, DbItem>>();
 
  859                    for (
int i = 0; i < rgImg.Count; i++)
 
  861                        while (nIdx < rgItems.Count && rgItems[nIdx].Item2.ID < rgImg[i].ImageID)
 
  866                        if (rgItems[nIdx].Item2.ID == rgImg[i].ImageID)
 
  868                            rgItems1.Add(rgItems[nIdx]);
 
  876                for (
int i = 0; i < rgItems.Count; i++)
 
  878                    rgReplace.Add(
new Tuple<int, SimpleDatum>(rgItems[i].Item1, rgImg[i]));
 
  883                    int nMismatchCount = 0;
 
  885                    for (
int i = 0; i < rgReplace.Count; i++)
 
  887                        int nIdx = rgReplace[i].Item1;
 
  888                        if (m_rgImages[nIdx] != 
null && m_rgImages[nIdx].Label != rgReplace[i].Item2.Label)
 
  891                            m_rgImages[nIdx] = rgReplace[i].Item2;
 
  894                    if (nMismatchCount > 0)
 
  895                        m_log.
WriteLine(
"WARNING: " + nMismatchCount.ToString(
"N0") + 
" label mismatches found!", 
true);
 
  900                m_evtRefreshRunning.Reset();
 
  901                m_evtRefreshDone.Set();
 
  906#pragma warning disable 1591 
  908    public class LoadSequence 
 
  910        List<int> m_rgLoadSequence = 
new List<int>();
 
  911        Dictionary<int, Tuple<bool, bool>> m_rgLoadConditions = 
new Dictionary<int, Tuple<bool, bool>>();
 
  912        Dictionary<int, AutoResetEvent> m_rgPending = 
new Dictionary<int, AutoResetEvent>();
 
  913        object m_syncObj = 
new object();
 
  915        public LoadSequence(
CryptoRandom random, 
int nCount, 
int nImageCount, RefreshManager refresh)
 
  919            if (nCount < nImageCount)
 
  921                Dictionary<int, List<DbItem>> rgItemsByLabel = refresh.GetItemsByLabel();
 
  922                List<int> rgLabel = rgItemsByLabel.Where(p => p.Value.Count > 0).Select(p => p.Key).ToList();
 
  924                for (
int i = 0; i < nCount; i++)
 
  926                    int nLabelIdx = random.
Next(rgLabel.Count);
 
  927                    int nLabel = rgLabel[nLabelIdx];
 
  928                    List<DbItem> rgItems = rgItemsByLabel[nLabel];
 
  929                    int nItemIdx = random.
Next(rgItems.Count);
 
  930                    DbItem item = rgItems[nItemIdx];
 
  932                    m_rgLoadSequence.Add(item.Index);
 
  934                    rgLabel.Remove(nLabel);
 
  935                    if (rgLabel.Count == 0)
 
  936                        rgLabel = rgItemsByLabel.Where(p => p.Value.Count > 0).Select(p => p.Key).ToList();
 
  944                for (
int i = 0; i < nCount; i++)
 
  946                    m_rgLoadSequence.Add(i);
 
  953            get { 
return m_rgLoadSequence.Count; }
 
  962                    return (m_rgLoadSequence.Count == 0) ? true : 
false;
 
  967        public void PreEmpt(
int nIdx, 
bool bLoadDataCriteria, 
bool bLoadDebugData)
 
  971                m_rgLoadConditions.Add(nIdx, 
new Tuple<bool, bool>(bLoadDataCriteria, bLoadDebugData));
 
  972                m_rgPending.Add(nIdx, 
new AutoResetEvent(
false));
 
  973                m_rgLoadSequence.Remove(nIdx);
 
  974                m_rgLoadSequence.Insert(0, nIdx);
 
  978        public void SetLoaded(
int nIdx)
 
  982                m_rgLoadConditions.Remove(nIdx);
 
  984                if (!m_rgPending.ContainsKey(nIdx))
 
  987                m_rgPending[nIdx].Set();
 
  991        public bool WaitForLoad(
int nIdx, 
int nWaitMs = 5000)
 
  993            if (!m_rgPending.ContainsKey(nIdx))
 
  996            bool bRes = m_rgPending[nIdx].WaitOne(nWaitMs);
 
 1000                m_rgPending.Remove(nIdx);
 
 1006        public int? GetNext()
 
 1010                if (m_rgLoadSequence.Count == 0)
 
 1013                int nIdx = m_rgLoadSequence[0];
 
 1014                m_rgLoadSequence.RemoveAt(0);
 
 1021    public class RefreshManager 
 
 1024        List<DbItem> m_rgItems;
 
 1025        Dictionary<int, List<DbItem>> m_rgItemsByLabel = 
null;
 
 1026        Dictionary<int, List<int>> m_rgLoadedIdx = 
new Dictionary<int, List<int>>();
 
 1027        Dictionary<int, List<int>> m_rgNotLoadedIdx = 
new Dictionary<int, List<int>>();
 
 1032            m_rgItems = factory.LoadImageIndexes(
false, 
true);
 
 1035        public Dictionary<int, List<DbItem>> GetItemsByLabel()
 
 1037            if (m_rgItemsByLabel == 
null)
 
 1039                m_rgItemsByLabel = 
new Dictionary<int, List<DbItem>>();
 
 1041                for (
int i=0; i<m_rgItems.Count; i++)
 
 1043                    DbItem item = m_rgItems[i];
 
 1046                    if (!m_rgItemsByLabel.ContainsKey(item.Label))
 
 1047                        m_rgItemsByLabel.Add(item.Label, 
new List<DbItem>());
 
 1049                    m_rgItemsByLabel[item.Label].Add(item);
 
 1055            return m_rgItemsByLabel;
 
 1060            m_rgLoadedIdx = 
new Dictionary<int, List<int>>();
 
 1061            m_rgNotLoadedIdx = 
new Dictionary<int, List<int>>();
 
 1063            foreach (KeyValuePair<
int, List<DbItem>> kv 
in m_rgItemsByLabel)
 
 1065                m_rgNotLoadedIdx.Add(kv.Key, kv.Value.Select(p => (
int)p.Tag).ToList());
 
 1071            if (!m_rgLoadedIdx.ContainsKey(sd.
Label))
 
 1072                m_rgLoadedIdx.Add(sd.
Label, 
new List<int>());
 
 1074            DbItem item = m_rgItemsByLabel[sd.
Label].Where(p => p.ID == sd.
ImageID).First();
 
 1075            m_rgLoadedIdx[sd.
Label].Add((
int)item.Tag);
 
 1077            m_rgNotLoadedIdx[sd.
Label].Remove((
int)item.Tag);
 
 1080        public DbItem GetNextImageId(
int? nLabel)
 
 1082            if (!nLabel.HasValue)
 
 1084                int nLabelIdx = m_random.
Next(m_rgItemsByLabel.Count);
 
 1085                nLabel = m_rgItemsByLabel.ElementAt(nLabelIdx).Key;
 
 1088            if (!m_rgLoadedIdx.ContainsKey(nLabel.Value))
 
 1089                m_rgLoadedIdx.Add(nLabel.Value, 
new List<int>());
 
 1091            List<int> rgLoadedIdx = m_rgLoadedIdx[nLabel.Value];
 
 1092            List<int> rgNotLoadedIdx = m_rgNotLoadedIdx[nLabel.Value];
 
 1094            if (rgNotLoadedIdx.Count == 0)
 
 1096                rgLoadedIdx.Clear();
 
 1097                rgNotLoadedIdx = m_rgItemsByLabel[nLabel.Value].Select(p => (
int)p.Tag).ToList();
 
 1100            int nIdx = m_random.
Next(rgNotLoadedIdx.Count);
 
 1101            int nMainIdx = rgNotLoadedIdx[nIdx];
 
 1102            DbItem item = m_rgItems[nMainIdx];
 
 1104            rgNotLoadedIdx.RemoveAt(nIdx);
 
 1105            rgLoadedIdx.Add(nMainIdx);
 
 1111#pragma warning restore 1591 
The CalculateImageMeanArgs is passed as an argument to the MyCaffeImageDatabase::OnCalculateImageMean...
 
SimpleDatum ImageMean
Get/set the image mean calculated from the Images.
 
bool Cancelled
Get/set a flag indicating to cancel the operation.
 
The CryptoRandom is a random number generator that can use either the standard .Net Random objec or t...
 
int Next(int nMinVal, int nMaxVal, bool bMaxInclusive=true)
Returns a random int within the range
 
The LabelMappingCollection manages a collection of LabelMapping's.
 
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 FAIL(string str)
Causes a failure which throws an exception with the desciptive text.
 
double Progress
Get/set the progress associated with the Log.
 
The SimpleDatum class holds a data input within host memory.
 
int OriginalLabel
Get/set the original known label of the data.
 
static SimpleDatum CalculateMean(Log log, SimpleDatum[] rgImg, WaitHandle[] rgAbort)
Calculate the mean of an array of SimpleDatum and return the mean as a new SimpleDatum.
 
void ResetBoost()
Reset the boost to the original boost.
 
void SetLabel(int nLabel)
Sets the label.
 
SimpleDatum Add(SimpleDatum d)
Creates a new SimpleDatum and adds another SimpleDatum to it.
 
override string ToString()
Return a string representation of the SimpleDatum.
 
int Index
Returns the index of the SimpleDatum.
 
void ResetLabel()
Resets the label to the original label used when creating the SimpleDatum.
 
int ImageID
Returns the ID of the image in the database.
 
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 SourceDescriptor class contains all information describing a data source.
 
int Height
Returns the height of each data item in the data source.
 
int Width
Returns the width of each data item in the data source.
 
int ImageCount
Returns the number of images within this data source.
 
int Channels
Returns the item colors - 1 channel = black/white, 3 channels = RGB color.
 
The DatasetFactory manages the connection to the Database object.
 
bool SaveImageMean(SimpleDatum sd, bool bUpdate, int nSrcId=0)
Save the SimpleDatum as a RawImageMean in the database.
 
RawImageMean GetRawImageMean()
Return the RawImageMean for the open data source.
 
List< SimpleDatum > GetImagesAt(List< int > rgImageIdx, ManualResetEvent evtCancel, int nSrcId=0, string strDescription=null)
Returns a list of SimpleDatum from the database for a data source.
 
SimpleDatum LoadImageAt(int nIdx, bool? bLoadDataCriteria=null, bool? bLoadDebugData=null, int nSrcId=0, int nPadW=0, int nPadH=0)
Load an image at a given index.
 
SimpleDatum LoadImageMean(int nSrcId, ConnectInfo ci=null)
Returns the image mean for a give data source.
 
void LoadRawData(SimpleDatum sd, bool bLoadDataCriteria, bool bLoadDebugData)
Load the data criteria and/or debug data.
 
int PutRawImageMean(SimpleDatum sd, bool bUpdate, ConnectInfo ci=null)
Save the SimpleDatum as a RawImageMean in the database for the open data source.
 
SimpleDatum LoadDatum(int nImageId, int nChannels, bool bDataIsReal, int nLabel, int nSrcId=0)
Loads a new SimpleDataum from a RawImage ID.
 
Specifies a database item used when querying boosted items.
 
int VirtualID
Specifies the image VirtualID (if any).
 
The MasterIndexes stores the indexes that define the index structure of the data source data.
 
List< DbItem > RawIndexes
Returns the raw indexes.
 
List< int > GetIndexes(int nStartIdx, int nQueryCount=int.MaxValue, string strFilterVal=null, int? nBoostVal=null, bool bBoostValIsExact=false)
Returns the indexes fitting the criteria.
 
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.
 
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.
 
void StopRefresh()
Stop the refresh thread if running.
 
List< DbItem > ReloadIndexing()
Reload the image indexing.
 
bool? IsFull
Returns true when the master list is fully loaded, false otherwise.
 
MasterList(CryptoRandom random, Log log, SourceDescriptor src, DatasetFactory factory, List< WaitHandle > rgAbort, int nMaxLoadCount=0)
The constructor.
 
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.
 
bool IsLoadLimitEnabled
Returns true when the database is loaded with LoadLimit > 0, false otherwise.
 
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.
 
bool IsRefreshDone
Returns true after the refresh completes.
 
void SetImageMean(SimpleDatum d, bool bSave=false)
Set the image mean.
 
int GetLoadedCount()
Return the currently loaded images in the data source.
 
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.
 
Initially the QueryState is copied from the MasterIndexes and during each query is altered by removin...
 
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_LOAD_METHOD
Defines how to laod the items into the in-memory database.
 
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-...