MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
CfcUnitParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.basecode;
7
8namespace MyCaffe.param.lnn
9{
18 [Serializable]
19 [TypeConverter(typeof(ExpandableObjectConverter))]
21 {
22 bool m_bNoGate = false;
23 bool m_bMinimal = false;
24 int m_nInputSize = 0;
25 int m_nHiddenSize = 0;
26 int m_nBackboneUnits = 1;
27 int m_nBackboneLayers = 1;
28 float m_fBackboneDropout = 0.0f;
29 ACTIVATION m_backboneActivation = ACTIVATION.SILU;
30
34 public enum ACTIVATION
35 {
39 SILU,
43 RELU,
47 TANH,
51 GELU,
55 LECUN
56 }
57
60 {
61 }
62
66 [Description("Specifies whether to use the gate or not (when true, the no gate mode is used to calculate the forward output).")]
67 public bool no_gate
68 {
69 get { return m_bNoGate; }
70 set { m_bNoGate = value; }
71 }
72
76 [Description("Specifies whether to use the minimal model or not (when true, the minimal mode is used to calculate the forward output).")]
77 public bool minimal
78 {
79 get { return m_bMinimal; }
80 set { m_bMinimal = value; }
81 }
82
86 [Description("Specifies the input size used to size the backbone units.")]
87 public int input_size
88 {
89 get { return m_nInputSize; }
90 set { m_nInputSize = value; }
91 }
92
96 [Description("Specifies the hidden size used to size the backbone units and other internal layers.")]
97 public int hidden_size
98 {
99 get { return m_nHiddenSize; }
100 set { m_nHiddenSize = value; }
101 }
102
106 [Description("Specifies the number of backbone units.")]
107 public int backbone_units
108 {
109 get { return m_nBackboneUnits; }
110 set { m_nBackboneUnits = value; }
111 }
112
116 [Description("Specifies the number of backbone layers.")]
118 {
119 get { return m_nBackboneLayers; }
120 set { m_nBackboneLayers = value; }
121 }
122
126 [Description("Specifies the backbone dropout ratio.")]
128 {
129 get { return m_fBackboneDropout; }
130 set { m_fBackboneDropout = value; }
131 }
132
136 [Description("Specifies the backbone activation function.")]
138 {
139 get { return m_backboneActivation; }
140 set { m_backboneActivation = value; }
141 }
142
144 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
145 {
146 RawProto proto = RawProto.Parse(br.ReadString());
147 CfcUnitParameter p = FromProto(proto);
148
149 if (!bNewInstance)
150 Copy(p);
151
152 return p;
153 }
154
156 public override void Copy(LayerParameterBase src)
157 {
159
160 m_bNoGate = p.no_gate;
161 m_bMinimal = p.minimal;
162 m_nInputSize = p.input_size;
163 m_nHiddenSize = p.hidden_size;
164 m_nBackboneUnits = p.backbone_units;
165 m_nBackboneLayers = p.backbone_layers;
166 m_fBackboneDropout = p.backbone_dropout_ratio;
167 m_backboneActivation = p.backbone_activation;
168 }
169
171 public override LayerParameterBase Clone()
172 {
174 p.Copy(this);
175 return p;
176 }
177
183 public override RawProto ToProto(string strName)
184 {
185 RawProtoCollection rgChildren = new RawProtoCollection();
186
187 rgChildren.Add("no_gate", no_gate.ToString());
188 rgChildren.Add("minimal", minimal.ToString());
189 rgChildren.Add("input_size", input_size.ToString());
190 rgChildren.Add("hidden_size", hidden_size.ToString());
191 rgChildren.Add("backbone_units", backbone_units.ToString());
192 rgChildren.Add("backbone_layers", backbone_layers.ToString());
193 rgChildren.Add("backbone_dropout_ratio", backbone_dropout_ratio.ToString());
194 rgChildren.Add("backbone_activation", backbone_activation.ToString());
195
196 return new RawProto(strName, "", rgChildren);
197 }
198
205 {
206 string strVal;
208
209 if ((strVal = rp.FindValue("no_gate")) != null)
210 p.no_gate = bool.Parse(strVal);
211
212 if ((strVal = rp.FindValue("minimal")) != null)
213 p.minimal = bool.Parse(strVal);
214
215 if ((strVal = rp.FindValue("input_size")) != null)
216 p.input_size = int.Parse(strVal);
217
218 if ((strVal = rp.FindValue("hidden_size")) != null)
219 p.hidden_size = int.Parse(strVal);
220
221 if ((strVal = rp.FindValue("backbone_units")) != null)
222 p.backbone_units = int.Parse(strVal);
223
224 if ((strVal = rp.FindValue("backbone_layers")) != null)
225 p.backbone_layers = int.Parse(strVal);
226
227 if ((strVal = rp.FindValue("backbone_dropout_ratio")) != null)
229
230 if ((strVal = rp.FindValue("backbone_activation")) != null)
231 p.backbone_activation = (ACTIVATION)Enum.Parse(typeof(ACTIVATION), strVal, true);
232
233 return p;
234 }
235 }
236}
The BaseParameter class is the base class for all other parameter classes.
static float ParseFloat(string strVal)
Parse float values using the US culture if the decimal separator = '.', then using the native culture...
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
string FindValue(string strName)
Searches for a falue of a node within this nodes children.
Definition: RawProto.cs:105
The LayerParameterBase is the base class for all other layer specific parameters.
Specifies the parameters for the CfcUnitLayer used by the CfCLayer.
ACTIVATION
Defines the activation function used by the backbone.
int input_size
Specifies the input size used to size the backbone units.
bool no_gate
Specifies whether to use the gate or not (when true, the no gate mode is used to calculate the forwar...
ACTIVATION backbone_activation
Specifies the backbone activation function.
int hidden_size
Specifies the hidden size used to size the backbone units and other internal layers.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
int backbone_units
Specifies the number of backbone units
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
CfcUnitParameter()
Constructor for the parameter.
bool minimal
Specifies whether to use the minimal model or not (when true, the minimal mode is used to calculate t...
int backbone_layers
Specifies the number of backbone layers.
static CfcUnitParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
float backbone_dropout_ratio
Specifies the backbone dropout ratio.
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