MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
GrnParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.basecode;
7using static MyCaffe.param.tft.GluParameter;
8
9namespace MyCaffe.param.tft
10{
25 [Serializable]
26 [TypeConverter(typeof(ExpandableObjectConverter))]
28 {
29 int m_nInputDim;
30 int m_nHiddenDim;
31 int m_nOutputDim;
32 float m_fDropoutRatio = 0.05f;
33 int? m_nContextDim = null;
34 bool m_bBatchFirst = true;
35 FillerParameter m_fillerParam_weights = new FillerParameter("xavier");
36 FillerParameter m_fillerParam_bias = new FillerParameter("constant", 0.1);
37 int m_nAxis = 1;
38 ACTIVATION m_activaiton = ACTIVATION.ELU;
39
43 public enum ACTIVATION
44 {
48 ELU,
49
53 RELU
54 }
55
57 public GrnParameter()
58 {
59 }
60
64 [Description("Specifies the activation type to use (default=ELU)")]
66 {
67 get { return m_activaiton; }
68 set { m_activaiton = value; }
69 }
70
74 [Description("Specifies the input dimension.")]
75 public int input_dim
76 {
77 get { return m_nInputDim; }
78 set { m_nInputDim = value; }
79 }
80
84 [Description("Specifies the hidden dimension.")]
85 public int hidden_dim
86 {
87 get { return m_nHiddenDim; }
88 set { m_nHiddenDim = value; }
89 }
90
94 [Description("Specifies the output dimension.")]
95 public int output_dim
96 {
97 get { return m_nOutputDim; }
98 set { m_nOutputDim = value; }
99 }
100
104 [Description("Specifies the context dimension, or null to ignore.")]
105 public int? context_dim
106 {
107 get { return m_nContextDim; }
108 set { m_nContextDim = value; }
109 }
110
114 [Description("Specifies the dropout ratio (default = 0.05 or 5%).")]
115 public float dropout_ratio
116 {
117 get { return m_fDropoutRatio; }
118 set { m_fDropoutRatio = value; }
119 }
120
124 [Description("Specifies the batch_first setting.")]
125 public bool batch_first
126 {
127 get { return m_bBatchFirst; }
128 set { m_bBatchFirst = value; }
129 }
130
134 [Category("Fillers")]
135 [Description("The filler for the weights.")]
137 {
138 get { return m_fillerParam_weights; }
139 set { m_fillerParam_weights = value; }
140 }
141
145 [Category("Fillers")]
146 [Description("The filler for the bias.")]
148 {
149 get { return m_fillerParam_bias; }
150 set { m_fillerParam_bias = value; }
151 }
152
158 [Description("Specifies the first axis to be lumped into a single inner product computation; all preceding axes are retained in the output.")]
159 public int axis
160 {
161 get { return m_nAxis; }
162 set { m_nAxis = value; }
163 }
164
166 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
167 {
168 RawProto proto = RawProto.Parse(br.ReadString());
169 GrnParameter p = FromProto(proto);
170
171 if (!bNewInstance)
172 Copy(p);
173
174 return p;
175 }
176
178 public override void Copy(LayerParameterBase src)
179 {
180 GrnParameter p = (GrnParameter)src;
181
182 m_nInputDim = p.input_dim;
183 m_nHiddenDim = p.hidden_dim;
184 m_nOutputDim = p.output_dim;
185 m_nContextDim = p.context_dim;
186 m_fDropoutRatio = p.dropout_ratio;
187 m_bBatchFirst = p.batch_first;
188 m_nAxis = p.m_nAxis;
189 m_activaiton = p.activation;
190
191 if (p.m_fillerParam_bias != null)
192 m_fillerParam_bias = p.m_fillerParam_bias.Clone();
193
194 if (p.m_fillerParam_weights != null)
195 m_fillerParam_weights = p.m_fillerParam_weights.Clone();
196 }
197
199 public override LayerParameterBase Clone()
200 {
201 GrnParameter p = new GrnParameter();
202 p.Copy(this);
203 return p;
204 }
205
211 public override RawProto ToProto(string strName)
212 {
213 RawProtoCollection rgChildren = new RawProtoCollection();
214
215 rgChildren.Add("input_dim", input_dim.ToString());
216 rgChildren.Add("hidden_dim", hidden_dim.ToString());
217 rgChildren.Add("output_dim", output_dim.ToString());
218 if (context_dim.HasValue)
219 rgChildren.Add("context_dim", context_dim.Value.ToString());
220 rgChildren.Add("dropout_ratio", dropout_ratio.ToString());
221 rgChildren.Add("batch_first", batch_first.ToString());
222
223 if (weight_filler != null)
224 rgChildren.Add(weight_filler.ToProto("weight_filler"));
225
226 if (bias_filler != null)
227 rgChildren.Add(bias_filler.ToProto("bias_filler"));
228
229 rgChildren.Add("axis", axis.ToString());
230 rgChildren.Add("activation", activation.ToString());
231
232 return new RawProto(strName, "", rgChildren);
233 }
234
241 {
242 string strVal;
243 GrnParameter p = new GrnParameter();
244
245 if ((strVal = rp.FindValue("input_dim")) != null)
246 p.input_dim = int.Parse(strVal);
247
248 if ((strVal = rp.FindValue("hidden_dim")) != null)
249 p.hidden_dim = int.Parse(strVal);
250
251 if ((strVal = rp.FindValue("output_dim")) != null)
252 p.output_dim = int.Parse(strVal);
253
254 if ((strVal = rp.FindValue("context_dim")) != null)
255 p.context_dim = int.Parse(strVal);
256
257 if ((strVal = rp.FindValue("dropout_ratio")) != null)
258 p.dropout_ratio = float.Parse(strVal);
259
260 if ((strVal = rp.FindValue("batch_first")) != null)
261 p.batch_first = 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("activation")) != null)
275 {
276 if (strVal == ACTIVATION.RELU.ToString())
277 p.activation = ACTIVATION.RELU;
278 else
279 p.activation = ACTIVATION.ELU;
280 }
281
282 return p;
283 }
284 }
285}
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
Specifies the parameters for the GrnLayer (Gated Response Network).
Definition: GrnParameter.cs:28
int? context_dim
Specifies the context dimension, or null to ignore.
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
FillerParameter weight_filler
The filler for the weights.
int output_dim
Specifies the output dimension.
Definition: GrnParameter.cs:96
bool batch_first
Specifies the batch_first setting.
static GrnParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
int input_dim
Specifies the input dimension.
Definition: GrnParameter.cs:76
ACTIVATION
Defines the activation type.
Definition: GrnParameter.cs:44
FillerParameter bias_filler
The filler for the bias.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
float dropout_ratio
Specifies the dropout ratio (default = 0.05 or 5%).
int hidden_dim
Specifies the input dimension.
Definition: GrnParameter.cs:86
ACTIVATION activation
Specifies the activation type to use (default=ELU)
Definition: GrnParameter.cs:66
int axis
Specifies the first axis to be lumped into a single inner product computation; all preceding axes are...
GrnParameter()
Constructor for the parameter.
Definition: GrnParameter.cs:57
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