MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
GatherParameter.cs
1using System;
2using System.Collections.Generic;
4using System.Linq;
5using System.Text;
6using MyCaffe.basecode;
7
8namespace MyCaffe.param.beta
9{
13 [Serializable]
14 [TypeConverter(typeof(ExpandableObjectConverter))]
16 {
17 int m_nAxis = 0;
18
21 {
22 }
23
28 [Description("Specifies the first axis to gather: all preceding axes are retained in the output.")]
29 public int axis
30 {
31 get { return m_nAxis; }
32 set { m_nAxis = value; }
33 }
34
36 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
37 {
38 RawProto proto = RawProto.Parse(br.ReadString());
39 GatherParameter p = FromProto(proto);
40
41 if (!bNewInstance)
42 Copy(p);
43
44 return p;
45 }
46
48 public override void Copy(LayerParameterBase src)
49 {
51 m_nAxis = p.m_nAxis;
52 }
53
55 public override LayerParameterBase Clone()
56 {
58 p.Copy(this);
59 return p;
60 }
61
67 public override RawProto ToProto(string strName)
68 {
69 RawProtoCollection rgChildren = new RawProtoCollection();
70
71 rgChildren.Add("axis", axis.ToString());
72
73 return new RawProto(strName, "", rgChildren);
74 }
75
82 {
83 string strVal;
85
86 if ((strVal = rp.FindValue("axis")) != null)
87 p.axis = int.Parse(strVal);
88
89 return p;
90 }
91
105 public static List<int> Reshape(int nAxis, List<int> rgBtmShape, List<int> rgIdxShape, float[] rgIdxF, out int nDim, out int nDimAtAxis, out int nM, out int nN, out string strErr)
106 {
107 nAxis = Utility.CanonicalAxisIndex(nAxis, rgBtmShape.Count);
108 nDim = Utility.Count(rgBtmShape, nAxis + 1);
109 nDimAtAxis = rgBtmShape[nAxis];
110 nM = Utility.Count(rgBtmShape, 0, nAxis);
111 nN = Utility.Count(rgIdxShape);
112
113 strErr = null;
114
115 if (rgIdxF != null)
116 {
117 if (nN != rgIdxF.Length)
118 {
119 strErr = "N should equal the number of indices.";
120 return null;
121 }
122
123 for (int i = 0; i < nN; i++)
124 {
125 int nIdx = (int)rgIdxF[i];
126 if (nIdx < -nDimAtAxis || nIdx > nDimAtAxis)
127 {
128 strErr = "The index at idx=" + i.ToString() + " is out of range! Must be within range [-" + nDimAtAxis.ToString() + "," + nDimAtAxis.ToString() + "]";
129 return null;
130 }
131 }
132 }
133
134 List<int> rgTopShape = new List<int>(rgIdxShape);
135 int nLen = rgTopShape.Count;
136
137 while (rgTopShape.Count > 0 && rgTopShape[rgTopShape.Count - 1] == 1)
138 {
139 rgTopShape.RemoveAt(rgTopShape.Count - 1);
140 }
141
142 if (nAxis == 0)
143 rgTopShape.Add(nDim);
144 else if (nAxis == 1)
145 rgTopShape.Insert(0, nM);
146
147 for (int i = rgTopShape.Count; i < nLen; i++)
148 {
149 rgTopShape.Add(1);
150 }
151
152 return rgTopShape;
153 }
154 }
155}
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
The LayerParameterBase is the base class for all other layer specific parameters.
Specifies the parameters for the GatherLayer.
int axis
Specifies the first axis to gather: all preceding axes are retained in the output....
override void Copy(LayerParameterBase src)
Copy on parameter to another.
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.
static List< int > Reshape(int nAxis, List< int > rgBtmShape, List< int > rgIdxShape, float[] rgIdxF, out int nDim, out int nDimAtAxis, out int nM, out int nN, out string strErr)
Calculate the reshape array given the parameters.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
static GatherParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
GatherParameter()
Constructor for the parameter.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe.param.beta parameters are used by the MyCaffe.layer.beta layers.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12