MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
DatasetDescriptor.cs
1using System;
2using System.Collections.Generic;
4using System.IO;
5using System.Linq;
6using System.Runtime.Serialization.Formatters.Binary;
7using System.Text;
8using System.Threading.Tasks;
9
11{
15 [Serializable]
16 [TypeConverter(typeof(ExpandableObjectConverter))]
18 {
19 SourceDescriptor m_srcTest;
20 SourceDescriptor m_srcTrain;
21 GroupDescriptor m_groupDataset;
22 GroupDescriptor m_groupModel;
24 string m_strCreatorName;
25 string m_strDescription;
26 GYM_TYPE m_gymType = GYM_TYPE.NONE;
27
41 public DatasetDescriptor(int nID, string strName, GroupDescriptor grpModel, GroupDescriptor grpDs, SourceDescriptor srcTrain, SourceDescriptor srcTest, string strCreatorName, string strDescription, string strOwner = null, GYM_TYPE gymType = GYM_TYPE.NONE)
42 : base(nID, strName, strOwner)
43 {
44 m_gymType = gymType;
45
46 if (grpModel != null)
47 m_groupModel = new descriptors.GroupDescriptor(grpModel);
48 else
49 m_groupModel = new descriptors.GroupDescriptor(0, null, null);
50
51 if (grpDs != null)
52 m_groupDataset = new descriptors.GroupDescriptor(grpDs);
53 else
54 m_groupDataset = new descriptors.GroupDescriptor(0, null, null);
55
56 if (srcTest != null)
57 m_srcTest = new SourceDescriptor(srcTest);
58
59 if (srcTrain != null)
60 m_srcTrain = new SourceDescriptor(srcTrain);
61
62 m_strDescription = strDescription;
63 m_strCreatorName = strCreatorName;
64 }
65
70 public DatasetDescriptor(string strName)
71 : this(0, strName, null, null, null, null, null, "")
72 {
73 }
74
81 {
82 m_colParameters = new ParameterDescriptorCollection(d.Parameters);
83 }
84
91 public void Resize(int nChannels, int nHeight, int nWidth)
92 {
93 m_srcTest.Resize(nChannels, nHeight, nWidth);
94 m_srcTrain.Resize(nChannels, nHeight, nWidth);
95 }
96
101 public void Copy(DatasetDescriptor ds)
102 {
103 base.Copy(ds);
104
105 m_gymType = ds.m_gymType;
106
107 if (ds.m_srcTest != null)
108 m_srcTest = new SourceDescriptor(ds.m_srcTest);
109 else
110 m_srcTest = null;
111
112 if (ds.m_srcTrain != null)
113 m_srcTrain = new SourceDescriptor(ds.m_srcTrain);
114 else
115 m_srcTrain = null;
116
117 if (ds.m_groupDataset != null)
118 m_groupDataset = new GroupDescriptor(ds.m_groupDataset);
119 else
120 m_groupDataset = null;
121
122 if (ds.m_groupModel != null)
123 m_groupModel = new GroupDescriptor(ds.m_groupModel);
124 else
125 m_groupModel = null;
126
127 m_colParameters = new descriptors.ParameterDescriptorCollection();
128 foreach (ParameterDescriptor p in ds.m_colParameters)
129 {
130 m_colParameters.Add(new ParameterDescriptor(p));
131 }
132
133 m_strCreatorName = ds.m_strCreatorName;
134 m_strDescription = ds.m_strDescription;
135 }
136
140 public bool IsGym
141 {
142 get { return (m_gymType == GYM_TYPE.NONE) ? false : true; }
143 }
144
149 {
150 get { return m_gymType; }
151 }
152
156 public bool IsModelData
157 {
158 get { return Name.StartsWith("MODEL") ? true : false; }
159 }
160
164 public bool IsDataTemporal
165 {
166 get { return IsModelData && Name.Contains("TEMPORAL") || (TrainingSource != null && TrainingSource.TemporalDescriptor != null); }
167 }
168
172 public string FullName
173 {
174 get { return (IsGym) ? "GYM:" + Name : Name; }
175 }
176
182 public static bool IsGymName(string str)
183 {
184 if (str.IndexOf("GYM:") == 0)
185 return true;
186
187 return false;
188 }
189
196 public static bool IsModelDataName(string str, out bool bTemporal)
197 {
198 bTemporal = false;
199
200 if (str.StartsWith("MODEL"))
201 {
202 if (str.Contains(":TEMPORAL"))
203 bTemporal = true;
204 return true;
205 }
206
207 return false;
208 }
209
216 public static string GetGymName(string str, out string strType)
217 {
218 strType = null;
219
220 int nPos = str.IndexOf("GYM:");
221 if (nPos < 0)
222 return str;
223
224 str = str.Substring(4);
225
226 nPos = str.IndexOf(':');
227 if (nPos < 0)
228 return str;
229
230 strType = str.Substring(nPos + 1);
231 return str.Substring(0, nPos);
232 }
233
237 [Category("Groups"), Description("Specifies the dataset group (if any).")]
239 {
240 get { return m_groupDataset; }
241 }
242
246 [Category("Groups"), Description("Specifies the model group (if any).")]
248 {
249 get { return m_groupModel; }
250 set { m_groupModel = value; }
251 }
252
256 [Category("Sources"), Description("Specifies the data source used when training.")]
258 {
259 get { return m_srcTrain; }
260 set { m_srcTrain = value; }
261 }
262
266 [Category("Sources"), Description("Specifies the data source used when testing.")]
268 {
269 get { return m_srcTest; }
270 set { m_srcTest = value; }
271 }
272
276 [Browsable(false)]
277 public string TrainingSourceName
278 {
279 get { return (m_srcTrain == null) ? null : m_srcTrain.Name; }
280 }
281
285 [Browsable(false)]
286 public string TestingSourceName
287 {
288 get { return (m_srcTest == null) ? null : m_srcTest.Name; }
289 }
290
294 [Description("Specifies the name of the creator used to create this dataset.")]
295 public string CreatorName
296 {
297 get { return m_strCreatorName; }
298 }
299
303 [Description("Specifies the description of this dataset.")]
304 public string Description
305 {
306 get { return m_strDescription; }
307 set { m_strDescription = value; }
308 }
309
313 [Description("Specifies the parameters of the data set (if any).")]
315 {
316 get { return m_colParameters; }
317 set { m_colParameters = value; }
318 }
319
325 public static byte[] Serialize(DatasetDescriptor ds)
326 {
327 using (MemoryStream ms = new MemoryStream())
328 {
329 BinaryFormatter bf = new BinaryFormatter();
330 bf.Serialize(ms, ds);
331 ms.Flush();
332 return ms.ToArray();
333 }
334 }
335
341 public static DatasetDescriptor Deserialize(byte[] rg)
342 {
343 using (MemoryStream ms = new MemoryStream(rg))
344 {
345 BinaryFormatter bf = new BinaryFormatter();
346 return bf.Deserialize(ms) as DatasetDescriptor;
347 }
348 }
349
354 public override string ToString()
355 {
356 return m_strCreatorName + ":" + Name;
357 }
358 }
359}
The BaseDescriptor is the base class for all other descriptors, where descriptors are used to describ...
string Owner
Get/set the owner of the item.
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...
GroupDescriptor DatasetGroup
Returns the dataset group.
bool? IsGym
Returns whether or not this dataset is from a Gym.
SourceDescriptor TrainingSource
Get/set the training data source.
static DatasetDescriptor Deserialize(byte[] rg)
Deserialize a dataset descriptor from a byte array.
GroupDescriptor ModelGroup
Get/set the dataset model group.
string? TrainingSourceName
Returns the training source name, or null if not specifies.
bool? IsModelData
Returns whether or not this dataset is from the model itself.
bool IsDataTemporal
Returns whether or not this dataset is from the model itself and is temporal.
string CreatorName
Returns the dataset creator name.
SourceDescriptor TestingSource
Get/set the testing data source.
string? TestingSourceName
Returns the testing source name or null if not specified.
static bool IsGymName(string str)
Returns whether or not the name is from a gym.
DatasetDescriptor(string strName)
The DatasetDescriptor constructor.
static byte[] Serialize(DatasetDescriptor ds)
Serialize a dataset descriptor to a byte array.
string? FullName
Returns the full name which returns 'GYM:Name:Type' when using a gym based dataset,...
GYM_TYPE GymType
Returns the Gym type, if any.
static bool IsModelDataName(string str, out bool bTemporal)
Returns whether or not the name directs to use data from the model itself.
void Resize(int nChannels, int nHeight, int nWidth)
Resize the testing and training data sources.
ParameterDescriptorCollection Parameters
Get/set the dataset parameters (if any).
static string GetGymName(string str, out string strType)
Returns the actual gym name by parsing off the 'GYM:' if it exists.
DatasetDescriptor(DatasetDescriptor d)
The DatasetDescriptor constructor.
string Description
Get/set the description of the Dataset.
override string ToString()
Creates the string representation of the descriptor.
DatasetDescriptor(int nID, string strName, GroupDescriptor grpModel, GroupDescriptor grpDs, SourceDescriptor srcTrain, SourceDescriptor srcTest, string strCreatorName, string strDescription, string strOwner=null, GYM_TYPE gymType=GYM_TYPE.NONE)
The DatasetDescriptor constructor.
void Copy(DatasetDescriptor ds)
Copy another DatasetDesciptor into this one.
The GroupDescriptor class defines a group.
GroupDescriptor(int nID, string strName, string strOwner)
The GroupDescriptor constructor.
The ParameterDescriptorCollection class contains a list of ParameterDescriptor's.
void Add(ParameterDescriptor p)
Adds a ParameterDescriptor to the collection.
ParameterDescriptorCollection()
The ParameterDescriptorCollection constructor.
The ParameterDescriptor class describes a parameter in the database.
The SourceDescriptor class contains all information describing a data source.
void Resize(int nChannels, int nHeight, int nWidth)
Resize the testing and training data sources.
TemporalDescriptor TemporalDescriptor
Get/set the temporal descriptor (if any).
The descriptors namespace contains all descriptor used to describe various items stored within the da...
GYM_TYPE
Defines the gym type (if any).
Definition: Interfaces.cs:116