MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
EltwiseParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.basecode;
7using MyCaffe.common;
8
9namespace MyCaffe.param
10{
19 [Serializable]
20 [TypeConverter(typeof(ExpandableObjectConverter))]
22 {
26 public enum EltwiseOp
27 {
31 PROD = 0,
35 SUM = 1,
39 MAX = 2,
43 MIN = 3,
47 DIV = 4,
51 SUB = 5
52 }
53
54 EltwiseOp m_operation = EltwiseOp.SUM;
55 List<double> m_rgdfCoeff = new List<double>();
56 bool m_bStableProdGrad = true;
57 bool m_bCoeffBlob = false;
58 bool m_bAllowSingleBatchInput = false;
59
62 {
63 }
64
68 [Description("Specifies the element-wise operation to perform.")]
70 {
71 get { return m_operation; }
72 set { m_operation = value; }
73 }
74
78 [Description("Specifies whether to allow single batch input for the second input (default = false).")]
80 {
81 get { return m_bAllowSingleBatchInput; }
82 set { m_bAllowSingleBatchInput = value; }
83 }
84
88 [Description("Specifies the blob-wise coefficient for SUM operation.")]
89 public List<double> coeff
90 {
91 get { return m_rgdfCoeff; }
92 set { m_rgdfCoeff = value; }
93 }
94
99 [Description("Specifies whether or not to use an asymtotically slower (for > 2 inputs) but stabler method for computing the gradient for PROD operation (No effect for SUM operation).")]
101 {
102 get { return m_bStableProdGrad; }
103 set { m_bStableProdGrad = value; }
104 }
105
110 [Description("If true and EltwiseOp is SUM, the last bottom blob is a singleton coefficient for the first N-1 bottom blobs, with shape (N-1, 1, 1, 1).")]
111 public bool coeff_blob
112 {
113 get { return m_bCoeffBlob; }
114 set { m_bCoeffBlob = value; }
115 }
116
118 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
119 {
120 RawProto proto = RawProto.Parse(br.ReadString());
121 EltwiseParameter p = FromProto(proto);
122
123 if (!bNewInstance)
124 Copy(p);
125
126 return p;
127 }
128
130 public override void Copy(LayerParameterBase src)
131 {
133 m_operation = p.m_operation;
134 m_rgdfCoeff = Utility.Clone<double>(p.m_rgdfCoeff);
135 m_bStableProdGrad = p.m_bStableProdGrad;
136 m_bCoeffBlob = p.m_bCoeffBlob;
137 m_bAllowSingleBatchInput = p.allow_single_batch_input;
138 }
139
141 public override LayerParameterBase Clone()
142 {
144 p.Copy(this);
145 return p;
146 }
147
153 public override RawProto ToProto(string strName)
154 {
155 RawProtoCollection rgChildren = new RawProtoCollection();
156
157 rgChildren.Add("operation", operation.ToString());
158 rgChildren.Add<double>("coeff", coeff);
159
160 if (stable_prod_grad != true)
161 rgChildren.Add("stable_prod_grad", stable_prod_grad.ToString());
162
163 if (coeff_blob != false)
164 rgChildren.Add("coeff_blob", coeff_blob.ToString());
165
166 if (allow_single_batch_input != false)
167 rgChildren.Add("allow_single_batch_input", allow_single_batch_input.ToString());
168
169 return new RawProto(strName, "", rgChildren);
170 }
171
178 {
179 string strVal;
181
182 if ((strVal = rp.FindValue("operation")) != null)
183 {
184 switch (strVal)
185 {
186 case "PROD":
187 p.operation = EltwiseOp.PROD;
188 break;
189
190 case "SUM":
191 p.operation = EltwiseOp.SUM;
192 break;
193
194 case "MAX":
195 p.operation = EltwiseOp.MAX;
196 break;
197
198 case "MIN":
199 p.operation = EltwiseOp.MIN;
200 break;
201
202 case "DIV":
203 p.operation = EltwiseOp.DIV;
204 break;
205
206 case "SUB":
207 p.operation = EltwiseOp.SUB;
208 break;
209
210 default:
211 throw new Exception("Unknown 'operation' value: " + strVal);
212 }
213 }
214
215 p.coeff = rp.FindArray<double>("coeff");
216
217 if ((strVal = rp.FindValue("stable_prod_grad")) != null)
218 p.stable_prod_grad = bool.Parse(strVal);
219
220 if ((strVal = rp.FindValue("coeff_blob")) != null)
221 p.coeff_blob = bool.Parse(strVal);
222
223 if ((strVal = rp.FindValue("allow_single_batch_input")) != null)
224 p.allow_single_batch_input = bool.Parse(strVal);
225
226 return p;
227 }
228 }
229}
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 Utility class provides general utility funtions.
Definition: Utility.cs:35
Specifies the parameters for the EltwiseLayer.
EltwiseOp
Defines the operation to perform.
bool allow_single_batch_input
Specifies whether to allow single batch input for the second input (default = false).
EltwiseParameter()
Constructor for the parameter.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
List< double > coeff
Specifies the blob-wise coefficient for SUM operation.
bool stable_prod_grad
Specifies whether or not to use an asymptotically slower (for > 2 inputs) but stabler method of compu...
EltwiseOp operation
Specifies the element-wise operation.
static EltwiseParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
bool coeff_blob
If true and the EltwiseOp is SUM, the last bottom blob is a singleton coefficient for the first N-1 b...
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
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.common namespace contains common MyCaffe classes.
Definition: BatchInput.cs:8
@ SUB
Specifies to perform a subtraction operation.
@ DIV
Specifies to perform a division operation.
@ PROD
Multiply the values.
@ MIN
Return the minimum value.
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