MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
ReductionParameter.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 {
20 public enum ReductionOp
21 {
25 SUM = 1,
29 ASUM = 2,
33 SUMSQ = 3,
37 MEAN = 4,
41 MIN = 5,
45 MAX = 6
46 }
47
48 ReductionOp m_operation = ReductionOp.SUM;
49 int m_nAxis = 0;
50 double m_dfCoeff = 1.0;
51
54 {
55 }
56
60 [Description("Specifies the reduction operation.")]
62 {
63 get { return m_operation; }
64 set { m_operation = value; }
65 }
66
85 [Description("Specifies the first axis to reduce to scalar -- may be negative to index from the end (e.g., -1 for the last axis)..")]
86 public int axis
87 {
88 get { return m_nAxis; }
89 set { m_nAxis = value; }
90 }
91
95 [Description("Specifies the coefficient for output.")]
96 public double coeff
97 {
98 get { return m_dfCoeff; }
99 set { m_dfCoeff = value; }
100 }
101
103 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
104 {
105 RawProto proto = RawProto.Parse(br.ReadString());
106 ReductionParameter p = FromProto(proto);
107
108 if (!bNewInstance)
109 Copy(p);
110
111 return p;
112 }
113
115 public override void Copy(LayerParameterBase src)
116 {
118 m_operation = p.m_operation;
119 m_nAxis = p.m_nAxis;
120 m_dfCoeff = p.m_dfCoeff;
121 }
122
124 public override LayerParameterBase Clone()
125 {
127 p.Copy(this);
128 return p;
129 }
130
136 public override RawProto ToProto(string strName)
137 {
138 RawProtoCollection rgChildren = new RawProtoCollection();
139
140 rgChildren.Add("operation", operation.ToString());
141
142 if (axis != 0)
143 rgChildren.Add("axis", axis.ToString());
144
145 if (coeff != 1.0)
146 rgChildren.Add("coeff", coeff.ToString());
147
148 return new RawProto(strName, "", rgChildren);
149 }
150
157 {
158 string strVal;
160
161 if ((strVal = rp.FindValue("operation")) != null)
162 {
163 switch (strVal)
164 {
165 case "ASUM":
166 p.operation = ReductionOp.ASUM;
167 break;
168
169 case "MEAN":
170 p.operation = ReductionOp.MEAN;
171 break;
172
173 case "SUM":
174 p.operation = ReductionOp.SUM;
175 break;
176
177 case "SUMSQ":
178 p.operation = ReductionOp.SUMSQ;
179 break;
180
181 case "MIN":
182 p.operation = ReductionOp.MIN;
183 break;
184
185 case "MAX":
186 p.operation = ReductionOp.MAX;
187 break;
188
189 default:
190 throw new Exception("Uknown 'operation' value: " + strVal);
191 }
192 }
193
194 if ((strVal = rp.FindValue("axis")) != null)
195 p.axis = int.Parse(strVal);
196
197 if ((strVal = rp.FindValue("coeff")) != null)
198 p.coeff = ParseDouble(strVal);
199
200 return p;
201 }
202 }
203}
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
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 used by ReductionLayer.
int axis
The first axis to reduce to scalar – may be negative index from the end (e.g., -1 for the last axis)....
ReductionOp
Defines the reduction operation.
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
double coeff
Specifies the coefficient used to scale the output.
ReductionOp operation
Specifies the reduction operation.
static ReductionParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
ReductionParameter()
Constructor for the parameter.
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