MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
AttentionParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.basecode;
7
8namespace MyCaffe.param
9{
15 [Serializable]
16 [TypeConverter(typeof(ExpandableObjectConverter))]
18 {
19 int m_nAxis = 2;
20 uint m_nDim = 1;
21 FillerParameter m_fillerParam_weights = new FillerParameter("xavier");
22 FillerParameter m_fillerParam_bias = new FillerParameter("constant", 0.1);
23
26 {
27 }
28
34 [Description("Specifies the axis along which to perform the softmax - may be negative to index from the end (e.g., -1 for the last axis).")]
35 public int axis
36 {
37 get { return m_nAxis; }
38 set { m_nAxis = value; }
39 }
40
44 public uint dim
45 {
46 get { return m_nDim; }
47 set { m_nDim = value; }
48 }
49
53 [Category("Fillers")]
54 [Description("The filler for the weights.")]
56 {
57 get { return m_fillerParam_weights; }
58 set { m_fillerParam_weights = value; }
59 }
60
64 [Category("Fillers")]
65 [Description("The filler for the bias.")]
67 {
68 get { return m_fillerParam_bias; }
69 set { m_fillerParam_bias = value; }
70 }
71
73 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
74 {
75 RawProto proto = RawProto.Parse(br.ReadString());
77
78 if (!bNewInstance)
79 Copy(p);
80
81 return p;
82 }
83
85 public override void Copy(LayerParameterBase src)
86 {
88
89 m_nDim = p.dim;
90 m_nAxis = p.m_nAxis;
91
92 if (p.m_fillerParam_bias != null)
93 m_fillerParam_bias = p.m_fillerParam_bias.Clone();
94
95 if (p.m_fillerParam_weights != null)
96 m_fillerParam_weights = p.m_fillerParam_weights.Clone();
97 }
98
100 public override LayerParameterBase Clone()
101 {
103 p.Copy(this);
104 return p;
105 }
106
112 public override RawProto ToProto(string strName)
113 {
114 RawProtoCollection rgChildren = new RawProtoCollection();
115
116 rgChildren.Add("axis", axis.ToString());
117 rgChildren.Add("dim", dim.ToString());
118
119 if (weight_filler != null)
120 rgChildren.Add(weight_filler.ToProto("weight_filler"));
121
122 if (bias_filler != null)
123 rgChildren.Add(bias_filler.ToProto("bias_filler"));
124
125 return new RawProto(strName, "", rgChildren);
126 }
127
134 {
135 string strVal;
137
138 if ((strVal = rp.FindValue("axis")) != null)
139 p.axis = int.Parse(strVal);
140
141 if ((strVal = rp.FindValue("dim")) != null)
142 p.dim = uint.Parse(strVal);
143
144 RawProto rpWeightFiller = rp.FindChild("weight_filler");
145 if (rpWeightFiller != null)
146 p.weight_filler = FillerParameter.FromProto(rpWeightFiller);
147
148 RawProto rpBiasFiller = rp.FindChild("bias_filler");
149 if (rpBiasFiller != null)
150 p.bias_filler = FillerParameter.FromProto(rpBiasFiller);
151
152 return p;
153 }
154 }
155}
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
[/b DEPRECIATED, use MultiHeadAttention layers instead.] Specifies the parameters for the AttentionLa...
int axis
The axis along which to perform the softmax – may be negative to index from the end (e....
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
AttentionParameter()
Constructor for the parameter.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
FillerParameter bias_filler
The filler for the bias.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
FillerParameter weight_filler
The filler for the weights.
static AttentionParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
uint dim
Specifies the dim of the attention unit which should match the LSTM output size.
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
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