MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
DistortionParameter.cs
1using System;
2using System.Collections.Generic;
4using System.IO;
5using System.Linq;
6using System.Text;
7using System.Threading.Tasks;
8using MyCaffe.basecode;
9
10namespace MyCaffe.param.ssd
11{
19 [Serializable]
20 [TypeConverter(typeof(ExpandableObjectConverter))]
22 {
23 float m_fBrightnessProb = 0;
24 float m_fBrightnessDelta = 0.0f;
25
26 float m_fContrastProb = 0;
27 float m_fContrastLower = 0.5f;
28 float m_fContrastUpper = 1.5f;
29
30 float m_fSaturationProb = 0;
31 float m_fSaturationLower = 0.5f;
32 float m_fSaturationUpper = 1.5f;
33
34 float m_fRandomOrderProb = 0;
35
36 long m_lRandomSeed = 0;
37 bool m_bUseGpu = true;
38
43 public DistortionParameter(bool bActive) : base(bActive)
44 {
45 }
46
51 public long random_seed
52 {
53 get { return m_lRandomSeed; }
54 set { m_lRandomSeed = value; }
55 }
56
60 public bool use_gpu
61 {
62 get { return m_bUseGpu; }
63 set { m_bUseGpu = value; }
64 }
65
69 [Description("Get/set probability of adjusting the brightness.")]
70 public float brightness_prob
71 {
72 get { return m_fBrightnessProb; }
73 set { m_fBrightnessProb = value; }
74 }
75
79 [Description("Get/set amount to add to the pixel values within [-delta,delta]")]
80 public float brightness_delta
81 {
82 get { return m_fBrightnessDelta; }
83 set { m_fBrightnessDelta = value; }
84 }
85
89 [Description("Get/set probability of adjusting the contrast.")]
90 public float contrast_prob
91 {
92 get { return m_fContrastProb; }
93 set { m_fContrastProb = value; }
94 }
95
99 [Description("Get/set lower bound for random contrast factor.")]
100 public float contrast_lower
101 {
102 get { return m_fContrastLower; }
103 set { m_fContrastLower = value; }
104 }
105
109 [Description("Get/set upper bound for random contrast factor.")]
110 public float contrast_upper
111 {
112 get { return m_fContrastUpper; }
113 set { m_fContrastUpper = value; }
114 }
115
119 [Description("Get/set probability of adjusting the saturation.")]
120 public float saturation_prob
121 {
122 get { return m_fSaturationProb; }
123 set { m_fSaturationProb = value; }
124 }
125
129 [Description("Get/set lower bound for random saturation factor.")]
130 public float saturation_lower
131 {
132 get { return m_fSaturationLower; }
133 set { m_fSaturationLower = value; }
134 }
135
139 [Description("Get/set upper bound for random saturation factor.")]
140 public float saturation_upper
141 {
142 get { return m_fSaturationUpper; }
143 set { m_fSaturationUpper = value; }
144 }
145
149 [Description("Get/set the probability of randomly ordering the image channels.")]
150 public float random_order_prob
151 {
152 get { return m_fRandomOrderProb; }
153 set { m_fRandomOrderProb = value; }
154 }
155
160 public override void Copy(OptionalParameter src)
161 {
162 base.Copy(src);
163
164 if (src is DistortionParameter)
165 {
167 m_fBrightnessProb = p.brightness_prob;
168 m_fBrightnessDelta = p.brightness_delta;
169
170 m_fContrastProb = p.contrast_prob;
171 m_fContrastLower = p.contrast_lower;
172 m_fContrastUpper = p.contrast_upper;
173
174 m_fSaturationProb = p.saturation_prob;
175 m_fSaturationLower = p.saturation_lower;
176 m_fSaturationUpper = p.saturation_upper;
177
178 m_fRandomOrderProb = p.random_order_prob;
179
180 m_lRandomSeed = p.m_lRandomSeed;
181 m_bUseGpu = p.use_gpu;
182 }
183 }
184
190 {
192 p.Copy(this);
193 return p;
194 }
195
201 public override RawProto ToProto(string strName)
202 {
203 RawProto rpBase = base.ToProto("option");
204 RawProtoCollection rgChildren = new RawProtoCollection();
205
206 rgChildren.Add(rpBase);
207 rgChildren.Add(new RawProto("active", Active.ToString()));
208 rgChildren.Add(new RawProto("brightness_prob", brightness_prob.ToString()));
209 rgChildren.Add(new RawProto("brightness_delta", brightness_delta.ToString()));
210 rgChildren.Add(new RawProto("contrast_prob", contrast_prob.ToString()));
211 rgChildren.Add(new RawProto("contrast_lower", contrast_lower.ToString()));
212 rgChildren.Add(new RawProto("contrast_upper", contrast_upper.ToString()));
213 rgChildren.Add(new RawProto("saturation_prob", saturation_prob.ToString()));
214 rgChildren.Add(new RawProto("saturation_lower", saturation_lower.ToString()));
215 rgChildren.Add(new RawProto("saturation_upper", saturation_upper.ToString()));
216 rgChildren.Add(new RawProto("random_order_prob", random_order_prob.ToString()));
217 rgChildren.Add(new RawProto("use_gpu", use_gpu.ToString()));
218 rgChildren.Add(new RawProto("random_seed", random_seed.ToString()));
219
220 return new RawProto(strName, "", rgChildren);
221 }
222
229 {
231 string strVal;
232
233 RawProto rpOption = rp.FindChild("option");
234 if (rpOption != null)
235 ((OptionalParameter)p).Copy(OptionalParameter.FromProto(rpOption));
236
237 if ((strVal = rp.FindValue("active")) != null)
238 p.Active = bool.Parse(strVal);
239
240 if ((strVal = rp.FindValue("brightness_prob")) != null)
242
243 if ((strVal = rp.FindValue("brightness_delta")) != null)
245
246 if ((strVal = rp.FindValue("contrast_prob")) != null)
248
249 if ((strVal = rp.FindValue("contrast_lower")) != null)
251
252 if ((strVal = rp.FindValue("contrast_upper")) != null)
254
255 if ((strVal = rp.FindValue("saturation_prob")) != null)
257
258 if ((strVal = rp.FindValue("saturation_lower")) != null)
260
261 if ((strVal = rp.FindValue("saturation_upper")) != null)
263
264 if ((strVal = rp.FindValue("random_order_prob")) != null)
266
267 if ((strVal = rp.FindValue("use_gpu")) != null)
268 p.use_gpu = bool.Parse(strVal);
269
270 if ((strVal = rp.FindValue("random_seed")) != null)
271 p.random_seed = long.Parse(strVal);
272
273 return p;
274 }
275 }
276}
The BaseParameter class is the base class for all other parameter classes.
static float ParseFloat(string strVal)
Parse float values using the US culture if the decimal separator = '.', then using the native culture...
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
string FindValue(string strName)
Searches for a falue of a node within this nodes children.
Definition: RawProto.cs:105
The OptionalParameter is the base class for parameters that are optional such as the MaskParameter,...
static OptionalParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
OptionalParameter(bool bActive=false)
The constructor.
bool Active
When active, the parameter is used, otherwise it is ignored.
Specifies the parameters for the DistortionParameter used with SSD.
float contrast_lower
Get/set lower bound for random contrast factor (default = 0.5).
float random_order_prob
Get/set the probability of randomly ordering the image channels (default = 0).
override void Copy(OptionalParameter src)
Copy the object.
float brightness_delta
Get/set amount to add to the pixel values within [-delta,delta] (default = 0)
float saturation_prob
Get/set probability of adjusting the saturation (default = 0).
float saturation_lower
Get/set lower bound for random saturation factor (default = 0.5).
override RawProto ToProto(string strName)
Convert this object to a raw proto.
DistortionParameter(bool bActive)
The constructor.
bool use_gpu
Get/set whether or not to use the GPU for the distortion operations (default = true).
static new DistortionParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
long random_seed
Get/set the random seed (default = 0, only used when testing).
float saturation_upper
Get/set upper bound for random saturation factor (default = 1.5).
float brightness_prob
Get/set probability of adjusting the brightness (default = 0).
float contrast_prob
Get/set probability of adjusting the contrast (default = 0).
DistortionParameter Clone()
Return a clone of the object.
float contrast_upper
Get/set upper bound for random contrast factor (default = 1.5).
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe.param.ssd namespace contains all SSD related parameter objects that correspond to the nat...
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12