MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
LSTMSimpleParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.basecode;
7
8namespace MyCaffe.param
9{
23 [Serializable]
24 [TypeConverter(typeof(ExpandableObjectConverter))]
26 {
27 uint m_nNumOutput;
28 double m_dfClippingThreshold = 0;
29 FillerParameter m_fillerWeights = new FillerParameter("xavier");
30 FillerParameter m_fillerBias = new FillerParameter("constant", 0.1);
31 uint m_nBatchSize = 1;
32 bool m_bEnableClockworkForgetGateBias = false;
33
36 {
37 }
38
42 [Description("Specifies the number of outputs for the layer.")]
43 public uint num_output
44 {
45 get { return m_nNumOutput; }
46 set { m_nNumOutput = value; }
47 }
48
52 [Description("Specifies the gradient clipping threshold, default = 0.0 (i.e. no clipping).")]
53 public double clipping_threshold
54 {
55 get { return m_dfClippingThreshold; }
56 set { m_dfClippingThreshold = value; }
57 }
58
62 [Description("Specifies the filler parameters for the weight filler.")]
63 [TypeConverter(typeof(ExpandableObjectConverter))]
65 {
66 get { return m_fillerWeights; }
67 set { m_fillerWeights = value; }
68 }
69
73 [Description("Specifies the filler parameters for the bias filler.")]
74 [TypeConverter(typeof(ExpandableObjectConverter))]
76 {
77 get { return m_fillerBias; }
78 set { m_fillerBias = value; }
79 }
80
84 [Description("Specifies the batch size, default = 1.")]
85 public uint batch_size
86 {
87 get { return m_nBatchSize; }
88 set { m_nBatchSize = value; }
89 }
90
97 [Description("When true, the forget gate bias is set to 5.0 as recommended by [1] Koutnik, J., Greff, K., Gomez, F., Schmidhuber, J., 'A Clockwork RNN', 2014")]
99 {
100 get { return m_bEnableClockworkForgetGateBias; }
101 set { m_bEnableClockworkForgetGateBias = value; }
102 }
103
105 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
106 {
107 RawProto proto = RawProto.Parse(br.ReadString());
109
110 if (!bNewInstance)
111 Copy(p);
112
113 return p;
114 }
115
117 public override void Copy(LayerParameterBase src)
118 {
120
121 m_nNumOutput = p.m_nNumOutput;
122 m_dfClippingThreshold = p.m_dfClippingThreshold;
123 m_fillerWeights = p.m_fillerWeights.Clone();
124 m_fillerBias = p.m_fillerBias.Clone();
125 m_nBatchSize = p.m_nBatchSize;
126 }
127
129 public override LayerParameterBase Clone()
130 {
132 p.Copy(this);
133 return p;
134 }
135
141 public override RawProto ToProto(string strName)
142 {
143 RawProtoCollection rgChildren = new RawProtoCollection();
144
145 rgChildren.Add("num_output", m_nNumOutput.ToString());
146
147 if (m_dfClippingThreshold != 0)
148 rgChildren.Add("clipping_threshold", m_dfClippingThreshold.ToString());
149
150 rgChildren.Add(m_fillerWeights.ToProto("weight_filler"));
151 rgChildren.Add(m_fillerBias.ToProto("bias_filler"));
152
153 if (m_nBatchSize != 1)
154 rgChildren.Add("batch_size", m_nBatchSize.ToString());
155
156 if (m_bEnableClockworkForgetGateBias != false)
157 rgChildren.Add("enable_clockwork_forgetgate_bias", m_bEnableClockworkForgetGateBias.ToString());
158
159 return new RawProto(strName, "", rgChildren);
160 }
161
168 {
169 string strVal;
171
172 if ((strVal = rp.FindValue("num_output")) != null)
173 p.num_output = uint.Parse(strVal);
174
175 if ((strVal = rp.FindValue("clipping_threshold")) != null)
177
178 RawProto rpWeightFiller = rp.FindChild("weight_filler");
179 if (rpWeightFiller != null)
180 p.weight_filler = FillerParameter.FromProto(rpWeightFiller);
181
182 RawProto rpBiasFiller = rp.FindChild("bias_filler");
183 if (rpBiasFiller != null)
184 p.bias_filler = FillerParameter.FromProto(rpBiasFiller);
185
186 if ((strVal = rp.FindValue("batch_size")) != null)
187 p.batch_size = uint.Parse(strVal);
188
189 if ((strVal = rp.FindValue("enable_clockwork_forgetgate_bias")) != null)
190 p.enable_clockwork_forgetgate_bias = bool.Parse(strVal);
191
192 return p;
193 }
194 }
195}
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.
[DEPRECIATED - use LSTMAttentionParameter instead with enable_attention = false] Specifies the parame...
LSTMSimpleParameter()
Constructor for the parameter.
double clipping_threshold
Specifies the gradient clipping threshold, default = 0.0 (i.e. no clipping).
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
FillerParameter weight_filler
Specifies the filler parameters for the weight filler.
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.
static LSTMSimpleParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
uint num_output
Specifies the number of outputs for the layer.
FillerParameter bias_filler
Specifies the filler parameters for the bias filler.
uint batch_size
Specifies the batch size, default = 1.
bool enable_clockwork_forgetgate_bias
When enabled, the forget gate bias is set to 5.0.
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