MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
DatasetExCollection.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using MyCaffe.basecode;
6
7namespace MyCaffe.db.image
8{
12 public class DatasetExCollection : IEnumerable<DatasetEx>, IDisposable
13 {
14 List<DatasetEx> m_rgDatasets = new List<DatasetEx>();
15 bool m_bUseTrainingSourcesForTesting = false;
16 ImageSet m_lastImgSet = null;
17 object m_syncObj = new object();
18
23 {
24 }
25
31 public bool RemoveDataset(DatasetEx ds)
32 {
33 return m_rgDatasets.Remove(ds);
34 }
35
40 {
41 List<int> rgIdx = new List<int>();
42
43 for (int i = 0; i < m_rgDatasets.Count; i++)
44 {
45 if (m_rgDatasets[i].Descriptor.ID < 0)
46 rgIdx.Add(i);
47 }
48
49 for (int i = rgIdx.Count - 1; i >= 0; i--)
50 {
51 m_rgDatasets.RemoveAt(rgIdx[i]);
52 }
53 }
54
60 public bool RemoveUser(Guid user)
61 {
62 bool bReleased = true;
63
64 foreach (DatasetEx ds in m_rgDatasets)
65 {
66 if (ds.RemoveUser(user) > 0)
67 bReleased = false;
68 }
69
70 return bReleased;
71 }
72
80 public bool SaveImageMean(int nSrcID, SimpleDatum sd, bool bUpdate)
81 {
82 foreach (DatasetEx ds in m_rgDatasets)
83 {
84 if (ds.SaveImageMean(nSrcID, sd, bUpdate))
85 return true;
86 }
87
88 return false;
89 }
90
96 public SimpleDatum QueryImageMean(int nSrcID)
97 {
98 foreach (DatasetEx ds in m_rgDatasets)
99 {
100 SimpleDatum sd = ds.QueryImageMean(nSrcID);
101 if (sd != null)
102 return sd;
103 }
104
105 return null;
106 }
107
113 {
115
116 col.m_bUseTrainingSourcesForTesting = m_bUseTrainingSourcesForTesting;
117
118 foreach (DatasetEx ds in m_rgDatasets)
119 {
120 col.Add(ds.Clone());
121 }
122
123 return col;
124 }
125
129 public void Reset()
130 {
131 m_lastImgSet = null;
132 }
133
139 {
140 foreach (DatasetEx ds in m_rgDatasets)
141 {
142 ds.Relabel(col);
143 }
144 }
145
149 public int Count
150 {
151 get { return m_rgDatasets.Count; }
152 }
153
158 public void EnableUsingTrainingSourcesForTesting(bool bEnable)
159 {
160 m_bUseTrainingSourcesForTesting = bEnable;
161
162 foreach (DatasetEx ds in m_rgDatasets)
163 {
164 ds.UseTrainingImagesForTesting = bEnable;
165 }
166 }
167
172 {
173 get { return m_bUseTrainingSourcesForTesting; }
174 }
175
181 public DatasetEx this[int nIdx]
182 {
183 get { return m_rgDatasets[nIdx]; }
184 }
185
191 public DatasetEx FindDataset(int nDatasetID)
192 {
193 foreach (DatasetEx ds in m_rgDatasets)
194 {
195 if (ds.DatasetID == nDatasetID)
196 return ds;
197 }
198
199 return null;
200 }
201
207 public DatasetEx FindDataset(string strDs)
208 {
209 foreach (DatasetEx ds in m_rgDatasets)
210 {
211 if (ds.DatasetName == strDs)
212 return ds;
213 }
214
215 return null;
216 }
217
223 public ImageSet FindImageset(int nSourceID)
224 {
225 lock (m_syncObj)
226 {
227 if (m_lastImgSet != null && m_lastImgSet.SourceID == nSourceID)
228 return m_lastImgSet;
229
230 foreach (DatasetEx ds in m_rgDatasets)
231 {
232 ImageSet imgSet = ds.Find(nSourceID);
233
234 if (imgSet != null)
235 {
236 m_lastImgSet = imgSet;
237 return imgSet;
238 }
239 }
240
241 throw new Exception("Could not find source with ID = " + nSourceID.ToString() + "!");
242 }
243 }
244
250 public ImageSet FindImageset(string strSource)
251 {
252 lock (m_syncObj)
253 {
254 if (m_lastImgSet != null && m_lastImgSet.SourceName == strSource)
255 return m_lastImgSet;
256
257 foreach (DatasetEx ds in m_rgDatasets)
258 {
259 ImageSet imgSet = ds.Find(strSource);
260
261 if (imgSet != null)
262 {
263 m_lastImgSet = imgSet;
264 return imgSet;
265 }
266 }
267
268 throw new Exception("Could not find source with Name = " + strSource + "!");
269 }
270 }
271
276 public void Add(DatasetEx ds)
277 {
278 m_rgDatasets.Add(ds);
279 }
280
285 protected virtual void Dispose(bool bDisposing)
286 {
287 foreach (DatasetEx ds in m_rgDatasets)
288 {
289 ds.Dispose();
290 }
291
292 m_rgDatasets.Clear();
293 }
294
298 public void Dispose()
299 {
300 Dispose(true);
301 }
302
307 public IEnumerator<DatasetEx> GetEnumerator()
308 {
309 return m_rgDatasets.GetEnumerator();
310 }
311
316 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
317 {
318 return m_rgDatasets.GetEnumerator();
319 }
320 }
321}
The LabelMappingCollection manages a collection of LabelMapping's.
Definition: LabelMapping.cs:15
The SimpleDatum class holds a data input within host memory.
Definition: SimpleDatum.cs:161
The DatasetExCollection contains a list of DatasetEx objects.
void Dispose()
Releases all resources used by the collection.
void Add(DatasetEx ds)
Adds a DatasetEx to the collection.
IEnumerator< DatasetEx > GetEnumerator()
Returns the enumerator for 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.
void Relabel(LabelMappingCollection col)
Relabels all datasets using a label mapping collection.
bool SaveImageMean(int nSrcID, SimpleDatum sd, bool bUpdate)
Saves the image mean in a SimpleDatum to the database for a data source.
SimpleDatum QueryImageMean(int nSrcID)
Returns the image mean for a data source.
ImageSet FindImageset(string strSource)
Searches for the ImageSet with a given data source name.
DatasetEx FindDataset(string strDs)
Searches for the dataset with the dataset name.
void EnableUsingTrainingSourcesForTesting(bool bEnable)
Enable/disable the using of the training sources for testing on all datasets.
int Count
Returns the number of datasets in the collection.
void RemoveCreatedDatasets()
Remove all dynamically created datasets.
bool UseTrainingSourcesForTesting
Returns whether or not the training sources are set to be used for testing.
DatasetExCollection Clone()
Creates a copy of the entire DatasetExCollection.
DatasetExCollection()
The DatasetExCollection constructor.
virtual void Dispose(bool bDisposing)
Releases all resources used by the collection.
bool RemoveDataset(DatasetEx ds)
Remove the dataset specified.
ImageSet FindImageset(int nSourceID)
Searches for the ImageSet with a given data source ID.
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...
Definition: DatasetEx.cs:17
int DatasetID
Returns the dataset ID of the dataset managesd by the DatasetEx object.
Definition: DatasetEx.cs:536
DatasetEx Clone(bool bReOrganizeByTime=false)
Copy the DatasetEx and its contents.
Definition: DatasetEx.cs:135
string DatasetName
Returns the dataset name of the dataset managesd by the DatasetEx object.
Definition: DatasetEx.cs:553
virtual void Dispose(bool bDisposing)
Releases all resources used.
Definition: DatasetEx.cs:447
SimpleDatum QueryImageMean(int nSrcId)
Query the image mean for a data source.
Definition: DatasetEx.cs:400
ImageSet Find(int nSourceID)
Returns the ImageSet corresponding to a data source ID.
Definition: DatasetEx.cs:483
bool UseTrainingImagesForTesting
Get/set whether or not to use the training images when testing.
Definition: DatasetEx.cs:215
int RemoveUser(Guid user)
Remove a user of the dataset.
Definition: DatasetEx.cs:76
bool SaveImageMean(int nSrcId, SimpleDatum sd, bool bUpdate)
Saves the image mean in a SimpleDatum to the database.
Definition: DatasetEx.cs:386
void Relabel(LabelMappingCollection col)
Relabels both the testing and training image sets using the label mapping collection.
Definition: DatasetEx.cs:196
The ImageSet class contains the list of image for a data source as well as a list of LabelSets that m...
Definition: Imageset.cs:17
string SourceName
Returns the data source name of the image set.
Definition: Imageset.cs:410
int SourceID
Returns the data source ID of the image set.
Definition: Imageset.cs:402
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
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