MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
InnerProductParameter.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 uint m_nNumOutput = 0;
21 bool m_bBiasTerm = true;
22 FillerParameter m_fillerParam_weights = new FillerParameter("xavier");
23 FillerParameter m_fillerParam_bias = new FillerParameter("constant", 0.1);
24 int m_nAxis = 1;
25 int m_nMinTopAxes = -1;
26 bool m_bTranspose = false;
27 bool m_bEnableNoise = false;
28 double m_dfSigmaInit = 0.017;
29 double m_dfBiasGradScale = 1.0;
30 bool m_bOutputContainsPredictions = false;
31
34 {
35 }
36
40 [Description("Specifies that the output contains predictions and that the output blob is marked as BLOB_TYPE.PREDICTION.")]
42 {
43 get { return m_bOutputContainsPredictions; }
44 set { m_bOutputContainsPredictions = value; }
45 }
46
50 [Description("Specifies a scaling value applied to the bias mutliplier and then unapplied after calculating the bias - used to help improve float accuracy (default = 1.0). A value of 1.0 is ignored.")]
51 public double bias_grad_scale
52 {
53 get { return m_dfBiasGradScale; }
54 set { m_dfBiasGradScale = value;}
55 }
56
63 [Description("Enable/disable noise in the inner-product layer (default = false).")]
64 public bool enable_noise
65 {
66 get { return m_bEnableNoise; }
67 set { m_bEnableNoise = value; }
68 }
69
73 [Description("Specifies the initialization value for the sigma weight and sigma bias used when 'enable_noise' = true.")]
74 public double sigma_init
75 {
76 get { return m_dfSigmaInit; }
77 set { m_dfSigmaInit = value; }
78 }
79
83 [Description("The number of outputs for the layer.")]
84 public uint num_output
85 {
86 get { return m_nNumOutput; }
87 set { m_nNumOutput = value; }
88 }
89
96 [Description("Optionally, specifies the minimum top axes (default = -1, which ignores this setting). NOTE: Deconvolution requies 'min_top_axes' = 4.")]
97 public int min_top_axes
98 {
99 get { return m_nMinTopAxes; }
100 set { m_nMinTopAxes = value; }
101 }
102
106 [Description("Whether to have bias terms or not.")]
107 public bool bias_term
108 {
109 get { return m_bBiasTerm; }
110 set { m_bBiasTerm = value; }
111 }
112
116 [Category("Fillers")]
117 [Description("The filler for the weights.")]
119 {
120 get { return m_fillerParam_weights; }
121 set { m_fillerParam_weights = value; }
122 }
123
127 [Category("Fillers")]
128 [Description("The filler for the bias.")]
130 {
131 get { return m_fillerParam_bias; }
132 set { m_fillerParam_bias = value; }
133 }
134
140 [Description("Specifies the first axis to be lumped into a single inner product computation; all preceding axes are retained in the output.")]
141 public int axis
142 {
143 get { return m_nAxis; }
144 set { m_nAxis = value; }
145 }
146
153 [Description("Specifies whether to transpose the weight matrix or not.")]
154 public bool transpose
155 {
156 get { return m_bTranspose; }
157 set { m_bTranspose = value; }
158 }
159
161 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
162 {
163 RawProto proto = RawProto.Parse(br.ReadString());
165
166 if (!bNewInstance)
167 Copy(p);
168
169 return p;
170 }
171
173 public override void Copy(LayerParameterBase src)
174 {
176
177 m_nNumOutput = p.m_nNumOutput;
178 m_bBiasTerm = p.m_bBiasTerm;
179
180 if (p.m_fillerParam_bias != null)
181 m_fillerParam_bias = p.m_fillerParam_bias.Clone();
182
183 if (p.m_fillerParam_weights != null)
184 m_fillerParam_weights = p.m_fillerParam_weights.Clone();
185
186 m_nAxis = p.m_nAxis;
187 m_bTranspose = p.m_bTranspose;
188 m_nMinTopAxes = p.m_nMinTopAxes;
189 m_bEnableNoise = p.m_bEnableNoise;
190 m_dfSigmaInit = p.m_dfSigmaInit;
191 m_dfBiasGradScale = p.m_dfBiasGradScale;
192 m_bOutputContainsPredictions = p.m_bOutputContainsPredictions;
193 }
194
196 public override LayerParameterBase Clone()
197 {
199 p.Copy(this);
200 return p;
201 }
202
208 public override RawProto ToProto(string strName)
209 {
210 RawProtoCollection rgChildren = new RawProtoCollection();
211
213 rgChildren.Add("output_contains_predictions", output_contains_predictions.ToString());
214
215 rgChildren.Add("num_output", num_output.ToString());
216 rgChildren.Add("bias_term", bias_term.ToString());
217
218 if (weight_filler != null)
219 rgChildren.Add(weight_filler.ToProto("weight_filler"));
220
221 if (bias_filler != null)
222 rgChildren.Add(bias_filler.ToProto("bias_filler"));
223
224 rgChildren.Add("axis", axis.ToString());
225
226 if (transpose != false)
227 rgChildren.Add("transpose", transpose.ToString());
228
229 if (min_top_axes != -1)
230 rgChildren.Add("min_top_axes", min_top_axes.ToString());
231
232 if (m_bEnableNoise)
233 {
234 rgChildren.Add("enable_noise", m_bEnableNoise.ToString());
235 rgChildren.Add("sigma_init", m_dfSigmaInit.ToString());
236 }
237
238 if (bias_grad_scale != 1.0)
239 rgChildren.Add("bias_grad_scale", m_dfBiasGradScale.ToString());
240
241 return new RawProto(strName, "", rgChildren);
242 }
243
250 {
251 string strVal;
253
254 if ((strVal = rp.FindValue("output_contains_predictions")) != null)
255 p.output_contains_predictions = bool.Parse(strVal);
256
257 if ((strVal = rp.FindValue("num_output")) != null)
258 p.num_output = uint.Parse(strVal);
259
260 if ((strVal = rp.FindValue("bias_term")) != null)
261 p.bias_term = bool.Parse(strVal);
262
263 RawProto rpWeightFiller = rp.FindChild("weight_filler");
264 if (rpWeightFiller != null)
265 p.weight_filler = FillerParameter.FromProto(rpWeightFiller);
266
267 RawProto rpBiasFiller = rp.FindChild("bias_filler");
268 if (rpBiasFiller != null)
269 p.bias_filler = FillerParameter.FromProto(rpBiasFiller);
270
271 if ((strVal = rp.FindValue("axis")) != null)
272 p.axis = int.Parse(strVal);
273
274 if ((strVal = rp.FindValue("transpose")) != null)
275 p.transpose = bool.Parse(strVal);
276
277 if ((strVal = rp.FindValue("min_top_axes")) != null)
278 p.min_top_axes = int.Parse(strVal);
279
280 if ((strVal = rp.FindValue("enable_noise")) != null)
281 p.enable_noise = bool.Parse(strVal);
282
283 if ((strVal = rp.FindValue("sigma_init")) != null)
284 p.sigma_init = ParseDouble(strVal);
285
286 if ((strVal = rp.FindValue("bias_grad_scale")) != null)
287 p.bias_grad_scale = ParseDouble(strVal);
288
289 return p;
290 }
291 }
292}
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
Specifies the filler parameters used to create each 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.
Specifies the parameters for the InnerProductLayer.
double sigma_init
Specifies the initialization value for the sigma weight and sigma bias used when 'enable_noise' = tru...
FillerParameter weight_filler
The filler for the weights.
int axis
Specifies the first axis to be lumped into a single inner product computation; all preceding axes are...
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
bool enable_noise
Enable/disable noise in the inner-product layer (default = false).
double bias_grad_scale
Specifies a scaling value applied to the bias mutliplier and then unapplied after calculating the bia...
int min_top_axes
Optionally, specifies the minimum top axes (default = -1, which ignores this setting).
bool transpose
Specifies whether to transpose the weight matrix or not. If transpose == true, any operations will be...
FillerParameter bias_filler
The filler for the bias.
uint num_output
The number of outputs for the layer.
InnerProductParameter()
Constructor for the parameter.
bool output_contains_predictions
Specifies that the output contains predictions and that the output blob is marked as BLOB_TYPE....
override void Copy(LayerParameterBase src)
Copy on parameter to another.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
bool bias_term
Whether to have bias terms or not.
static InnerProductParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
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