MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
PoolingParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.basecode;
7
8namespace MyCaffe.param
9{
18 [Serializable]
19 [TypeConverter(typeof(ExpandableObjectConverter))]
21 {
22 PoolingMethod m_pool = PoolingMethod.MAX;
23 bool m_bGlobalPooling = false;
24 PoolingReshapeAlgorithm m_reshapeAlgorithm = PoolingReshapeAlgorithm.DEFAULT;
25
30 {
34 DEFAULT,
38 CAFFE, // default
42 ONNX,
43 }
44
48 public enum PoolingMethod
49 {
53 MAX = 0,
57 AVE = 1,
61 STOCHASTIC = 2
62 }
63
66 {
67 }
68
73 public string useCaffeReason()
74 {
75 if (engine == Engine.CAFFE)
76 return "The engine setting is set on CAFFE.";
77
78 if (pool == PoolingMethod.STOCHASTIC)
79 return "The STOCHASTIC pooing method is currently not supported with cuDnn.";
80
81 return "";
82 }
83
88 public bool useCudnn()
89 {
90 if (engine == EngineParameter.Engine.CAFFE)
91 return false;
92
93 if (pool == PoolingParameter.PoolingMethod.STOCHASTIC)
94 return false;
95
96 return true;
97 }
98
102 [Description("Specifies pooling method to use.")]
104 {
105 get { return m_pool; }
106 set { m_pool = value; }
107 }
108
112 [Description("Specifies whether or not to enable global pooling.")]
113 public bool global_pooling
114 {
115 get { return m_bGlobalPooling; }
116 set { m_bGlobalPooling = value; }
117 }
118
132 {
133 get { return m_reshapeAlgorithm; }
134 set { m_reshapeAlgorithm = value; }
135 }
136
138 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
139 {
140 RawProto proto = RawProto.Parse(br.ReadString());
141 PoolingParameter p = FromProto(proto);
142
143 if (!bNewInstance)
144 Copy(p);
145
146 return p;
147 }
148
150 public override void Copy(LayerParameterBase src)
151 {
152 base.Copy(src);
153
154 if (src is PoolingParameter)
155 {
157 m_pool = p.m_pool;
158 m_bGlobalPooling = p.m_bGlobalPooling;
159 m_reshapeAlgorithm = p.m_reshapeAlgorithm;
160 }
161 }
162
164 public override LayerParameterBase Clone()
165 {
167 p.Copy(this);
168 return p;
169 }
170
172 public override RawProto ToProto(string strName)
173 {
174 dilation.Clear();
175 RawProto rpBase = base.ToProto("kernel");
176 RawProtoCollection rgChildren = new RawProtoCollection();
177
178 rgChildren.Add(rpBase.Children);
179 rgChildren.Add("pool", pool.ToString());
180
181 if (global_pooling != false)
182 rgChildren.Add("global_pooling", global_pooling.ToString());
183
185 rgChildren.Add("reshape_algorithm", reshape_algorithm.ToString());
186
187 return new RawProto(strName, "", rgChildren);
188 }
189
195 public static new PoolingParameter FromProto(RawProto rp)
196 {
197 string strVal;
199
201
202 if ((strVal = rp.FindValue("pool")) != null)
203 {
204 switch (strVal)
205 {
206 case "MAX":
207 p.pool = PoolingMethod.MAX;
208 break;
209
210 case "AVE":
211 p.pool = PoolingMethod.AVE;
212 break;
213
214 case "STOCHASTIC":
215 p.pool = PoolingMethod.STOCHASTIC;
216 break;
217
218 default:
219 throw new Exception("Unknown pooling 'method' value: " + strVal);
220 }
221 }
222
223 if ((strVal = rp.FindValue("global_pooling")) != null)
224 p.global_pooling = bool.Parse(strVal);
225
226 if ((strVal = rp.FindValue("reshape_algorithm")) != null)
227 {
228 switch (strVal)
229 {
230 case "CAFFE":
232 break;
233
234 case "ONNX":
236 break;
237
238 default:
240 break;
241 }
242 }
243
244 return p;
245 }
246 }
247}
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
RawProtoCollection Children
Returns a collection of this nodes child nodes.
Definition: RawProto.cs:96
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 whether to use the NVIDIA cuDnn version or Caffe version of a given forward/backward operat...
Engine engine
Specifies the Engine in use.
Engine
Defines the type of engine to use.
Specifies the basic kernel parameters (used by convolution and pooling)
static new KernelParameter FromProto(RawProto rp)
Parse a RawProto into a new instance of the parameter.
List< uint > dilation
Factor used to dilate the kernel, (implicitly) zero-filling the resulting holes. (Kernel dilation is ...
KernelParameter()
Constructor for the parameter.
The LayerParameterBase is the base class for all other layer specific parameters.
Specifies the parameters for the PoolingLayer.
PoolingReshapeAlgorithm
Defines the pooling reshape algorithm to use.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
string useCaffeReason()
Returns the reason that Caffe version was used instead of NVIDIA's cuDnn.
PoolingMethod
Defines the pooling method.
PoolingParameter()
Constructor for the parameter.
bool useCudnn()
Queries whether or not to use NVIDIA's cuDnn.
PoolingMethod pool
Specifies the pooling method.
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
static new PoolingParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
bool global_pooling
Specifies whether or not to enable global pooling.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
PoolingReshapeAlgorithm reshape_algorithm
Specifies the reshape algorithm to use, either the original Caffe reshape (default = false) or the ne...
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
@ DEFAULT
Specifies to use the default data type of the gym used.
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