MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
DatasetCollection.cs
1using MyCaffe.basecode;
3using System;
4using System.Collections.Generic;
5using System.Linq;
6using System.Text;
7using System.Threading.Tasks;
8
10{
14 public class DatasetCollection : IDisposable
15 {
16 Dictionary<int, DataSet> m_rgDatasets = new Dictionary<int, DataSet>();
17 Dictionary<string, int> m_rgDatasetIDs = new Dictionary<string, int>();
18 Dictionary<int, int> m_rgSourceIDtoDatasetID = new Dictionary<int, int>();
19
24 {
25 }
26
30 public void Dispose()
31 {
32 CleanUp(0);
33 }
34
39 public void CleanUp(int nDsID)
40 {
41 if (nDsID == 0)
42 {
43 foreach (KeyValuePair<int, DataSet> kv in m_rgDatasets)
44 {
45 kv.Value.CleanUp();
46 }
47 }
48 else
49 {
50 if (m_rgDatasets.ContainsKey(nDsID))
51 {
52 m_rgDatasets[nDsID].CleanUp();
53 m_rgDatasets.Remove(nDsID);
54 }
55 }
56 }
57
65 {
66 DataSet ds = Find(dsd.ID);
67 if (ds != null)
68 return ds;
69
70 ds = new DataSet(dsd, log);
71 Add(ds);
72
73 if (!m_rgSourceIDtoDatasetID.ContainsKey(ds.Dataset.TrainingSource.ID))
74 m_rgSourceIDtoDatasetID.Add(ds.Dataset.TrainingSource.ID, ds.Dataset.ID);
75 if (!m_rgSourceIDtoDatasetID.ContainsKey(ds.Dataset.TestingSource.ID))
76 m_rgSourceIDtoDatasetID.Add(ds.Dataset.TestingSource.ID, ds.Dataset.ID);
77
78 return ds;
79 }
80
85 public void Add(DataSet ds)
86 {
87 m_rgDatasets.Add(ds.Dataset.ID, ds);
88
89 if (!m_rgDatasetIDs.ContainsKey(ds.Dataset.Name))
90 m_rgDatasetIDs.Add(ds.Dataset.Name, ds.Dataset.ID);
91
92 if (!m_rgSourceIDtoDatasetID.ContainsKey(ds.Dataset.TrainingSource.ID))
93 m_rgSourceIDtoDatasetID.Add(ds.Dataset.TrainingSource.ID, ds.Dataset.ID);
94 if (!m_rgSourceIDtoDatasetID.ContainsKey(ds.Dataset.TestingSource.ID))
95 m_rgSourceIDtoDatasetID.Add(ds.Dataset.TestingSource.ID, ds.Dataset.ID);
96 }
97
103 public DataSet Find(int nDatasetID)
104 {
105 if (!m_rgDatasets.ContainsKey(nDatasetID))
106 return null;
107
108 return m_rgDatasets[nDatasetID];
109 }
110
116 public DataSet Find(string strDs)
117 {
118 int nDsID = GetDatasetID(strDs);
119 if (nDsID == 0)
120 return null;
121
122 return Find(nDsID);
123 }
124
131 {
132 foreach (KeyValuePair<int, DataSet> kvp in m_rgDatasets)
133 {
134 SourceDescriptor src = kvp.Value.Dataset.TrainingSource;
135 if (src.ID == nSrcID)
136 return src;
137
138 src = kvp.Value.Dataset.TestingSource;
139 if (src.ID == nSrcID)
140 return src;
141 }
142
143 return null;
144 }
145
151 public SourceDescriptor FindSourceByName(string strSrc)
152 {
153 foreach (KeyValuePair<int, DataSet> kvp in m_rgDatasets)
154 {
155 SourceDescriptor src = kvp.Value.Dataset.TrainingSource;
156 if (src.Name == strSrc)
157 return src;
158
159 src = kvp.Value.Dataset.TestingSource;
160 if (src.Name == strSrc)
161 return src;
162 }
163
164 return null;
165 }
166
173 {
174 if (!m_rgSourceIDtoDatasetID.ContainsKey(nSrcID))
175 return null;
176
177 int nDsID = m_rgSourceIDtoDatasetID[nSrcID];
178
179 DataSet ds = Find(nDsID);
180 if (ds == null)
181 return null;
182
183 return ds.GetTemporalSetBySourceID(nSrcID);
184 }
185
191 public int GetDatasetID(string strDs)
192 {
193 if (!m_rgDatasetIDs.ContainsKey(strDs))
194 return 0;
195
196 return m_rgDatasetIDs[strDs];
197 }
198 }
199}
The Log class provides general output in text form.
Definition: Log.cs:13
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.
The SourceDescriptor class contains all information describing a data source.
The DataSet class loads the training and testing data.
Definition: DataSet.cs:17
DatasetDescriptor Dataset
Return the dataset descriptor.
Definition: DataSet.cs:55
TemporalSet GetTemporalSetBySourceID(int nSourceID)
Returns the temporal set for the specified source ID.
Definition: DataSet.cs:77
The DatasetCollection manages a set of datasets.
void Dispose()
Release all resources used.
TemporalSet FindTemporalSetBySourceID(int nSrcID)
Find the temporal set associated with the source ID.
SourceDescriptor FindSourceByID(int nSrcID)
Find the source descriptor associated with the source ID.
void CleanUp(int nDsID)
Release all resources used by the dataset with the specified ID.
DataSet Find(string strDs)
Find and return the dataset associated with the dataset name.
DataSet Find(int nDatasetID)
Find and return the dataset associated with the dataset ID.
DataSet Add(DatasetDescriptor dsd, Log log)
Add a new dataset to the collection if it does not already exist.
SourceDescriptor FindSourceByName(string strSrc)
Find the source descriptor associated with the source Name.
void Add(DataSet ds)
Add a new dataset to the collection.
int GetDatasetID(string strDs)
Returns the dataset ID associated with the dataset name.
The TemporalSet manages a set of temporal data for a given data source.
Definition: TemporalSet.cs:21
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
The MyCaffe.db.temporal namespace contains all classes used to create the MyCaffeTemporalDatabase in-...
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12