MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
EmbedParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.basecode;
7
8namespace MyCaffe.param
9{
13 [Serializable]
14 [TypeConverter(typeof(ExpandableObjectConverter))]
16 {
17 uint m_nNumOutput;
18 uint m_nInputDim;
19 bool m_bBiasTerm = true;
20 FillerParameter m_fillerParam_weights = new FillerParameter("xavier");
21 FillerParameter m_fillerParam_bias = new FillerParameter("constant", 0.1);
22
25 {
26 }
27
31 [Description("Specifies the number of outputs for the layer.")]
32 public uint num_output
33 {
34 get { return m_nNumOutput; }
35 set { m_nNumOutput = value; }
36 }
37
43 [Description("Specifies the input given as integers to be interpreted as one-hot vector indices with dimension 'num_init'. Hence 'num_input' should be 1 greater than the maximum possible input value.")]
44 public uint input_dim
45 {
46 get { return m_nInputDim; }
47 set { m_nInputDim = value; }
48 }
49
53 [Description("Specifies wheter ot use a bias term or not.")]
54 public bool bias_term
55 {
56 get { return m_bBiasTerm; }
57 set { m_bBiasTerm = value; }
58 }
59
63 [Description("Specifies the filler for the weights.")]
65 {
66 get { return m_fillerParam_weights; }
67 set { m_fillerParam_weights = value; }
68 }
69
73 [Description("Specifies the filler for the bias.")]
75 {
76 get { return m_fillerParam_bias; }
77 set { m_fillerParam_bias = value; }
78 }
79
81 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
82 {
83 RawProto proto = RawProto.Parse(br.ReadString());
84 EmbedParameter p = FromProto(proto);
85
86 if (!bNewInstance)
87 Copy(p);
88
89 return p;
90 }
91
93 public override void Copy(LayerParameterBase src)
94 {
96
97 m_nNumOutput = p.m_nNumOutput;
98 m_nInputDim = p.m_nInputDim;
99 m_bBiasTerm = p.m_bBiasTerm;
100
101 if (p.m_fillerParam_bias != null)
102 m_fillerParam_bias = p.m_fillerParam_bias.Clone();
103
104 if (p.m_fillerParam_weights != null)
105 m_fillerParam_weights = p.m_fillerParam_weights.Clone();
106 }
107
109 public override LayerParameterBase Clone()
110 {
112 p.Copy(this);
113 return p;
114 }
115
121 public override RawProto ToProto(string strName)
122 {
123 RawProtoCollection rgChildren = new RawProtoCollection();
124
125 rgChildren.Add("num_output", num_output.ToString());
126 rgChildren.Add("input_dim", input_dim.ToString());
127
128 if (bias_term != true)
129 rgChildren.Add("bias_term", bias_term.ToString());
130
131 if (weight_filler != null)
132 rgChildren.Add(weight_filler.ToProto("weight_filler"));
133
134 if (bias_term && bias_filler != null)
135 rgChildren.Add(bias_filler.ToProto("bias_filler"));
136
137 return new RawProto(strName, "", rgChildren);
138 }
139
146 {
147 string strVal;
149
150 if ((strVal = rp.FindValue("num_output")) != null)
151 p.num_output = uint.Parse(strVal);
152
153 if ((strVal = rp.FindValue("input_dim")) != null)
154 p.input_dim = uint.Parse(strVal);
155
156 if ((strVal = rp.FindValue("bias_term")) != null)
157 p.bias_term = bool.Parse(strVal);
158
159 RawProto rpWeightFiller = rp.FindChild("weight_filler");
160 if (rpWeightFiller != null)
161 p.weight_filler = FillerParameter.FromProto(rpWeightFiller);
162
163 RawProto rpBiasFiller = rp.FindChild("bias_filler");
164 if (rpBiasFiller != null)
165 p.bias_filler = FillerParameter.FromProto(rpBiasFiller);
166
167 return p;
168 }
169 }
170}
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 parameters used by the EmbedLayer.
uint num_output
Specifies the number of outputs for the layer.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
static EmbedParameter 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 void Copy(LayerParameterBase src)
Copy on parameter to another.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
EmbedParameter()
Constructor for the parameter.
FillerParameter bias_filler
Specifies the filler for the bias.
FillerParameter weight_filler
Specifies the filler for the weights.
uint input_dim
Specifies the input given as integers to be interpreted as one-hot vector indices with dimension num_...
bool bias_term
Specifies whether to use a bias term or not.
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.
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