MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
FlattenParameter.cs
1using System;
2using System.Collections.Generic;
4using System.Linq;
5using System.Text;
6using MyCaffe.basecode;
7
8namespace MyCaffe.param
9{
17 [Serializable]
18 [TypeConverter(typeof(ExpandableObjectConverter))]
20 {
21 int m_nAxis = 1;
22 int m_nEndAxis = -1;
23
26 {
27 }
28
33 [Description("Specifies the first axis to flatten: all preceding axes are retained in the output.")]
34 public int axis
35 {
36 get { return m_nAxis; }
37 set { m_nAxis = value; }
38 }
39
44 [Description("Specifies the last axis to flatten: all following axes are retained in the output.")]
45 public int end_axis
46 {
47 get { return m_nEndAxis; }
48 set { m_nEndAxis = value; }
49 }
50
52 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
53 {
54 RawProto proto = RawProto.Parse(br.ReadString());
55 FlattenParameter p = FromProto(proto);
56
57 if (!bNewInstance)
58 Copy(p);
59
60 return p;
61 }
62
64 public override void Copy(LayerParameterBase src)
65 {
67 m_nAxis = p.m_nAxis;
68 m_nEndAxis = p.m_nEndAxis;
69 }
70
72 public override LayerParameterBase Clone()
73 {
75 p.Copy(this);
76 return p;
77 }
78
84 public override RawProto ToProto(string strName)
85 {
86 RawProtoCollection rgChildren = new RawProtoCollection();
87
88 rgChildren.Add("axis", axis.ToString());
89 rgChildren.Add("end_axis", end_axis.ToString());
90
91 return new RawProto(strName, "", rgChildren);
92 }
93
100 {
101 string strVal;
103
104 if ((strVal = rp.FindValue("axis")) != null)
105 p.axis = int.Parse(strVal);
106
107 if ((strVal = rp.FindValue("end_axis")) != null)
108 p.end_axis = int.Parse(strVal);
109
110 return p;
111 }
112
122 public static List<int> Reshape(int nParamAxis, int nParamEndAxis, List<int> rgShape, int nStartAxis = -1, int nEndAxis = -1)
123 {
124 if (nStartAxis < 0)
125 nStartAxis = Utility.CanonicalAxisIndex(nParamAxis, rgShape.Count);
126
127 if (nEndAxis < 0)
128 nEndAxis = Utility.CanonicalAxisIndex(nParamEndAxis, rgShape.Count);
129
130 List<int> rgTopShape = new List<int>();
131 for (int i = 0; i < nStartAxis; i++)
132 {
133 rgTopShape.Add(rgShape[i]);
134 }
135
136 int nFlattenDim = Utility.Count(rgShape, nStartAxis, nEndAxis + 1);
137 rgTopShape.Add(nFlattenDim);
138
139 for (int i = nEndAxis + 1; i < rgShape.Count; i++)
140 {
141 rgTopShape.Add(rgShape[i]);
142 }
143
144 return rgTopShape;
145 }
146 }
147}
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
static int CanonicalAxisIndex(int nIdx, int nNumAxes)
Returns the 'canonical' version of a (usually) user-specified axis, allowing for negative indexing (e...
Definition: Utility.cs:50
static int Count(List< int > rgShape, int nStartIdx=0, int nEndIdx=-1)
Return the count of items given the shape.
Definition: Utility.cs:83
Specifies the parameters for the FlattenLayer.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
static FlattenParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
static List< int > Reshape(int nParamAxis, int nParamEndAxis, List< int > rgShape, int nStartAxis=-1, int nEndAxis=-1)
Calculate the reshape array given the parameters.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
int axis
Specifies the first axis to flatten: all preceding axes are retained in the output....
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
int end_axis
Specifies the last axis to flatten: all following axes are retained in the output....
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
FlattenParameter()
Constructor for 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