MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
DataNormalizerParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.basecode;
7
8namespace MyCaffe.param
9{
16 [Serializable]
17 [TypeConverter(typeof(ExpandableObjectConverter))]
19 {
20 bool m_bNormalizeAcrossDataAndLabel = false;
21 List<int> m_rgIgnoreChannels = new List<int>();
22 List<NORMALIZATION_STEP> m_rgNormalizationSteps = new List<NORMALIZATION_STEP>();
23 double m_dfOutputMin = 0;
24 double m_dfOutputMax = 1;
25 double m_dfInputMin = 0;
26 double m_dfInputMax = 0;
27 double? m_dfInputStdDev = null;
28 double? m_dfInputMean = null;
29 int? m_nLabelDataChannel = null;
30
35 {
39 CENTER,
43 STDEV,
47 RANGE,
51 ADDITIVE,
55 RETURNS,
59 LOG
60 }
61
64 {
65 }
66
74 [Description("Specifies to data channel used for the label (if any).")]
76 {
77 get { return m_nLabelDataChannel; }
78 set { m_nLabelDataChannel = value; }
79 }
80
88 [Description("Specifies to normalize across both the data and label data together.")]
90 {
91 get { return m_bNormalizeAcrossDataAndLabel; }
92 set { m_bNormalizeAcrossDataAndLabel = value; }
93 }
94
98 [Description("Specifies the normalization steps which are performed in the order for which they are listed.")]
99 public List<NORMALIZATION_STEP> steps
100 {
101 get { return m_rgNormalizationSteps; }
102 set { m_rgNormalizationSteps = value; }
103 }
104
108 [Description("Specifies the channels to ignore and just pass through in their original form.")]
109 public List<int> ignore_channels
110 {
111 get { return m_rgIgnoreChannels; }
112 set { m_rgIgnoreChannels = value; }
113 }
114
118 [Description("Specifies the minimum data range of the intput, if known. When not specified the input_stdev is determined dynamically from the data input itself.")]
119 public double? input_stdev
120 {
121 get { return m_dfInputStdDev; }
122 set { m_dfInputStdDev = value; }
123 }
124
128 [Description("Specifies the minimum data range of the intput, if known. When not specified the input_mean is determined dynamically from the data input itself.")]
129 public double? input_mean
130 {
131 get { return m_dfInputMean; }
132 set { m_dfInputMean = value; }
133 }
134
138 [Description("Specifies the minimum data range of the intput, if known. If both input_min and input_max are 0 the input_min/input_max are determined dynamically from the data input itself.")]
139 public double input_min
140 {
141 get { return m_dfInputMin; }
142 set { m_dfInputMin = value; }
143 }
144
148 [Description("Specifies the maximum data range of the intput, if known. If both input_min and input_max are 0 the input_min/input_max are determined dynamically from the data input itself.")]
149 public double input_max
150 {
151 get { return m_dfInputMax; }
152 set { m_dfInputMax = value; }
153 }
154
158 [Description("Specifies the minimum data range of the output.")]
159 public double output_min
160 {
161 get { return m_dfOutputMin; }
162 set { m_dfOutputMin = value; }
163 }
164
168 [Description("Specifies the maximum data range of the output.")]
169 public double output_max
170 {
171 get { return m_dfOutputMax; }
172 set { m_dfOutputMax = value; }
173 }
174
176 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
177 {
178 RawProto proto = RawProto.Parse(br.ReadString());
180
181 if (!bNewInstance)
182 Copy(p);
183
184 return p;
185 }
186
188 public override void Copy(LayerParameterBase src)
189 {
191 }
192
194 public override LayerParameterBase Clone()
195 {
197 p.Copy(this);
198 return p;
199 }
200
206 public override RawProto ToProto(string strName)
207 {
208 RawProtoCollection rgChildren = new RawProtoCollection();
209 List<string> rgstrStep = new List<string>();
210
211 for (int i = 0; i < m_rgNormalizationSteps.Count; i++)
212 {
213 rgstrStep.Add(steps[i].ToString().ToLower());
214 }
215
216 rgChildren.Add<string>("step", rgstrStep);
217 rgChildren.Add("across_data_and_label", "\"" + across_data_and_label.ToString() + "\"");
218 rgChildren.Add<int>("ignore_ch", ignore_channels);
219 rgChildren.Add("input_min", input_min.ToString());
220 rgChildren.Add("input_max", input_max.ToString());
221 rgChildren.Add("output_min", output_min.ToString());
222 rgChildren.Add("output_max", output_max.ToString());
223
224 if (input_mean.HasValue)
225 rgChildren.Add("input_mean", input_mean.Value.ToString());
226
227 if (input_stdev.HasValue)
228 rgChildren.Add("input_stdev", input_stdev.Value.ToString());
229
230 if (label_data_channel.HasValue)
231 rgChildren.Add("label_data_channel", label_data_channel.Value.ToString());
232
233 return new RawProto(strName, "", rgChildren);
234 }
235
243 {
244 string strVal;
245
246 if (p == null)
247 p = new DataNormalizerParameter();
248
249 List<string> rgstrStep = rp.FindArray<string>("step");
250 p.steps = new List<NORMALIZATION_STEP>();
251
252 foreach (string strStep in rgstrStep)
253 {
254 p.steps.Add(convertStep(strStep));
255 }
256
257 if ((strVal = rp.FindValue("across_data_and_label")) != null)
258 p.across_data_and_label = bool.Parse(strVal);
259
260 p.ignore_channels = rp.FindArray<int>("ignore_ch");
261
262 if ((strVal = rp.FindValue("input_min")) != null)
263 p.input_min = ParseDouble(strVal);
264
265 if ((strVal = rp.FindValue("input_max")) != null)
266 p.input_max = ParseDouble(strVal);
267
268 if ((strVal = rp.FindValue("output_min")) != null)
269 p.output_min = ParseDouble(strVal);
270
271 if ((strVal = rp.FindValue("output_max")) != null)
272 p.output_max = ParseDouble(strVal);
273
274 if ((strVal = rp.FindValue("input_mean")) != null)
275 p.input_mean = ParseDouble(strVal);
276 else
277 p.input_mean = null;
278
279 if ((strVal = rp.FindValue("input_stdev")) != null)
280 p.input_stdev = ParseDouble(strVal);
281 else
282 p.input_stdev = null;
283
284 if ((strVal = rp.FindValue("label_data_channel")) != null)
285 p.label_data_channel = int.Parse(strVal);
286 else
287 p.label_data_channel = null;
288
289 return p;
290 }
291
292 private static NORMALIZATION_STEP convertStep(string str)
293 {
294 str = str.ToUpper();
295
296 if (str == NORMALIZATION_STEP.ADDITIVE.ToString())
297 return NORMALIZATION_STEP.ADDITIVE;
298
299 if (str == NORMALIZATION_STEP.CENTER.ToString())
300 return NORMALIZATION_STEP.CENTER;
301
302 if (str == NORMALIZATION_STEP.LOG.ToString())
303 return NORMALIZATION_STEP.LOG;
304
305 if (str == NORMALIZATION_STEP.RANGE.ToString())
306 return NORMALIZATION_STEP.RANGE;
307
308 if (str == NORMALIZATION_STEP.RETURNS.ToString())
309 return NORMALIZATION_STEP.RETURNS;
310
311 if (str == NORMALIZATION_STEP.STDEV.ToString())
312 return NORMALIZATION_STEP.STDEV;
313
314 throw new Exception("The step '" + str + "' is unknown!");
315 }
316 }
317}
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
static RawProto Parse(string str)
Parses a prototxt and places it in a new RawProto.
Definition: RawProto.cs:306
Specifies the parameter for the data normalizer layer.
double output_max
Specifies the maximum data range of the output.
double input_max
Specifies the maximum data range of the intput, if known. If both input_min and input_max are 0 the i...
int? label_data_channel
Specifies to data channel used for the label (if any).
bool across_data_and_label
Specifies to normalize across both the data and label data together.
DataNormalizerParameter()
Constructor for the parameter.
double input_min
Specifies the minimum data range of the intput, if known. If both input_min and input_max are 0 the i...
override void Copy(LayerParameterBase src)
Copy on parameter to another.
static DataNormalizerParameter FromProto(RawProto rp, DataNormalizerParameter p=null)
Parses the parameter from a RawProto.
double output_min
Specifies the minimum data range of the output.
List< NORMALIZATION_STEP > steps
Specifies the normalization steps which are performed in the order for which they are listed.
NORMALIZATION_STEP
Specifies the normalization step to run.
List< int > ignore_channels
Specifies the channels to ignore and just pass through in their original form.
double? input_mean
Specifies the input mean, if known. When not specified the input_mean is determined dynamically from ...
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
double? input_stdev
Specifies the input standard deviation, if known. When not specified input_stdev is determined dynami...
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
Specifies the parameter for the data layer.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
The LayerParameterBase is the base class for all other layer specific parameters.
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