MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
GluParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.basecode;
7
8namespace MyCaffe.param.tft
9{
25 [Serializable]
26 [TypeConverter(typeof(ExpandableObjectConverter))]
28 {
29 FillerParameter m_fillerParam_weights = new FillerParameter("xavier");
30 FillerParameter m_fillerParam_bias = new FillerParameter("constant", 0.1);
31 int m_nAxis = 1;
32 int m_nInputDim;
33 bool m_bBiasTerm = true;
34 bool m_bEnableNoise = false;
35 double m_dfSigmaInit = 0.017;
36 MODULATION m_modulation = MODULATION.SIGMOID;
37
41 public enum MODULATION
42 {
46 SIGMOID
47 }
48
50 public GluParameter()
51 {
52 }
53
57 [Description("Specifies the input dimension.")]
58 public int input_dim
59 {
60 get { return m_nInputDim; }
61 set { m_nInputDim = value; }
62 }
63
67 [Description("Specifies the gate modulation type.")]
69 {
70 get { return m_modulation; }
71 set { m_modulation = value; }
72 }
73
80 [Description("Enable/disable noise in the inner-product layer (default = false).")]
81 public bool enable_noise
82 {
83 get { return m_bEnableNoise; }
84 set { m_bEnableNoise = value; }
85 }
86
90 [Description("Specifies the initialization value for the sigma weight and sigma bias used when 'enable_noise' = true.")]
91 public double sigma_init
92 {
93 get { return m_dfSigmaInit; }
94 set { m_dfSigmaInit = value; }
95 }
96
100 [Description("Whether to have bias terms or not.")]
101 public bool bias_term
102 {
103 get { return m_bBiasTerm; }
104 set { m_bBiasTerm = value; }
105 }
106
110 [Category("Fillers")]
111 [Description("The filler for the weights.")]
113 {
114 get { return m_fillerParam_weights; }
115 set { m_fillerParam_weights = value; }
116 }
117
121 [Category("Fillers")]
122 [Description("The filler for the bias.")]
124 {
125 get { return m_fillerParam_bias; }
126 set { m_fillerParam_bias = value; }
127 }
128
134 [Description("Specifies the first axis to be lumped into a single inner product computation; all preceding axes are retained in the output.")]
135 public int axis
136 {
137 get { return m_nAxis; }
138 set { m_nAxis = value; }
139 }
140
141
143 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
144 {
145 RawProto proto = RawProto.Parse(br.ReadString());
146 GluParameter p = FromProto(proto);
147
148 if (!bNewInstance)
149 Copy(p);
150
151 return p;
152 }
153
155 public override void Copy(LayerParameterBase src)
156 {
157 GluParameter p = (GluParameter)src;
158
159 m_modulation = p.modulation;
160 m_nInputDim = p.input_dim;
161 m_bBiasTerm = p.m_bBiasTerm;
162
163 if (p.m_fillerParam_bias != null)
164 m_fillerParam_bias = p.m_fillerParam_bias.Clone();
165
166 if (p.m_fillerParam_weights != null)
167 m_fillerParam_weights = p.m_fillerParam_weights.Clone();
168
169 m_nAxis = p.m_nAxis;
170 m_bEnableNoise = p.m_bEnableNoise;
171 m_dfSigmaInit = p.m_dfSigmaInit;
172 }
173
175 public override LayerParameterBase Clone()
176 {
177 GluParameter p = new GluParameter();
178 p.Copy(this);
179 return p;
180 }
181
187 public override RawProto ToProto(string strName)
188 {
189 RawProtoCollection rgChildren = new RawProtoCollection();
190
191 rgChildren.Add("modulation", modulation.ToString());
192 rgChildren.Add("input_dim", input_dim.ToString());
193 rgChildren.Add("bias_term", bias_term.ToString());
194
195 if (weight_filler != null)
196 rgChildren.Add(weight_filler.ToProto("weight_filler"));
197
198 if (bias_filler != null)
199 rgChildren.Add(bias_filler.ToProto("bias_filler"));
200
201 rgChildren.Add("axis", axis.ToString());
202
203 if (m_bEnableNoise)
204 {
205 rgChildren.Add("enable_noise", m_bEnableNoise.ToString());
206 rgChildren.Add("sigma_init", m_dfSigmaInit.ToString());
207 }
208
209 return new RawProto(strName, "", rgChildren);
210 }
211
218 {
219 string strVal;
220 GluParameter p = new GluParameter();
221
222 if ((strVal = rp.FindValue("input_dim")) != null)
223 p.input_dim = int.Parse(strVal);
224
225 if ((strVal = rp.FindValue("modulation")) != null)
226 {
227 if (strVal == MODULATION.SIGMOID.ToString())
228 p.modulation = MODULATION.SIGMOID;
229 }
230
231 if ((strVal = rp.FindValue("bias_term")) != null)
232 p.bias_term = bool.Parse(strVal);
233
234 RawProto rpWeightFiller = rp.FindChild("weight_filler");
235 if (rpWeightFiller != null)
236 p.weight_filler = FillerParameter.FromProto(rpWeightFiller);
237
238 RawProto rpBiasFiller = rp.FindChild("bias_filler");
239 if (rpBiasFiller != null)
240 p.bias_filler = FillerParameter.FromProto(rpBiasFiller);
241
242 if ((strVal = rp.FindValue("axis")) != null)
243 p.axis = int.Parse(strVal);
244
245 if ((strVal = rp.FindValue("enable_noise")) != null)
246 p.enable_noise = bool.Parse(strVal);
247
248 if ((strVal = rp.FindValue("sigma_init")) != null)
249 p.sigma_init = ParseDouble(strVal);
250
251 return p;
252 }
253 }
254}
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.
The LayerParameterBase is the base class for all other layer specific parameters.
Specifies the parameters for the GluLayer (Gated Linear Unit).
Definition: GluParameter.cs:28
MODULATION modulation
Specifies the gate modulation type.
Definition: GluParameter.cs:69
FillerParameter bias_filler
The filler for the bias.
int input_dim
Specifies the input dimension.
Definition: GluParameter.cs:59
static GluParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
bool enable_noise
Enable/disable noise in the inner-product layer (default = false).
Definition: GluParameter.cs:82
int axis
Specifies the first axis to be lumped into a single inner product computation; all preceding axes are...
double sigma_init
Specifies the initialization value for the sigma weight and sigma bias used when 'enable_noise' = tru...
Definition: GluParameter.cs:92
bool bias_term
Whether to have bias terms or not.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
GluParameter()
Constructor for the parameter.
Definition: GluParameter.cs:50
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
FillerParameter weight_filler
The filler for the weights.
MODULATION
Defines the modulation type.
Definition: GluParameter.cs:42
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12