MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
TransformationParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.basecode;
7using MyCaffe.common;
8using MyCaffe.param.ssd;
9
10namespace MyCaffe.param
11{
16 [Serializable]
17 [TypeConverter(typeof(ExpandableObjectConverter))]
19 {
20 double m_dfScale = 1;
21 SCALE_OPERATOR? m_scaleOperator = null;
22 bool m_bMirror = false;
23 uint m_nCropSize = 0;
24 bool m_bUseImageDbMean = false;
25 List<double> m_rgMeanValue = new List<double>();
26 bool m_bForceColor = false;
27 bool m_bForceGray = false;
28 double m_dfForcedPositiveRangeMax = 0.0;
29 int? m_nRandomSeed = null;
30 string m_strMeanFile = null;
31 COLOR_ORDER m_colorOrder = COLOR_ORDER.RGB;
32 ResizeParameter m_resize = new ResizeParameter(false);
33 NoiseParameter m_noise = new NoiseParameter(false);
34 DistortionParameter m_distortion = new DistortionParameter(false);
35 ExpansionParameter m_expansion = new ExpansionParameter(false);
36 EmitConstraint m_emitConstraint = new EmitConstraint(false);
37 MaskParameter m_mask = new MaskParameter(false);
38 DataLabelMappingParameter m_labelMapping = new DataLabelMappingParameter(false);
39
43 public enum SCALE_OPERATOR
44 {
48 NONE,
52 MUL,
56 POW
57 }
58
62 public enum COLOR_ORDER
63 {
67 RGB = 0,
71 BGR = 1
72 }
73
78 {
79 }
80
85 [Category("Data Pre-Processing"), Description("When specified (value > 0), the data values are fit into the positive range [0, forced_positive_range_max]. When set to 0 no range fitting is performed.")]
87 {
88 get { return m_dfForcedPositiveRangeMax; }
89 set { m_dfForcedPositiveRangeMax = value; }
90 }
91
97 [Category("Data Pre-Processing"), Description("This value is used for simple scaling and subtracting the data mean if provided. Note that the mean subtraction is always carried out before scaling.")]
98 public double scale
99 {
100 get { return m_dfScale; }
101 set { m_dfScale = value; }
102 }
103
108 {
109 get { return m_scaleOperator; }
110 set { m_scaleOperator = value; }
111 }
112
116 [Category("Data Pre-Processing"), Description("Specify if we want to randomly mirror the data.")]
117 public bool mirror
118 {
119 get { return m_bMirror; }
120 set { m_bMirror = value; }
121 }
122
126 [Category("Data Pre-Processing"), Description("Specify if we want to randomly crop the image. A value of 0 disables the croping.")]
127 public uint crop_size
128 {
129 get { return m_nCropSize; }
130 set { m_nCropSize = value; }
131 }
132
137 [Category("Data Mean"), Description("Specifies whether or not to use the image mean for the data source from the image database. When true, the mean image is subtracted from the current image.")]
139 {
140 get { return m_bUseImageDbMean; }
141 set { m_bUseImageDbMean = value; }
142 }
143
154 [Category("Data Mean"), Description("If specified can be repeated once (will subtract the value from all of teh channels, or can be repeated the same number of times as channels which will then subtract each corresponding value from each associated channel) So for example if there are 3 channels, mean values could have 3 values (one for each channel) or just one value that is then applied to all channels.")]
155 public List<double> mean_value
156 {
157 get { return m_rgMeanValue; }
158 set { m_rgMeanValue = value; }
159 }
160
164 [Category("Data Color"), Description("When true, force the decoded image to have 3 color channels.")]
165 public bool force_color
166 {
167 get { return m_bForceColor; }
168 set { m_bForceColor = value; }
169 }
170
174 [Category("Data Color"), Description("When true, force the decoded image to have 1 color channel.")]
175 public bool force_gray
176 {
177 get { return m_bForceGray; }
178 set { m_bForceGray = value; }
179 }
180
184 [Category("Testing"), Description("Only used during testing.")]
185 public int? random_seed
186 {
187 get { return m_nRandomSeed; }
188 set { m_nRandomSeed = value; }
189 }
190
198 [Category("Data Mean"), Description("The mean file is used when specified and 'use_imagedb_mean' = true. If the 'use_imagedb_mean' is true and the 'mean_file' is not set, then the image database is queried for the mean image to use.")]
199 public string mean_file
200 {
201 get { return m_strMeanFile; }
202 set { m_strMeanFile = value; }
203 }
204
209 [Category("Data Color"), Description("Specifies the color ordering to use. Native Caffe models expect the BGR color ordering.")]
211 {
212 get { return m_colorOrder; }
213 set { m_colorOrder = value; }
214 }
215
222 [Category("Image"), Description("When active, used as the resize policy for altering image data.")]
224 {
225 get { return m_resize; }
226 set { m_resize = value; }
227 }
228
235 [Category("Image"), Description("When active, used as the noise policy for altering image data.")]
237 {
238 get { return m_noise; }
239 set { m_noise = value; }
240 }
241
248 [Category("Image"), Description("When active, used as the distortion policy for altering image data.")]
250 {
251 get { return m_distortion; }
252 set { m_distortion = value; }
253 }
254
261 [Category("Image"), Description("When active, used as the expansion policy for altering image data.")]
263 {
264 get { return m_expansion; }
265 set { m_expansion = value; }
266 }
267
274 [Category("Image"), Description("When active, used as the emit constratin for emitting annotation after transformation.")]
276 {
277 get { return m_emitConstraint; }
278 set { m_emitConstraint = value; }
279 }
280
289 [Category("Image"), Description("When active, used to mask portions of the image (set to Black) as defined by the boundary of the mask. The mask is applied after all other alterations.")]
291 {
292 get { return m_mask; }
293 set { m_mask = value; }
294 }
295
303 {
304 get { return m_labelMapping; }
305 set { m_labelMapping = value; }
306 }
307
309 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
310 {
311 RawProto proto = RawProto.Parse(br.ReadString());
313
314 if (!bNewInstance)
315 Copy(p);
316
317 return p;
318 }
319
321 public override void Copy(LayerParameterBase src)
322 {
324
325 m_bUseImageDbMean = p.m_bUseImageDbMean;
326 m_bForceColor = p.m_bForceColor;
327 m_bForceGray = p.m_bForceGray;
328 m_bMirror = p.m_bMirror;
329 m_dfScale = p.m_dfScale;
330 m_scaleOperator = p.m_scaleOperator;
331 m_nCropSize = p.m_nCropSize;
332 m_rgMeanValue = Utility.Clone<double>(p.m_rgMeanValue);
333 m_dfForcedPositiveRangeMax = p.m_dfForcedPositiveRangeMax;
334 m_nRandomSeed = p.m_nRandomSeed;
335 m_strMeanFile = p.m_strMeanFile;
336 m_colorOrder = p.m_colorOrder;
337
338 m_resize = (p.resize_param == null) ? null : p.resize_param.Clone();
339 m_noise = (p.noise_param == null) ? null : p.noise_param.Clone();
340 m_distortion = (p.distortion_param == null) ? null : p.distortion_param.Clone();
341 m_expansion = (p.expansion_param == null) ? null : p.expansion_param.Clone();
342 m_emitConstraint = (p.emit_constraint == null) ? null : p.emit_constraint.Clone();
343
344 if (p.mask_param != null)
345 m_mask = p.mask_param.Clone();
346
347 if (p.label_mapping != null)
348 m_labelMapping = p.label_mapping.Clone();
349 }
350
352 public override LayerParameterBase Clone()
353 {
355 p.Copy(this);
356 return p;
357 }
358
364 public override RawProto ToProto(string strName)
365 {
366 RawProtoCollection rgChildren = new RawProtoCollection();
367
368 if (scale != 1.0)
369 rgChildren.Add("scale", scale.ToString());
370
371 if (scale_operator.HasValue)
372 rgChildren.Add("scale_operator", scale_operator.Value.ToString());
373
374 if (mirror != false)
375 rgChildren.Add("mirror", mirror.ToString());
376
377 if (crop_size != 0)
378 rgChildren.Add("crop_size", crop_size.ToString());
379
380 if (use_imagedb_mean != false)
381 rgChildren.Add("use_imagedb_mean", use_imagedb_mean.ToString());
382
383 rgChildren.Add<double>("mean_value", mean_value);
384
385 if (force_color != false)
386 rgChildren.Add("force_color", force_color.ToString());
387
388 if (force_gray != false)
389 rgChildren.Add("force_gray", force_gray.ToString());
390
392 rgChildren.Add("force_positive_range_max", forced_positive_range_max.ToString());
393
394 if (mean_file != null && mean_file.Length > 0)
395 rgChildren.Add("mean_file", mean_file);
396
397 rgChildren.Add("color_order", m_colorOrder.ToString());
398
399 if (m_resize != null)
400 rgChildren.Add(m_resize.ToProto("resize_param"));
401
402 if (m_noise != null)
403 rgChildren.Add(m_noise.ToProto("noise_param"));
404
405 if (m_distortion != null)
406 rgChildren.Add(m_distortion.ToProto("distortion_param"));
407
408 if (m_expansion != null)
409 rgChildren.Add(m_expansion.ToProto("expansion_param"));
410
411 if (m_emitConstraint != null)
412 rgChildren.Add(m_emitConstraint.ToProto("emit_constraint"));
413
414 if (m_mask != null)
415 rgChildren.Add(m_mask.ToProto("mask_param"));
416
417 if (m_labelMapping != null)
418 rgChildren.Add(m_labelMapping.ToProto("label_mapping"));
419
420 return new RawProto(strName, "", rgChildren);
421 }
422
429 {
430 string strVal;
432
433 if ((strVal = rp.FindValue("scale")) != null)
434 p.scale = ParseDouble(strVal);
435
436 if ((strVal = rp.FindValue("scale_operator")) != null)
437 {
438 if (strVal == SCALE_OPERATOR.MUL.ToString())
440 else if (strVal == SCALE_OPERATOR.POW.ToString())
442 else
444 }
445 else
446 {
447 p.scale_operator = null;
448 }
449
450 if ((strVal = rp.FindValue("mirror")) != null)
451 p.mirror = bool.Parse(strVal);
452
453 if ((strVal = rp.FindValue("crop_size")) != null)
454 p.crop_size = uint.Parse(strVal);
455
456 if ((strVal = rp.FindValue("use_image_mean")) != null ||
457 (strVal = rp.FindValue("use_imagedb_mean")) != null)
458 p.use_imagedb_mean = bool.Parse(strVal);
459
460 if ((strVal = rp.FindValue("mean_file")) != null)
461 p.use_imagedb_mean = true;
462
463 p.mean_value = rp.FindArray<double>("mean_value");
464
465 if ((strVal = rp.FindValue("force_color")) != null)
466 p.force_color = bool.Parse(strVal);
467
468 if ((strVal = rp.FindValue("force_gray")) != null)
469 p.force_gray = bool.Parse(strVal);
470
471 if ((strVal = rp.FindValue("force_positive_range_max")) != null)
473
474 if ((strVal = rp.FindValue("mean_file")) != null)
475 p.mean_file = strVal;
476
477 if ((strVal = rp.FindValue("color_order")) != null)
478 {
479 if (strVal == COLOR_ORDER.BGR.ToString())
480 p.color_order = COLOR_ORDER.BGR;
481 else
482 p.color_order = COLOR_ORDER.RGB;
483 }
484
485 RawProto rpResize = rp.FindChild("resize_param");
486 if (rpResize != null)
488 else
489 p.resize_param = null;
490
491 RawProto rpNoise = rp.FindChild("noise_param");
492 if (rpNoise != null)
494 else
495 p.noise_param = null;
496
497 RawProto rpDistort = rp.FindChild("distortion_param");
498 if (rpDistort != null)
500
501 RawProto rpExpand = rp.FindChild("expansion_param");
502 if (rpExpand != null)
504 else
505 p.expansion_param = null;
506
507 RawProto rpEmitCon = rp.FindChild("emit_constraint");
508 if (rpEmitCon != null)
510 else
511 p.emit_constraint = null;
512
513 RawProto rpMask = rp.FindChild("mask_param");
514 if (rpMask != null)
516
517 RawProto rpLabelMapping = rp.FindChild("label_mapping");
518 if (rpLabelMapping != null)
520
521 return p;
522 }
523 }
524}
static double ParseDouble(string strVal)
Parse double values using the US culture if the decimal separator = '.', then using the native cultur...
The RawProtoCollection class is a list of RawProto objects.
void Add(RawProto p)
Adds a RawProto to the collection.
The RawProto class is used to parse and output Google prototxt file data.
Definition: RawProto.cs:17
RawProto FindChild(string strName)
Searches for a given node.
Definition: RawProto.cs:231
static RawProto Parse(string str)
Parses a prototxt and places it in a new RawProto.
Definition: RawProto.cs:306
string FindValue(string strName)
Searches for a falue of a node within this nodes children.
Definition: RawProto.cs:105
The Utility class provides general utility funtions.
Definition: Utility.cs:35
Specifies the parameters for the DataLabelMappingParameter used to map labels by the DataTransformer....
DataLabelMappingParameter Clone()
Return a copy of this object.
override RawProto ToProto(string strName)
Convert the DataLabelMappingParameter into a RawProto.
static new DataLabelMappingParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
The LayerParameterBase is the base class for all other layer specific parameters.
Specifies the parameters for the MaskParameter used to mask portions of the transformed data when act...
override RawProto ToProto(string strName)
Convert this object to a raw proto.
static new MaskParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
MaskParameter Clone()
Return a copy of this object.
Stores parameters used to apply transformation to the data layer's data.
int? random_seed
Only used during testing.
COLOR_ORDER
Defines the color ordering used to tranform the input data.
DistortionParameter distortion_param
Optionally, specifies the distortion policy, otherwise this is null.
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
string mean_file
Specifies the path to file containing the image mean in the proto buffer format of a BlobProto.
List< double > mean_value
If specified can be repeated once (would subtract it from all the channels or can be repeated the sam...
bool mirror
Specify if we want to randomly mirror the data.
NoiseParameter noise_param
Optionally, specifies the noise policy, otherwise this is null.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
bool force_color
Force the decoded image to have 3 color channels.
double forced_positive_range_max
Specifies whether or not to fit the data into a forced range of [0, forced_positive_range_max].
bool use_imagedb_mean
Specifies whether to subtract the mean image from the image database, subtract the mean values,...
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
SCALE_OPERATOR
Defines the type of scale operator to use (if any).
uint crop_size
Specify if we would like to randomly crop an image.
DataLabelMappingParameter label_mapping
Optionally, specifies the label mapping which defines how to map lables when calling the DataTransfor...
override void Copy(LayerParameterBase src)
Copy on parameter to another.
COLOR_ORDER color_order
Specifies the color ordering to use. Native Caffe models often uses COLOR_ORDER.BGR,...
ExpansionParameter expansion_param
Optionally, specifies the expansion policy, otherwise this is null.
SCALE_OPERATOR? scale_operator
Get/set the scale operator used to apply the scale value to the data-mean or data result.
ResizeParameter resize_param
Optionally, specifies the resize policy, otherwise this is null.
MaskParameter mask_param
Optionally, specifies the image mask which defines the boundary area that is set to black on the imag...
static TransformationParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
EmitConstraint emit_constraint
Optionally, specifies the emit constraint on emitting annotation after transformation,...
bool force_gray
Force the decoded image to have 1 color channel.
double scale
For data pre-processing, we can do simple scaling and subtracting the data mean, if provided....
Specifies the parameters for the DistortionParameter used with SSD.
override RawProto ToProto(string strName)
Convert this object to a raw proto.
static new DistortionParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
DistortionParameter Clone()
Return a clone of the object.
Specifies the parameters for the EmitConstraint used with SSD.
override RawProto ToProto(string strName)
Convert this object to a raw proto.
EmitConstraint Clone()
Return a copy of this object.
static new EmitConstraint FromProto(RawProto rp)
Parses the parameter from a RawProto.
Specifies the parameters for the ExpansionParameter used with SSD.
static new ExpansionParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
override RawProto ToProto(string strName)
Convert this object to a raw proto.
ExpansionParameter Clone()
Return a clone of the object.
Specifies the parameters for the NoiseParameter used with SSD.
static new NoiseParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
override RawProto ToProto(string strName)
Convert this object to a raw proto.
NoiseParameter Clone()
Return a clone of the object.
Specifies the parameters for the ResizeParameter for use with SSD.
ResizeParameter Clone()
Return a copy of this object.
static new ResizeParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
override RawProto ToProto(string strName)
Convert this object to a raw proto.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
@ NONE
No training category specified.
The MyCaffe.common namespace contains common MyCaffe classes.
Definition: BatchInput.cs:8
@ MUL
Specifies to perform a multiplication operation.
The MyCaffe.param.ssd namespace contains all SSD related parameter objects that correspond to the nat...
The MyCaffe.param namespace contains parameters used to create models.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12