MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
AccuracyParameter.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 uint m_nTopK = 1;
21 int m_nAxis = 1;
22 List<int> m_rgnIgnoreLabel = new List<int>();
23 bool m_bEnableSimpleAccuracy = false;
24 bool m_bEnableLastElementOnly = false;
25
28 {
29 }
30
34 [Description("Enables a simple argmax based accuracy calculation where the argmax is compared with the actual.")]
36 {
37 get { return m_bEnableSimpleAccuracy; }
38 set { m_bEnableSimpleAccuracy = value; }
39 }
40
44 [Description("When computing accuracy, only count the last element of the prediction blob.")]
46 {
47 get { return m_bEnableLastElementOnly; }
48 set { m_bEnableLastElementOnly = value; }
49 }
50
56 [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 class (i.e. argmax).")]
57 public uint top_k
58 {
59 get { return m_nTopK; }
60 set { m_nTopK = value; }
61 }
62
70 [Description("Specifies the 'label' axis of the prediction blob, whos argmax corresponds to the predicted label -- may be negative to index from the end (e.g., -1 for the last axis). For example, if axis == 1 and the predictions are (NxCxHxW), the label blob is expected to contain N*H*W ground truth labels with integer values in {0, 1,..., C-1}.")]
71 public int axis
72 {
73 get { return m_nAxis; }
74 set { m_nAxis = value; }
75 }
76
80 [Description("If specified, ignore instances with the given label(s).")]
81 public List<int> ignore_labels
82 {
83 get { return m_rgnIgnoreLabel; }
84 set
85 {
86 if (value == null)
87 m_rgnIgnoreLabel.Clear();
88 else
89 m_rgnIgnoreLabel = value;
90 }
91 }
92
98 public bool IgnoreLabel(int nLabel)
99 {
100 return m_rgnIgnoreLabel.Contains(nLabel);
101 }
102
104 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
105 {
106 RawProto proto = RawProto.Parse(br.ReadString());
107 AccuracyParameter 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_nTopK = p.m_nTopK;
120 m_nAxis = p.m_nAxis;
121 m_bEnableSimpleAccuracy = p.m_bEnableSimpleAccuracy;
122 m_bEnableLastElementOnly = p.m_bEnableLastElementOnly;
123 m_rgnIgnoreLabel = Utility.Clone<int>(p.m_rgnIgnoreLabel);
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 (top_k != 1)
144 rgChildren.Add("top_k", top_k.ToString());
145
146 if (axis != 1)
147 rgChildren.Add("axis", axis.ToString());
148
150 rgChildren.Add("enable_simple_accuracy", enable_simple_accuracy.ToString());
151
153 rgChildren.Add("enable_last_element_only", enable_last_element_only.ToString());
154
155 if (m_rgnIgnoreLabel.Count > 0)
156 {
157 if (m_rgnIgnoreLabel.Count == 1)
158 rgChildren.Add("ignore_label", m_rgnIgnoreLabel[0]);
159 else
160 rgChildren.Add("ignore_labels", Utility.ToString<int>(m_rgnIgnoreLabel));
161 }
162
163 return new RawProto(strName, "", rgChildren);
164 }
165
172 {
173 string strVal;
175
176 if ((strVal = rp.FindValue("top_k")) != null)
177 p.top_k = uint.Parse(strVal);
178
179 if ((strVal = rp.FindValue("axis")) != null)
180 p.axis = int.Parse(strVal);
181
182 if ((strVal = rp.FindValue("enable_simple_accuracy")) != null)
183 p.enable_simple_accuracy = bool.Parse(strVal);
184
185 if ((strVal = rp.FindValue("enable_last_element_only")) != null)
186 p.enable_last_element_only = bool.Parse(strVal);
187
188 if ((strVal = rp.FindValue("ignore_label")) != null)
189 {
190 p.ignore_labels.Clear();
191 p.ignore_labels.Add(int.Parse(strVal));
192 }
193
194 if ((strVal = rp.FindValue("ignore_labels")) != null)
195 {
196 p.ignore_labels.Clear();
197
198 string[] rgstr = strVal.Trim(' ', '{', '}').Split(',');
199
200 foreach (string str in rgstr)
201 {
202 if (!string.IsNullOrEmpty(str))
203 p.ignore_labels.Add(int.Parse(str));
204 }
205 }
206
207 return p;
208 }
209 }
210}
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
Specifies the parameters for the AccuracyLayer.
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....
AccuracyParameter()
Constructor for the parameter.
List< int > ignore_labels
If specified, ignore instances with the given label(s).
override void Copy(LayerParameterBase src)
Copy on parameter to another.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
int axis
The 'label' axis of the prediction blob, whos argmax corresponds to the predicted label – may be nega...
bool IgnoreLabel(int nLabel)
Returns 'true' if the label is to be ignored.
bool enable_simple_accuracy
Enables a simple accuracy calculation where the argmax is compared with the actual.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
static AccuracyParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
bool enable_last_element_only
When computing accuracy, only count the last element of the prediction blob.
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