MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
DatasetEx2.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading;
6using MyCaffe.basecode;
7using System.Diagnostics;
9
10namespace MyCaffe.db.image
11{
17 public class DatasetEx2 : IDisposable
18 {
19 CryptoRandom m_random = null;
20 object m_syncObj = new object();
21 DatasetFactory m_factory = null;
22 DatasetDescriptor m_ds = null;
23 ImageSet2 m_TestingImages = null;
24 ImageSet2 m_TrainingImages = null;
25 bool m_bUseTrainingImagesForTesting = false;
26 List<Guid> m_rgUsers = new List<Guid>();
27 int m_nOriginalDsId = 0;
28 QueryStateCollection m_queryStates = new QueryStateCollection();
29 long m_lDefaultQueryState = 0;
30 ManualResetEvent m_evtRefreshScheduleCancel = new ManualResetEvent(false);
31 ManualResetEvent m_evtRefreshScheduleRunning = new ManualResetEvent(false);
32 ManualResetEvent m_evtRefreshScheduleDone = new ManualResetEvent(false);
33 Thread m_refreshScheduleThread = null;
34 int m_nRefreshUpdatePeriod = 0;
35 double m_dfRegreshReplacementPct = 0;
36 int m_nTrainingRefreshCount = 0;
37 int m_nTestingRefreshCount = 0;
38 bool m_bRefreshTraining = false;
39 bool m_bRefreshTesting = false;
40 Log m_log = null;
41
42
46 public event EventHandler<CalculateImageMeanArgs> OnCalculateImageMean;
47
54 public DatasetEx2(Guid user, DatasetFactory factory, CryptoRandom random)
55 {
56 m_random = random;
57
58 if (user != Guid.Empty)
59 m_rgUsers.Add(user);
60
61 m_factory = new DatasetFactory(factory);
62 }
63
64
70 public int AddUser(Guid user)
71 {
72 m_rgUsers.Add(user);
73 return m_rgUsers.Count;
74 }
75
81 public int RemoveUser(Guid user)
82 {
83 m_rgUsers.Remove(user);
84 return m_rgUsers.Count;
85 }
86
102 public 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)
103 {
104 lock (m_syncObj)
105 {
106 m_log = log;
107
108 if (ds != null)
109 m_ds = ds;
110
111 if (m_ds.TrainingSource.Width == -1 || m_ds.TrainingSource.Height == -1)
112 {
113 log.WriteLine("WARNING: Cannot create a mean image for data sources that contain variable sized images. The mean check will be skipped.", true);
114 bSkipMeanCheck = true;
115 }
116
117 bool bSilentLoad = (loadMethod == DB_LOAD_METHOD.LOAD_ON_DEMAND_BACKGROUND) ? true : false;
118
119 m_TrainingImages = new ImageSet2(ImageSet2.TYPE.TRAIN, log, m_factory, m_ds.TrainingSource, loadMethod, m_random, rgAbort);
120 m_TrainingImages.OnCalculateImageMean += OnCalculateImageMean;
121 QueryState qsTraining = m_TrainingImages.Initialize(bSilentLoad, true, true, nImageDbLoadLimit, bVerify);
122 SimpleDatum sdMean = null;
123
124 if (!bSkipMeanCheck)
125 {
126 bool bQueryOnly = false;
128 bQueryOnly = true;
129
130 sdMean = m_TrainingImages.GetImageMean(log, rgAbort, bQueryOnly);
131 }
132
133 if (EventWaitHandle.WaitAny(rgAbort, 0) != EventWaitHandle.WaitTimeout)
134 return 0;
135
136 m_TestingImages = new ImageSet2(ImageSet2.TYPE.TEST, log, m_factory, m_ds.TestingSource, loadMethod, m_random, rgAbort);
138 QueryState qsTesting = m_TestingImages.Initialize(bSilentLoad, true, true, nImageDbLoadLimit, bVerify);
139
140 if (!bSkipMeanCheck)
141 {
142 bool bSave = true;
144 bSave = false;
145
146 m_TestingImages.SetImageMean(sdMean, bSave);
147 }
148
149 if (EventWaitHandle.WaitAny(rgAbort, 0) != EventWaitHandle.WaitTimeout)
150 return 0;
151
152 if (loadMethod == DB_LOAD_METHOD.LOAD_ALL && nImageDbLoadLimit > 0 && nImageDbAutoRefreshScheduledUpdateInMs > 0 && dfImageDbAutoRefreshScheduledReplacementPct > 0)
153 StartAutomaticRefreshSchedule(true, true, nImageDbAutoRefreshScheduledUpdateInMs, dfImageDbAutoRefreshScheduledReplacementPct);
154
155 m_lDefaultQueryState = m_queryStates.CreateNewState(qsTraining, qsTesting);
156 return m_lDefaultQueryState;
157 }
158 }
159
167 public bool WaitForLoadingToComplete(bool bTraining, bool bTesting, int nWait = int.MaxValue)
168 {
169 if (bTraining)
170 {
171 if (!m_TrainingImages.WaitForLoadingToComplete(nWait))
172 return false;
173 }
174
175 if (bTesting)
176 {
177 if (!m_TestingImages.WaitForLoadingToComplete(nWait))
178 return false;
179 }
180
181 return true;
182 }
183
191 public bool WaitForRefreshToComplete(bool bTraining, bool bTesting, int nWait = int.MaxValue)
192 {
193 if (bTraining)
194 {
195 if (!m_TrainingImages.WaitForRefreshToComplete(nWait))
196 return false;
197 }
198
199 if (bTesting)
200 {
201 if (!m_TestingImages.WaitForRefreshToComplete(nWait))
202 return false;
203 }
204
205 return true;
206 }
207
214 public bool IsRefreshRunning(bool bTraining, bool bTesting)
215 {
216 bool bRunning = false;
217
218 if (bTraining)
219 {
220 if (m_TrainingImages.IsRefreshRunning)
221 bRunning = true;
222 }
223
224 if (bTesting)
225 {
226 if (m_TestingImages.IsRefreshRunning)
227 bRunning = true;
228 }
229
230 return bRunning;
231 }
232
242 public void StartRefresh(bool bTraining = true, bool bTesting = true, double dfReplacementPct = 0.25)
243 {
244 if (bTraining)
245 m_TrainingImages.StartRefresh(dfReplacementPct);
246
247 if (bTesting)
248 m_TestingImages.StartRefresh(dfReplacementPct);
249 }
250
256 public void StopRefresh(bool bTraining = true, bool bTesting = true)
257 {
258 if (bTraining)
259 m_TrainingImages.StopRefresh();
260
261 if (bTesting)
262 m_TestingImages.StopRefresh();
263 }
264
273 public bool StartAutomaticRefreshSchedule(bool bTraining, bool bTesting, int nPeriodInMs, double dfReplacementPct)
274 {
275 if (m_refreshScheduleThread != null)
276 return false;
277
278 if (nPeriodInMs == 0 || dfReplacementPct == 0)
279 return false;
280
281 if (bTraining && m_TrainingImages.LoadMethod != DB_LOAD_METHOD.LOAD_ALL)
282 {
283 m_log.WriteLine("WARNING: The shared training data source '" + m_TrainingImages.Source.Name + "' appears to already be open with the '" + m_TrainingImages.LoadMethod.ToString() + "', so the load limit with automatic refresh will not be used.");
284 return false;
285 }
286
287 if (bTesting && m_TestingImages.LoadMethod != DB_LOAD_METHOD.LOAD_ALL)
288 {
289 m_log.WriteLine("WARNING: The shared testing data source '" + m_TestingImages.Source.Name + "' appears to already be open with the '" + m_TestingImages.LoadMethod.ToString() + "', so the load limit with automatic refresh will not be used.");
290 return false;
291 }
292
293 m_nRefreshUpdatePeriod = nPeriodInMs;
294 m_dfRegreshReplacementPct = dfReplacementPct;
295 m_bRefreshTraining = bTraining;
296 m_bRefreshTesting = bTesting;
297 m_refreshScheduleThread = new Thread(new ParameterizedThreadStart(refreshSchedule));
298 m_evtRefreshScheduleCancel.Reset();
299 m_evtRefreshScheduleDone.Reset();
300 m_evtRefreshScheduleRunning.Reset();
301 m_refreshScheduleThread.Start(new Tuple<int, double, bool, bool>(nPeriodInMs, dfReplacementPct, bTraining, bTesting));
302 return m_evtRefreshScheduleRunning.WaitOne(1000);
303 }
304
311 public bool StopAutomaticRefreshSchedule(bool bTraining, bool bTesting)
312 {
313 if (m_refreshScheduleThread == null)
314 return false;
315
316 if (m_evtRefreshScheduleRunning.WaitOne(0))
317 {
318 m_evtRefreshScheduleCancel.Set();
319 m_evtRefreshScheduleDone.WaitOne();
320 }
321
322 m_refreshScheduleThread = null;
323
324 return true;
325 }
326
335 public bool GetAutomaticRefreshSchedule(out int nPeriodInMs, out double dfReplacementPct, out int nTrainingRefreshCount, out int nTestingRefreshCount)
336 {
337 nPeriodInMs = 0;
338 dfReplacementPct = 0;
339 nTrainingRefreshCount = m_nTrainingRefreshCount;
340 nTestingRefreshCount = m_nTestingRefreshCount;
341
342 if (m_refreshScheduleThread == null)
343 return false;
344
345 if (!m_evtRefreshScheduleRunning.WaitOne(0))
346 return false;
347
348 nPeriodInMs = m_nRefreshUpdatePeriod;
349 dfReplacementPct = m_dfRegreshReplacementPct;
350
351 return true;
352 }
353
354 private void refreshSchedule(object obj)
355 {
356 m_evtRefreshScheduleRunning.Set();
357 m_nTrainingRefreshCount = 0;
358 m_nTestingRefreshCount = 0;
359
360 try
361 {
362 Tuple<int, double, bool, bool> arg = obj as Tuple<int, double, bool, bool>;
363 int nPeriodMs = arg.Item1;
364 double dfReplacementPct = arg.Item2;
365 bool bTraining = arg.Item3;
366 bool bTesting = arg.Item4;
367 Stopwatch sw = new Stopwatch();
368
369 sw.Start();
370
371 m_log.WriteLine("INFO: Starting refresh cycle on '" + m_ds.Name + "' and running every " + m_nRefreshUpdatePeriod.ToString("N0") + " ms. with replacement percent = " + m_dfRegreshReplacementPct.ToString("P"));
372
373 while (!m_evtRefreshScheduleCancel.WaitOne(1000))
374 {
375 if (sw.ElapsedMilliseconds > m_nRefreshUpdatePeriod)
376 {
377 if (m_bRefreshTraining)
378 {
379 if (!m_TrainingImages.IsRefreshRunning)
380 {
381 m_log.WriteLine("INFO: Refreshing '" + m_TrainingImages.Source.Name + "'...");
382 m_TrainingImages.StartRefresh(m_dfRegreshReplacementPct);
383 m_nTrainingRefreshCount++;
384 }
385 else
386 {
387 m_log.WriteLine("'" + m_TrainingImages.Source.Name + "' refresh already running.");
388 }
389 }
390
391 if (m_bRefreshTesting)
392 {
393 if (!m_TestingImages.IsRefreshRunning)
394 {
395 m_log.WriteLine("INFO: Refreshing '" + m_TestingImages.Source.Name + "'...");
396 m_TestingImages.StartRefresh(m_dfRegreshReplacementPct);
397 m_nTestingRefreshCount++;
398 }
399 else
400 {
401 m_log.WriteLine("'" + m_TestingImages.Source.Name + "' refresh already running.");
402 }
403 }
404
405 sw.Restart();
406 }
407 }
408
409 if (m_TrainingImages.IsRefreshRunning)
410 {
411 m_TrainingImages.StopRefresh();
412 m_log.WriteLine("Stopped '" + m_TrainingImages.Source.Name + "' refresh.");
413 }
414
415 if (m_TestingImages.IsRefreshRunning)
416 {
417 m_TestingImages.StopRefresh();
418 m_log.WriteLine("Stopped '" + m_TestingImages.Source.Name + "' refresh.");
419 }
420 }
421 finally
422 {
423 m_evtRefreshScheduleDone.Set();
424 m_evtRefreshScheduleRunning.Reset();
425 }
426 }
427
428
433 {
434 get { return m_lDefaultQueryState; }
435 }
436
441 protected virtual void Dispose(bool bDisposing)
442 {
443 m_ds = null;
444
446
447 if (m_TestingImages != null)
448 {
449 m_TestingImages.Dispose();
450 m_TestingImages = null;
451 }
452
453 if (m_TrainingImages != null)
454 {
455 m_TrainingImages.Dispose();
456 m_TrainingImages = null;
457 }
458
459 if (m_factory != null)
460 {
461 m_factory.Dispose();
462 m_factory = null;
463 }
464 }
465
469 public void Dispose()
470 {
471 Dispose(true);
472 }
473
481 public long CreateQueryState(bool bUseUniqueLabelIndexes = true, bool bUseUniqueImageIndexes = true, IMGDB_SORT sort = IMGDB_SORT.NONE)
482 {
483 QueryState qsTraining = m_TrainingImages.CreateQueryState(bUseUniqueLabelIndexes, bUseUniqueImageIndexes, sort);
484 QueryState qsTesting = m_TestingImages.CreateQueryState(bUseUniqueLabelIndexes, bUseUniqueImageIndexes, sort);
485 return m_queryStates.CreateNewState(qsTraining, qsTesting);
486 }
487
493 public bool SetDefaultQueryState(long lQueryState)
494 {
495 m_lDefaultQueryState = lQueryState;
496 return true;
497 }
498
504 public bool FreeQueryState(long lHandle)
505 {
506 // Cannot free the default query state.
507 if (lHandle == m_lDefaultQueryState)
508 return false;
509
510 return m_queryStates.FreeQueryState(lHandle);
511 }
512
519 public QueryState FindQueryState(long lQueryState, ImageSet2.TYPE type)
520 {
521 if (lQueryState == 0)
522 lQueryState = m_lDefaultQueryState;
523
524 if (type == ImageSet2.TYPE.TEST)
525 return m_queryStates.GetTestingState(lQueryState);
526 else
527 return m_queryStates.GetTrainingState(lQueryState);
528 }
529
533 public void ReloadIndexing()
534 {
535 List<DbItem> rgItems = m_TrainingImages.ReloadIndexing();
536 m_queryStates.ReIndexTraining(rgItems);
537
538 rgItems = m_TrainingImages.ReloadIndexing();
539 m_queryStates.ReIndexTesting(rgItems);
540 }
541
547 {
548 List<DbItem> rgItems = m_TrainingImages.Relabel(col);
549 m_queryStates.ReIndexTraining(rgItems);
550
551 rgItems = m_TrainingImages.Relabel(col);
552 m_queryStates.ReIndexTesting(rgItems);
553 }
554
558 public void ResetLabels()
559 {
560 List<DbItem> rgItems = m_TrainingImages.ResetLabels();
561 m_queryStates.ReIndexTraining(rgItems);
562
563 rgItems = m_TrainingImages.ResetLabels();
564 m_queryStates.ReIndexTesting(rgItems);
565 }
566
570 public void ResetAllBoosts()
571 {
572 List<DbItem> rgItems = m_TrainingImages.ResetAllBoosts();
573 m_queryStates.ReIndexTraining(rgItems);
574
575 rgItems = m_TrainingImages.ResetAllBoosts();
576 m_queryStates.ReIndexTesting(rgItems);
577 }
578
583 {
584 get { return m_bUseTrainingImagesForTesting; }
585 set { m_bUseTrainingImagesForTesting = value; }
586 }
587
595 public bool SaveImageMean(int nSrcId, SimpleDatum sd, bool bUpdate)
596 {
597 if (m_TestingImages.Source.ID != nSrcId &&
598 m_TrainingImages.Source.ID != nSrcId)
599 return false;
600
601 return m_factory.SaveImageMean(sd, bUpdate, nSrcId);
602 }
603
609 public SimpleDatum QueryImageMean(int nSrcId)
610 {
611 if (m_TestingImages.Source.ID != nSrcId &&
612 m_TrainingImages.Source.ID != nSrcId)
613 return null;
614
615 return m_factory.QueryImageMean(nSrcId);
616 }
617
621 public void Unload(bool bReload)
622 {
623 lock (m_syncObj)
624 {
625 m_TestingImages.Unload(bReload);
626 m_TrainingImages.Unload(bReload);
627 }
628 }
629
636 public double GetPercentageLoaded(out double dfTraining, out double dfTesting)
637 {
638 int nTrainingTotal = m_TrainingImages.GetTotalCount();
639 int nTrainingLoaded = m_TrainingImages.GetLoadedCount();
640 int nTestingTotal = m_TestingImages.GetTotalCount();
641 int nTestingLoaded = m_TestingImages.GetLoadedCount();
642
643 dfTraining = (double)nTrainingLoaded / (double)nTrainingTotal;
644 dfTesting = (double)nTestingLoaded / (double)nTestingTotal;
645
646 int nTotalLoaded = nTrainingLoaded + nTestingLoaded;
647 int nTotalImages = nTrainingTotal + nTestingTotal;
648
649 return (double)nTotalLoaded / (double)nTotalImages;
650 }
651
657 public ImageSet2 Find(int nSourceID)
658 {
659 if (m_TestingImages.Source.ID == nSourceID)
660 {
661 if (m_bUseTrainingImagesForTesting)
662 return m_TrainingImages;
663
664 return m_TestingImages;
665 }
666
667 if (m_TrainingImages.Source.ID == nSourceID)
668 {
669 return m_TrainingImages;
670 }
671
672 return null;
673 }
674
680 public ImageSet2 Find(string strSource)
681 {
682 if (m_TestingImages.Source.Name == strSource)
683 {
684 if (m_bUseTrainingImagesForTesting)
685 return m_TrainingImages;
686
687 return m_TestingImages;
688 }
689
690 if (m_TrainingImages.Source.Name == strSource)
691 {
692 return m_TrainingImages;
693 }
694
695 return null;
696 }
697
702 {
703 get { return m_ds; }
704 }
705
709 public int DatasetID
710 {
711 get { return (m_ds == null) ? 0 : m_ds.ID; }
712 set { m_ds.ID = value; }
713 }
714
719 {
720 get { return m_nOriginalDsId; }
721 }
722
726 public string DatasetName
727 {
728 get { return m_ds.Name; }
729 }
730 }
731}
The ConnectInfo class specifies the server, database and username/password used to connect to a datab...
Definition: ConnectInfo.cs:14
TYPE
Defines the generic connection location
Definition: ConnectInfo.cs:25
TYPE Location
Get/set the generic location type.
Definition: ConnectInfo.cs:118
The CryptoRandom is a random number generator that can use either the standard .Net Random objec or t...
Definition: CryptoRandom.cs:14
The LabelMappingCollection manages a collection of LabelMapping's.
Definition: LabelMapping.cs:15
The Log class provides general output in text form.
Definition: Log.cs:13
void WriteLine(string str, bool bOverrideEnabled=false, bool bHeader=false, bool bError=false, bool bDisable=false)
Write a line of output.
Definition: Log.cs:80
The SimpleDatum class holds a data input within host memory.
Definition: SimpleDatum.cs:161
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.
SourceDescriptor TestingSource
Get/set the testing 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.
[V2 Image Database] The DatasetEx2 class provides the in-memory dataset functionality that is used by...
Definition: DatasetEx2.cs:18
long CreateQueryState(bool bUseUniqueLabelIndexes=true, bool bUseUniqueImageIndexes=true, IMGDB_SORT sort=IMGDB_SORT.NONE)
Create a new QueryState on the dataset.
Definition: DatasetEx2.cs:481
int? DatasetID
Returns the dataset ID of the dataset managesd by the DatasetEx object.
Definition: DatasetEx2.cs:710
bool StartAutomaticRefreshSchedule(bool bTraining, bool bTesting, int nPeriodInMs, double dfReplacementPct)
Start the automatic refresh schedule on the training and/or testing data sources.
Definition: DatasetEx2.cs:273
void Unload(bool bReload)
Unload the images of the training and testing image sets.
Definition: DatasetEx2.cs:621
bool SetDefaultQueryState(long lQueryState)
Set the default query state to a new query state.
Definition: DatasetEx2.cs:493
bool StopAutomaticRefreshSchedule(bool bTraining, bool bTesting)
Stop the automatic refresh schedule on the training and/or testing data sources.
Definition: DatasetEx2.cs:311
void ResetLabels()
Resets the labels to their original labels.
Definition: DatasetEx2.cs:558
bool UseTrainingImagesForTesting
Get/set whether or not to use the training images when testing.
Definition: DatasetEx2.cs:583
QueryState FindQueryState(long lQueryState, ImageSet2.TYPE type)
Returns the query state for a given query state handle and type.
Definition: DatasetEx2.cs:519
ImageSet2 Find(string strSource)
Returns the ImageSet corresponding to a data source name.
Definition: DatasetEx2.cs:680
DatasetEx2(Guid user, DatasetFactory factory, CryptoRandom random)
The DatasetEx constructor.
Definition: DatasetEx2.cs:54
bool FreeQueryState(long lHandle)
Free an existing query state.
Definition: DatasetEx2.cs:504
void Relabel(LabelMappingCollection col)
Relabels both the testing and training image sets using the label mapping collection.
Definition: DatasetEx2.cs:546
void StopRefresh(bool bTraining=true, bool bTesting=true)
Stop any refresh operation currently running.
Definition: DatasetEx2.cs:256
ImageSet2 Find(int nSourceID)
Returns the ImageSet corresponding to a data source ID.
Definition: DatasetEx2.cs:657
bool SaveImageMean(int nSrcId, SimpleDatum sd, bool bUpdate)
Saves the image mean in a SimpleDatum to the database.
Definition: DatasetEx2.cs:595
bool GetAutomaticRefreshSchedule(out int nPeriodInMs, out double dfReplacementPct, out int nTrainingRefreshCount, out int nTestingRefreshCount)
Get the automatic refresh schedule status and its period and replacement percentage.
Definition: DatasetEx2.cs:335
virtual void Dispose(bool bDisposing)
Releases all resources used.
Definition: DatasetEx2.cs:441
void ReloadIndexing()
Reload the indexing for both the training and testing data sources.
Definition: DatasetEx2.cs:533
int AddUser(Guid user)
Adds a user of the dataset.
Definition: DatasetEx2.cs:70
int OriginalDatasetID
Returns the original DatsetID if this is a cloned re-organized dataset, otherwise 0 is returned.
Definition: DatasetEx2.cs:719
bool WaitForLoadingToComplete(bool bTraining, bool bTesting, int nWait=int.MaxValue)
Wait for either the training, testing or both data sources to complete loading.
Definition: DatasetEx2.cs:167
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.
Definition: DatasetEx2.cs:102
long DefaultQueryState
Returns the default query state created when first initializing the dataset.
Definition: DatasetEx2.cs:433
void Dispose()
Releases all resources used.
Definition: DatasetEx2.cs:469
bool WaitForRefreshToComplete(bool bTraining, bool bTesting, int nWait=int.MaxValue)
Wait for either the training, testing or both data sources to complete refreshing.
Definition: DatasetEx2.cs:191
int RemoveUser(Guid user)
Remove a user of the dataset.
Definition: DatasetEx2.cs:81
DatasetDescriptor Descriptor
Returns the dataset descriptor of the dataset managesd by the DatasetEx object.
Definition: DatasetEx2.cs:702
void ResetAllBoosts()
Reset all boosts for both the testing and training image sets.
Definition: DatasetEx2.cs:570
bool IsRefreshRunning(bool bTraining, bool bTesting)
Returns whether or not the refresh is running on the training and/or testing data source.
Definition: DatasetEx2.cs:214
EventHandler< CalculateImageMeanArgs > OnCalculateImageMean
The OnCalculateImageMean event is passed to each image set and fires each time the Image set need to ...
Definition: DatasetEx2.cs:46
double GetPercentageLoaded(out double dfTraining, out double dfTesting)
Returns the total percentage of images loaded for testing, training and combined.
Definition: DatasetEx2.cs:636
SimpleDatum QueryImageMean(int nSrcId)
Query the image mean for a data source.
Definition: DatasetEx2.cs:609
void StartRefresh(bool bTraining=true, bool bTesting=true, double dfReplacementPct=0.25)
Start an image refresh on the training and/or testing data sources.
Definition: DatasetEx2.cs:242
string DatasetName
Returns the dataset name of the dataset managesd by the DatasetEx object.
Definition: DatasetEx2.cs:727
The DatasetFactory manages the connection to the Database object.
SimpleDatum QueryImageMean(int nSrcId=0)
Return the SimpleDatum for the image mean from the open data source.
bool SaveImageMean(SimpleDatum sd, bool bUpdate, int nSrcId=0)
Save the SimpleDatum as a RawImageMean in the database.
void Dispose()
Releases all resources used.
The EntitiesConnection class defines how to connect to the database via Entity Frameworks.
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,...
Definition: ImageSet2.cs:17
int GetLoadedCount()
Get the total number of images already loaded in the image set.
Definition: ImageSet2.cs:236
QueryState CreateQueryState(bool bUseUniqueLabelIndexes=true, bool bUseUniqueImageIndexes=true, IMGDB_SORT sort=IMGDB_SORT.NONE)
Create a new QueryState and optionally sort the results.
Definition: ImageSet2.cs:218
override void Dispose(bool bDisposing)
Releases the resouces used.
Definition: ImageSet2.cs:74
bool WaitForRefreshToComplete(int nWait=int.MaxValue)
Wait for the image refresh to complete loading.
Definition: ImageSet2.cs:172
DB_LOAD_METHOD LoadMethod
Get the image load method used on initialization.
Definition: ImageSet2.cs:145
List< DbItem > ResetLabels()
Reset all labels of the image set to the original labels.
Definition: ImageSet2.cs:268
bool StartRefresh(double dfReplacementPct=0.25)
Start the refresh process which only valid when initialized with LoadLimit > 0.
Definition: ImageSet2.cs:162
void Unload(bool bReload)
Unload all images from the master list (freeing memory) and optionally reload the dataset.
Definition: ImageSet2.cs:206
void SetImageMean(SimpleDatum sd, bool bSave=false)
Sets the data source image mean.
Definition: ImageSet2.cs:328
SimpleDatum GetImageMean(Log log, WaitHandle[] rgAbort, bool bQueryOnly)
Get the image mean for the iamge set, or create one if it does not exist.
Definition: ImageSet2.cs:248
bool WaitForLoadingToComplete(int nWait=int.MaxValue)
Wait for the image set to complete loading.
Definition: ImageSet2.cs:136
int GetTotalCount()
Get the total number of images in the image set whether loaded or not.
Definition: ImageSet2.cs:227
EventHandler< CalculateImageMeanArgs > OnCalculateImageMean
The OnCalculateImageMean event fires when the ImageSet needs to calculate the image mean for the imag...
Definition: ImageSet2.cs:30
bool IsRefreshRunning
Returns whether or not the refresh is running.
Definition: ImageSet2.cs:153
List< DbItem > ResetAllBoosts()
Reset all boosts to their original settings.
Definition: ImageSet2.cs:291
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 ...
Definition: ImageSet2.cs:102
TYPE
Defines the type of image set.
Definition: ImageSet2.cs:36
List< DbItem > Relabel(LabelMappingCollection col)
Reset the image set based on the LabelMappingCollection.
Definition: ImageSet2.cs:280
List< DbItem > ReloadIndexing()
Reload the indexing for the image set.
Definition: ImageSet2.cs:257
void StopRefresh()
Abort any refresh currently running.
Definition: ImageSet2.cs:180
SourceDescriptor Source
Returns the data source of the image set.
Definition: ImageSetBase.cs:65
The QueryStateCollection manages all query states used by matching the QueryState handles with the Qu...
Definition: QueryState.cs:212
void ReIndexTraining(List< DbItem > rgItems)
Relabels the training QueryState based on the DbItems.
Definition: QueryState.cs:320
QueryState GetTrainingState(long lHandle)
Returns the QueryState used with thet Training data source.
Definition: QueryState.cs:289
bool FreeQueryState(long lHandle)
Free the QueryStates associated with the handle and remove it from the handle list.
Definition: QueryState.cs:265
QueryState GetTestingState(long lHandle)
Returns the QueryState used with thet Testing data source.
Definition: QueryState.cs:305
void ReIndexTesting(List< DbItem > rgItems)
Relabels the testing QueryState based on the DbItems.
Definition: QueryState.cs:336
long CreateNewState(QueryState training, QueryState testing)
Create a new QueryState handle based on the QueryStates passed to this function.
Definition: QueryState.cs:245
Initially the QueryState is copied from the MasterIndexes and during each query is altered by removin...
Definition: QueryState.cs:19
The descriptors namespace contains all descriptor used to describe various items stored within the da...
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
DB_LOAD_METHOD
Defines how to laod the items into the in-memory database.
Definition: Interfaces.cs:154
IMGDB_SORT
Defines the sorting method.
Definition: Interfaces.cs:358
The MyCaffe.db.image namespace contains all image database related classes.
Definition: Database.cs:18
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12