MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
DecodeParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using MyCaffe.basecode;
7
20namespace MyCaffe.param.beta
21{
25 [Serializable]
26 [TypeConverter(typeof(ExpandableObjectConverter))]
28 {
29 bool m_bEnableCentroidUpdate = true;
30 int m_nCentroidOutputIteration = 300;
31 bool m_bOutputCentroids = false;
32 List<int> m_rgIgnoreLabels = new List<int>();
33 TARGET m_target = TARGET.CENTROID;
34 int m_nCacheSize = 100;
35 int m_nK = 5;
36 double m_dfPreGenAlpha = 1.1;
37 int m_nPreGenerateTargetCount = 0;
38
42 public enum TARGET
43 {
47 PREGEN,
51 CENTROID,
55 KNN
56 }
57
60 {
61 }
62
66 [Description("Specifies the pregen margin.")]
67 public double pregen_alpha
68 {
69 get { return m_dfPreGenAlpha; }
70 set { m_dfPreGenAlpha = value; }
71 }
72
82 [Description("Specifies the pre-generate target count, only used when 'target' = PREGEN.")]
84 {
85 get { return m_nPreGenerateTargetCount; }
86 set { m_nPreGenerateTargetCount = value; }
87 }
88
92 [Description("Specifies whether or not to update the centroids. For example in some cases a fixed centroid may be desired, such as in the case when initializing centroids with a PREGEN value.")]
94 {
95 get { return m_bEnableCentroidUpdate; }
96 set { m_bEnableCentroidUpdate = value; }
97 }
98
102 [Description("Specifies the iteration where calculated centroids are output for each label, before this value, the centroids should not be used for their calculation is not complete (default = 300).")]
104 {
105 get { return m_nCentroidOutputIteration; }
106 set { m_nCentroidOutputIteration = value; }
107 }
108
112 [Description("Optionally, specifies to output the centroids in top[1] (default = false).")]
114 {
115 get { return m_bOutputCentroids; }
116 set { m_bOutputCentroids = value; }
117 }
118
122 [Description("Optionally, specifies one or more labels to ignore. (default = none, which then expects all labels).")]
123 public List<int> ignore_labels
124 {
125 get { return m_rgIgnoreLabels; }
126 set { m_rgIgnoreLabels = value; }
127 }
128
132 [Description("Optionally, specifies the target type to use (default = CENTROID).")]
134 {
135 get { return m_target; }
136 set { m_target = value; }
137 }
138
142 [Description("Specifies the size of the cache (in number of batches) used when calculating the CENTROID and KNN values (default = 300).")]
143 public int cache_size
144 {
145 get { return m_nCacheSize; }
146 set { m_nCacheSize = value; }
147 }
148
152 [Description("Optionally, specifies the K value to use with the KNN target (default = 5).")]
153 public int k
154 {
155 get { return m_nK; }
156 set { m_nK = value; }
157 }
158
165 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
166 {
167 RawProto proto = RawProto.Parse(br.ReadString());
168 DecodeParameter p = FromProto(proto);
169
170 if (!bNewInstance)
171 Copy(p);
172
173 return p;
174 }
175
180 public override void Copy(LayerParameterBase src)
181 {
183 m_nCentroidOutputIteration = p.m_nCentroidOutputIteration;
184 m_nCacheSize = p.m_nCacheSize;
185 m_bOutputCentroids = p.m_bOutputCentroids;
186 m_dfPreGenAlpha = p.m_dfPreGenAlpha;
187 m_nPreGenerateTargetCount = p.m_nPreGenerateTargetCount;
188 m_bEnableCentroidUpdate = p.m_bEnableCentroidUpdate;
189
190 if (p.m_rgIgnoreLabels != null)
191 m_rgIgnoreLabels = Utility.Clone<int>(p.m_rgIgnoreLabels);
192
193 m_target = p.m_target;
194 m_nK = p.m_nK;
195 }
196
201 public override LayerParameterBase Clone()
202 {
204 p.Copy(this);
205 return p;
206 }
207
213 public override RawProto ToProto(string strName)
214 {
215 RawProtoCollection rgChildren = new RawProtoCollection();
216
217 rgChildren.Add("centroid_output_iteration", centroid_output_iteration.ToString());
218 rgChildren.Add("enable_centroid_update", enable_centroid_update.ToString());
219 rgChildren.Add("cache_size", cache_size.ToString());
220 rgChildren.Add("output_centroids", output_centroids.ToString());
221 rgChildren.Add("target", target.ToString());
222 rgChildren.Add("pregen_alpha", pregen_alpha.ToString());
223 rgChildren.Add("pregen_label_count", pregen_label_count.ToString());
224 rgChildren.Add("k", k.ToString());
225
226 foreach (int nLabel in ignore_labels)
227 {
228 rgChildren.Add("ignore_label", nLabel.ToString());
229 }
230
231 return new RawProto(strName, "", rgChildren);
232 }
233
240 {
241 string strVal;
243
244 if ((strVal = rp.FindValue("centroid_output_iteration")) != null)
245 p.centroid_output_iteration = int.Parse(strVal);
246
247 if ((strVal = rp.FindValue("enable_centroid_update")) != null)
248 p.enable_centroid_update = bool.Parse(strVal);
249
250 if ((strVal = rp.FindValue("cache_size")) != null)
251 p.cache_size = int.Parse(strVal);
252
253 if ((strVal = rp.FindValue("output_centroids")) != null)
254 p.output_centroids = bool.Parse(strVal);
255
256 if ((strVal = rp.FindValue("pregen_alpha")) != null)
257 p.pregen_alpha = ParseDouble(strVal);
258
259 if ((strVal = rp.FindValue("pregen_label_count")) != null)
260 p.pregen_label_count = int.Parse(strVal);
261
262 p.ignore_labels = new List<int>();
263 RawProtoCollection rpIgnore = rp.FindChildren("ignore_label");
264 foreach (RawProto rplabel in rpIgnore)
265 {
266 int nLabel = int.Parse(rplabel.Value);
267 if (!p.ignore_labels.Contains(nLabel))
268 p.ignore_labels.Add(nLabel);
269 }
270
271 if ((strVal = rp.FindValue("target")) != null)
272 {
273 if (strVal == TARGET.KNN.ToString())
274 p.target = TARGET.KNN;
275 else if (strVal == TARGET.PREGEN.ToString())
276 p.target = TARGET.PREGEN;
277 else
278 p.target = TARGET.CENTROID;
279 }
280
281 if ((strVal = rp.FindValue("k")) != null)
282 p.k = int.Parse(strVal);
283
284 return p;
285 }
286 }
287}
static double ParseDouble(string strVal)
Parse double values using the US culture if the decimal separator = '.', then using the native cultur...
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
string Value
Get/set the value of the node.
Definition: RawProto.cs:79
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
RawProtoCollection FindChildren(params string[] rgstrName)
Searches for all children with a given name in this node's children.
Definition: RawProto.cs:263
The Utility class provides general utility funtions.
Definition: Utility.cs:35
The LayerParameterBase is the base class for all other layer specific parameters.
Specifies the parameters for the DecodeLayer and the AccuracyEncodingLayer.
DecodeParameter()
Constructor for the parameter.
bool output_centroids
Optionally, specifies to output the centroids in top[1] (default = false).
override void Copy(LayerParameterBase src)
Copy on parameter to another.
bool enable_centroid_update
Specifies whether or not to update the centroids. For example in some cases a fixed centroid may be d...
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
int centroid_output_iteration
Specifies the iteration where calculated centroids are output for each label, before this value,...
static DecodeParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
double pregen_alpha
Specifies the pregen margin.
TARGET
Defines the target type.
int cache_size
Specifies the size of the cache (in number of batches) used when calculating the CENTROID and KNN val...
int pregen_label_count
Specifies the pre-generate target count, only used when 'target' = PREGEN.
TARGET target
Optionally, specifies the target type to use (default = CENTROID).
int k
Optionally, specifies the K value to use with the KNN target (default = 5).
List< int > ignore_labels
Optionally, specifies one or more labels to ignore. (default = none, which then expects all labels).
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
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