MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
ArgMaxParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using MyCaffe.basecode;
7
8namespace MyCaffe.param
9{
16 [Serializable]
17 [TypeConverter(typeof(ExpandableObjectConverter))]
19 {
20 bool m_bOutMaxVal = false;
21 uint m_nTopK = 1;
22 int? m_nAxis = null;
24 bool m_bEnableCudaImplementation = false;
25
29 public enum COMPARE_OPERATOR
30 {
34 MAX,
38 MIN
39 }
40
43 {
44 }
45
52 public bool enable_cuda_impl
53 {
54 get { return m_bEnableCudaImplementation; }
55 set { m_bEnableCudaImplementation = value; }
56 }
57
61 [Description("Specifies the operation to use (default = MAX).")]
63 {
64 get { return m_op; }
65 set { m_op = value; }
66 }
67
71 [Description("If true, produce pairs (argmax, maxval -or- argmin, minval when using 'op' = MIN).")]
72 public bool out_max_val
73 {
74 get { return m_bOutMaxVal; }
75 set { m_bOutMaxVal = value; }
76 }
77
83 [Description("When computing accuracy, count as correct by comparing the true label to the 'top_k' scoring classes. By default, only compare the top scoring classes (i.e. argmax).")]
84 public uint top_k
85 {
86 get { return m_nTopK; }
87 set { m_nTopK = value; }
88 }
89
96 [Description("Specifies the axis along which to maximize -- may be negative to index from end (e.g., -1 for the last axis). By default the ArgMaxLayer maximizes over the flattened trailing dimensions for each index of the first / num dimension.")]
97 public int? axis
98 {
99 get { return m_nAxis; }
100 set { m_nAxis = value; }
101 }
102
104 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
105 {
106 RawProto proto = RawProto.Parse(br.ReadString());
107 ArgMaxParameter p = FromProto(proto);
108
109 if (!bNewInstance)
110 Copy(p);
111
112 return p;
113 }
114
116 public override void Copy(LayerParameterBase src)
117 {
119 m_bOutMaxVal = p.m_bOutMaxVal;
120 m_nTopK = p.m_nTopK;
121 m_nAxis = p.m_nAxis;
122 m_op = p.m_op;
123 m_bEnableCudaImplementation = p.enable_cuda_impl;
124 }
125
127 public override LayerParameterBase Clone()
128 {
130 p.Copy(this);
131 return p;
132 }
133
139 public override RawProto ToProto(string strName)
140 {
141 RawProtoCollection rgChildren = new RawProtoCollection();
142
143 if (out_max_val != false)
144 rgChildren.Add("out_max_val", out_max_val.ToString());
145
146 if (top_k != 1)
147 rgChildren.Add("top_k", top_k.ToString());
148
149 if (axis.HasValue)
150 rgChildren.Add("axis", axis.Value.ToString());
151
152 if (operation != COMPARE_OPERATOR.MAX)
153 rgChildren.Add("operation", operation.ToString());
154
155 rgChildren.Add("enable_cuda_impl", m_bEnableCudaImplementation.ToString());
156
157 return new RawProto(strName, "", rgChildren);
158 }
159
166 {
167 string strVal;
169
170 if ((strVal = rp.FindValue("out_max_val")) != null)
171 p.out_max_val = bool.Parse(strVal);
172
173 if ((strVal = rp.FindValue("top_k")) != null)
174 p.top_k = uint.Parse(strVal);
175
176 if ((strVal = rp.FindValue("axis")) != null)
177 p.axis = int.Parse(strVal);
178
179 if ((strVal = rp.FindValue("operation")) != null)
180 {
181 if (strVal == COMPARE_OPERATOR.MIN.ToString())
183 else
185 }
186
187 if ((strVal = rp.FindValue("enable_cuda_impl")) != null)
188 p.m_bEnableCudaImplementation = bool.Parse(strVal);
189
190 return p;
191 }
192 }
193}
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
Specifies the parameters for the ArgMaxLayer
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
bool enable_cuda_impl
Specifies to use the low-level full cuda implementation of LayerNorm (default = false).
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
uint top_k
When computing accuracy, count as correct by comparing the true label to the top_k scoring classes....
override void Copy(LayerParameterBase src)
Copy on parameter to another.
static ArgMaxParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
COMPARE_OPERATOR operation
Specifies the operation to use (default = MAX).
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
bool out_max_val
If true produce pairs (argmax, maxval)
COMPARE_OPERATOR
Defines the compare operator to use (max or min, default = max).
int? axis
The axis along which to maximize – may be negative to index from the end (e.g., -1 for the last axis)...
ArgMaxParameter()
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