MyCaffe  1.11.8.27
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 == "MODEL") ? true : false; }
159 }
160
164 public string FullName
165 {
166 get { return (IsGym) ? "GYM:" + Name : Name; }
167 }
168
174 public static bool IsGymName(string str)
175 {
176 if (str.IndexOf("GYM:") == 0)
177 return true;
178
179 return false;
180 }
181
187 public static bool IsModelDataName(string str)
188 {
189 if (str == "MODEL")
190 return true;
191
192 return false;
193 }
194
201 public static string GetGymName(string str, out string strType)
202 {
203 strType = null;
204
205 int nPos = str.IndexOf("GYM:");
206 if (nPos < 0)
207 return str;
208
209 str = str.Substring(4);
210
211 nPos = str.IndexOf(':');
212 if (nPos < 0)
213 return str;
214
215 strType = str.Substring(nPos + 1);
216 return str.Substring(0, nPos);
217 }
218
222 [Category("Groups"), Description("Specifies the dataset group (if any).")]
224 {
225 get { return m_groupDataset; }
226 }
227
231 [Category("Groups"), Description("Specifies the model group (if any).")]
233 {
234 get { return m_groupModel; }
235 set { m_groupModel = value; }
236 }
237
241 [Category("Sources"), Description("Specifies the data source used when training.")]
243 {
244 get { return m_srcTrain; }
245 set { m_srcTrain = value; }
246 }
247
251 [Category("Sources"), Description("Specifies the data source used when testing.")]
253 {
254 get { return m_srcTest; }
255 set { m_srcTest = value; }
256 }
257
261 [Browsable(false)]
262 public string TrainingSourceName
263 {
264 get { return (m_srcTrain == null) ? null : m_srcTrain.Name; }
265 }
266
270 [Browsable(false)]
271 public string TestingSourceName
272 {
273 get { return (m_srcTest == null) ? null : m_srcTest.Name; }
274 }
275
279 [Description("Specifies the name of the creator used to create this dataset.")]
280 public string CreatorName
281 {
282 get { return m_strCreatorName; }
283 }
284
288 [Description("Specifies the description of this dataset.")]
289 public string Description
290 {
291 get { return m_strDescription; }
292 set { m_strDescription = value; }
293 }
294
298 [Description("Specifies the parameters of the data set (if any).")]
300 {
301 get { return m_colParameters; }
302 set { m_colParameters = value; }
303 }
304
310 public static byte[] Serialize(DatasetDescriptor ds)
311 {
312 using (MemoryStream ms = new MemoryStream())
313 {
314 BinaryFormatter bf = new BinaryFormatter();
315 bf.Serialize(ms, ds);
316 ms.Flush();
317 return ms.ToArray();
318 }
319 }
320
326 public static DatasetDescriptor Deserialize(byte[] rg)
327 {
328 using (MemoryStream ms = new MemoryStream(rg))
329 {
330 BinaryFormatter bf = new BinaryFormatter();
331 return bf.Deserialize(ms) as DatasetDescriptor;
332 }
333 }
334
339 public override string ToString()
340 {
341 return m_strCreatorName + ":" + Name;
342 }
343 }
344}
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.
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.
void Resize(int nChannels, int nHeight, int nWidth)
Resize the testing and training data sources.
static bool IsModelDataName(string str)
Returns whether or not the name directs to use data from the model itself.
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.
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:97