MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
FillerParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.basecode;
7
8namespace MyCaffe.param
9{
13 [Serializable]
14 [TypeConverter(typeof(ExpandableObjectConverter))]
15 public class FillerParameter : BaseParameter, ICloneable
16 {
17 string m_strType;
18 double m_fVal; // The value in constant filler.
19 double m_fMin; // The min value in uniform filler.
20 double m_fMax; // The max value in uniform filler.
21 double m_fMean; // The mean value in Gaussian filler.
22 double m_fStd; // The std value in Gaussian filler.
23
24 // The expected number of non-zero output weights for a given input in
25 // Guassian filler -- the default -1 means don't perform sparsification.
26 int m_nSparse = -1;
27
28 // Normalize the filler variance by fan_in, fan_out, or their average.
29 // Applies to 'xavier' and 'msra' fillers.
30
34 public enum FillerType
35 {
39 CONSTANT,
44 SEQUENCE,
51 UNIFORM,
58 GAUSSIAN,
65 XAVIER,
73 MSRA,
77 POSITIVEUNITBALL,
81 BILINEAR
82 }
83
87 public enum VarianceNorm
88 {
92 FAN_IN = 0,
96 FAN_OUT = 1,
100 AVERAGE = 2
101 }
102 VarianceNorm m_varianceNorm = VarianceNorm.FAN_IN;
103
116 public FillerParameter(string strType = "gaussian", double dfVal = 0.0, double dfMean = 0.0, double dfStd = 1.0)
117 {
118 m_strType = strType;
119 m_fVal = dfVal;
120 m_fMin = 0;
121 m_fMax = 1;
122 m_fMean = dfMean;
123 m_fStd = dfStd;
124 }
125
129 [Description("Specifies the type of filler to use.")]
130 [Browsable(false)]
131 public string type
132 {
133 get { return m_strType; }
134 set { m_strType = value; }
135 }
136
137#pragma warning disable 1591
138
139 [DisplayName("type")]
140 [Description("Specifies the type of filler type to use.")]
141 public FillerType FillerTypeMethod
142 {
143 get
144 {
145 switch (m_strType)
146 {
147 case "constant":
148 return FillerType.CONSTANT;
149
150 case "sequence":
151 return FillerType.SEQUENCE;
152
153 case "uniform":
154 return FillerType.UNIFORM;
155
156 case "gaussian":
157 return FillerType.GAUSSIAN;
158
159 case "xavier":
160 return FillerType.XAVIER;
161
162 case "msra":
163 return FillerType.MSRA;
164
165 case "positive_unitball":
166 return FillerType.POSITIVEUNITBALL;
167
168 case "bilinear":
169 return FillerType.BILINEAR;
170
171 default:
172 throw new Exception("Unknown filler type '" + m_strType + "'");
173 }
174 }
175
176 set { m_strType = FillerParameter.GetFillerName(value); }
177 }
178
179#pragma warning restore 1591
180
186 public static string GetFillerName(FillerType type)
187 {
188 switch (type)
189 {
190 case FillerType.CONSTANT:
191 return "constant";
192
193 case FillerType.SEQUENCE:
194 return "sequence";
195
196 case FillerType.UNIFORM:
197 return "uniform";
198
199 case FillerType.GAUSSIAN:
200 return "gaussian";
201
202 case FillerType.XAVIER:
203 return "xavier";
204
205 case FillerType.MSRA:
206 return "msra";
207
208 case FillerType.POSITIVEUNITBALL:
209 return "positive_unitball";
210
211 case FillerType.BILINEAR:
212 return "bilinear";
213
214 default:
215 throw new Exception("Unknown filler type '" + type.ToString() + "'");
216 }
217 }
218
222 [Description("Specifies the value used by 'constant' filler.")]
223 public double value
224 {
225 get { return m_fVal; }
226 set { m_fVal = value; }
227 }
228
232 [Description("Specifies the minimum value to use with the 'uniform' filler.")]
233 public double min
234 {
235 get { return m_fMin; }
236 set { m_fMin = value; }
237 }
238
242 [Description("Specifies the maximum value to use with the 'uniform' filler.")]
243 public double max
244 {
245 get { return m_fMax; }
246 set { m_fMax = value; }
247 }
248
252 [Description("Specifies the mean value to use with the 'gaussian' filler.")]
253 public double mean
254 {
255 get { return m_fMean; }
256 set { m_fMean = value; }
257 }
258
262 [Description("Specifies the standard deviation value to use with the 'gaussian' filler.")]
263 public double std
264 {
265 get { return m_fStd; }
266 set { m_fStd = value; }
267 }
268
272 [Description("Specifies the sparcity value to use with the 'guassian' filler.")]
273 public int sparse
274 {
275 get { return m_nSparse; }
276 set { m_nSparse = value; }
277 }
278
282 [Description("Specifies the variance normalization method to use with the 'xavier' and 'mrsa' fillers.")]
284 {
285 get { return m_varianceNorm; }
286 set { m_varianceNorm = value; }
287 }
288
294 {
296
297 p.m_strType = m_strType;
298 p.m_fVal = m_fVal;
299 p.m_fMin = m_fMin;
300 p.m_fMax = m_fMax;
301 p.m_fMean = m_fMean;
302 p.m_fStd = m_fStd;
303 p.m_nSparse = m_nSparse;
304 p.m_varianceNorm = m_varianceNorm;
305
306 return p;
307 }
308
314 public override RawProto ToProto(string strName)
315 {
316 RawProtoCollection rgChildren = new RawProtoCollection();
317
318 rgChildren.Add(new RawProto("type", "\"" + type + "\""));
319
320 if (type.ToLower() == "constant")
321 rgChildren.Add(new RawProto("value", value.ToString()));
322
323 if (type.ToLower() == "uniform")
324 {
325 rgChildren.Add(new RawProto("min", min.ToString()));
326 rgChildren.Add(new RawProto("max", max.ToString()));
327 }
328
329 if (type.ToLower() == "gaussian")
330 {
331 rgChildren.Add(new RawProto("mean", mean.ToString()));
332 rgChildren.Add(new RawProto("std", std.ToString()));
333
334 if (sparse != -1)
335 rgChildren.Add(new RawProto("sparse", sparse.ToString()));
336 }
337
338 if (type.ToLower() == "xavier" ||
339 type.ToLower() == "mrsa")
340 rgChildren.Add(new RawProto("variance_norm", variance_norm.ToString()));
341
342 return new RawProto(strName, "", rgChildren);
343 }
344
351 {
352 string strVal;
353
354 if ((strVal = rp.FindValue("type")) == null)
355 throw new Exception("Could not find 'type'");
356
357 FillerParameter p = new FillerParameter(strVal);
358
359 if ((strVal = rp.FindValue("value")) != null)
360 p.value = ParseDouble(strVal);
361
362 if ((strVal = rp.FindValue("min")) != null)
363 p.min = ParseDouble(strVal);
364
365 if ((strVal = rp.FindValue("max")) != null)
366 p.max = ParseDouble(strVal);
367
368 if ((strVal = rp.FindValue("mean")) != null)
369 p.mean = ParseDouble(strVal);
370
371 if ((strVal = rp.FindValue("std")) != null)
372 p.std = ParseDouble(strVal);
373
374 if ((strVal = rp.FindValue("sparse")) != null)
375 p.sparse = int.Parse(strVal);
376
377 if ((strVal = rp.FindValue("variance_norm")) != null)
378 {
379 switch (strVal)
380 {
381 case "FAN_IN":
382 p.variance_norm = VarianceNorm.FAN_IN;
383 break;
384
385 case "FAN_OUT":
386 p.variance_norm = VarianceNorm.FAN_OUT;
387 break;
388
389 case "AVERAGE":
390 p.variance_norm = VarianceNorm.AVERAGE;
391 break;
392
393 default:
394 throw new Exception("Unknown 'variance_norm' value: " + strVal);
395 }
396 }
397
398 return p;
399 }
400
401 object ICloneable.Clone()
402 {
403 return Clone();
404 }
405 }
406}
The BaseParameter class is the base class for all other parameter classes.
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
string FindValue(string strName)
Searches for a falue of a node within this nodes children.
Definition: RawProto.cs:105
Specifies the filler parameters used to create each Filler.
double min
Specifies the minimum value to use with the 'uniform' filler.
double max
Specifies the maximum value to use with the 'uniform' filler.
double value
Specifies the value used by 'constant' filler.
int sparse
Specifies the sparcity value to use with the 'guassian' filler.
VarianceNorm
Defines the variance normalization.
double mean
Specifies the mean value to use with the 'gaussian' filler.
static FillerParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
FillerParameter Clone()
Creates a new copy of this instance of the parameter.
VarianceNorm variance_norm
Specifies the variance normalization method to use with the 'xavier' and 'mrsa' fillers.
string type
Specifies the type of filler to use.
double std
Specifies the standard deviation value to use with the 'gaussian' filler.
static string GetFillerName(FillerType type)
Queries the filler text name corresponding to the FillerType.
FillerType
Defines the type of filler.
FillerParameter(string strType="gaussian", double dfVal=0.0, double dfMean=0.0, double dfStd=1.0)
Filler parameter constructor
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
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