MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
KernelParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.basecode;
7using MyCaffe.common;
8
9namespace MyCaffe.param
10{
14 [Serializable]
15 [TypeConverter(typeof(ExpandableObjectConverter))]
17 {
18 List<uint> m_rgPad = new List<uint>();
19 List<uint> m_rgStride = new List<uint>();
20 List<uint> m_rgKernelSize = new List<uint>();
21 List<uint> m_rgDilation = new List<uint>();
22 uint? m_nPadH = null;
23 uint? m_nPadW = null;
24 uint? m_nStrideH = null;
25 uint? m_nStrideW = null;
26 uint? m_nKernelH = null;
27 uint? m_nKernelW = null;
28
29
32 {
33 }
34
39 [Description("Specifies pad given as a single value for equal dimensions in all spatial dimensions, or once per spatial dimension.")]
40 public List<uint> pad
41 {
42 get { return m_rgPad; }
43 set { m_rgPad = value; }
44 }
45
50 [Description("Specifies stride given as a single value for equal dimensions in all spatial dimensions, or once per spatial dimension.")]
51 public List<uint> stride
52 {
53 get { return m_rgStride; }
54 set { m_rgStride = value; }
55 }
56
61 [Description("Specifies kernel size given as a single value for equal dimensions in all spatial dimensions, or once per spatial dimension.")]
62 public List<uint> kernel_size
63 {
64 get { return m_rgKernelSize; }
65 set { m_rgKernelSize = value; }
66 }
67
80 [Description("Specifies dilation given as a single value for equal dimensions in all spatial dimensions, or once per spatial dimension. When specified, this is used to dilate the kernel, (implicitly) zero-filling the resulting holes. (Kernel dilation is sometimes referred to by its use in the algorithm 'a trous from Holschneider et al. 1987.)")]
81 public List<uint> dilation
82 {
83 get { return m_rgDilation; }
84 set { m_rgDilation = value; }
85 }
86
94 [Description("Specifies padding height (2D only). 'pad_h' and 'pad_w' are used -or- 'pad' is used, but not both.")]
95 public uint? pad_h
96 {
97 get { return m_nPadH; }
98 set { m_nPadH = value; }
99 }
100
108 [Description("Specifies padding width (2D only). 'pad_h' and 'pad_w' are used -or- 'pad' is used, but not both.")]
109 public uint? pad_w
110 {
111 get { return m_nPadW; }
112 set { m_nPadW = value; }
113 }
114
122 [Description("Specifies stride height (2D only). 'stride_h' and 'stride_w' are used -or- 'stride' is used, but not both.")]
123 public uint? stride_h
124 {
125 get { return m_nStrideH; }
126 set { m_nStrideH = value; }
127 }
128
136 [Description("Specifies stride width (2D only). 'stride_h' and 'stride_w' are used -or- 'stride' is used, but not both.")]
137 public uint? stride_w
138 {
139 get { return m_nStrideW; }
140 set { m_nStrideW = value; }
141 }
142
150 [Description("Specifies kernel size height (2D only). 'kernel_h' and 'kernel_w' are used -or- 'kernel_size' is used, but not both.")]
151 public uint? kernel_h
152 {
153 get { return m_nKernelH; }
154 set { m_nKernelH = value; }
155 }
156
164 [Description("Specifies kernel size width (2D only). 'kernel_h' and 'kernel_w' are used -or- 'kernel_size' is used, but not both.")]
165 public uint? kernel_w
166 {
167 get { return m_nKernelW; }
168 set { m_nKernelW = value; }
169 }
170
172 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
173 {
174 RawProto proto = RawProto.Parse(br.ReadString());
175 KernelParameter p = FromProto(proto);
176
177 if (!bNewInstance)
178 Copy(p);
179
180 return p;
181 }
182
184 public override void Copy(LayerParameterBase src)
185 {
186 base.Copy(src);
187
188 if (src is KernelParameter)
189 {
191 m_rgPad = Utility.Clone<uint>(p.m_rgPad);
192 m_rgStride = Utility.Clone<uint>(p.m_rgStride);
193 m_rgKernelSize = Utility.Clone<uint>(p.m_rgKernelSize);
194 m_rgDilation = Utility.Clone<uint>(p.m_rgDilation);
195 m_nPadH = p.m_nPadH;
196 m_nPadW = p.m_nPadW;
197 m_nStrideH = p.m_nStrideH;
198 m_nStrideW = p.m_nStrideW;
199 m_nKernelH = p.m_nKernelH;
200 m_nKernelW = p.m_nKernelW;
201 }
202 }
203
205 public override LayerParameterBase Clone()
206 {
208 p.Copy(this);
209 return p;
210 }
211
217 public override RawProto ToProto(string strName)
218 {
219 RawProto rpBase = base.ToProto("engine");
220 RawProtoCollection rgChildren = new RawProtoCollection();
221
222 rgChildren.Add(rpBase.Children);
223 rgChildren.Add<uint>("kernel_size", m_rgKernelSize);
224 rgChildren.Add<uint>("stride", m_rgStride);
225 rgChildren.Add<uint>("pad", m_rgPad);
226
227 if (m_rgDilation.Count > 0)
228 rgChildren.Add<uint>("dilation", m_rgDilation);
229
230 rgChildren.Add("kernel_h", m_nKernelH);
231 rgChildren.Add("kernel_w", m_nKernelW);
232 rgChildren.Add("stride_h", m_nStrideH);
233 rgChildren.Add("stride_w", m_nStrideW);
234 rgChildren.Add("pad_h", m_nPadH);
235 rgChildren.Add("pad_w", m_nPadW);
236
237 return new RawProto(strName, "", rgChildren);
238 }
239
245 public static new KernelParameter FromProto(RawProto rp)
246 {
248
250
251 p.m_rgPad = rp.FindArray<uint>("pad");
252 p.m_rgStride = rp.FindArray<uint>("stride");
253 p.m_rgKernelSize = rp.FindArray<uint>("kernel_size");
254 p.m_rgDilation = rp.FindArray<uint>("dilation");
255 p.m_nPadH = (uint?)rp.FindValue("pad_h", typeof(uint));
256 p.m_nPadW = (uint?)rp.FindValue("pad_w", typeof(uint));
257 p.m_nStrideH = (uint?)rp.FindValue("stride_h", typeof(uint));
258 p.m_nStrideW = (uint?)rp.FindValue("stride_w", typeof(uint));
259 p.m_nKernelH = (uint?)rp.FindValue("kernel_h", typeof(uint));
260 p.m_nKernelW = (uint?)rp.FindValue("kernel_w", typeof(uint));
261
262 return p;
263 }
264 }
265}
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
The Utility class provides general utility funtions.
Definition: Utility.cs:35
Specifies whether to use the NVIDIA cuDnn version or Caffe version of a given forward/backward operat...
EngineParameter()
Constructor for the parameter.
static EngineParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
Specifies the basic kernel parameters (used by convolution and pooling)
uint? stride_h
The stride height (2D only)
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
List< uint > kernel_size
Kernel size is given as a single value for equal dimensions in all spatial dimensions,...
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 ...
uint? stride_w
The stride width (2D only)
override void Copy(LayerParameterBase src)
Copy on parameter to another.
uint? pad_h
The padding height (2D only)
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
uint? kernel_h
The kernel height (2D only)
List< uint > stride
Stride is given as a single value for equal dimensions in all spatial dimensions, or once per spatial...
uint? kernel_w
The kernel width (2D only)
KernelParameter()
Constructor for the parameter.
uint? pad_w
The padding width (2D only)
List< uint > pad
Pad is given as a single value for equal dimensions in all spatial dimensions, or once per spatial di...
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
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