MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
DetectionOutputParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.basecode;
7
8namespace MyCaffe.param.ssd
9{
17 [Serializable]
18 [TypeConverter(typeof(ExpandableObjectConverter))]
20 {
21 uint m_nNumClasses;
22 bool m_bShareLocation = true;
23 int m_nBackgroundLabelId = 0;
25 SaveOutputParameter m_saveOutputParam = new SaveOutputParameter(true);
27 bool m_bVarianceEncodedInTarget = false;
28 int m_nKeepTopK = -1;
29 float? m_fConfidenceThreshold;
30 bool m_bVisualize = false;
31 float? m_fVisualizeThreshold = null;
32 string m_strSaveFile = null;
33
38 {
39 }
40
44 [Description("Specifies the number of classes that are actually predicted - required!")]
45 public uint num_classes
46 {
47 get { return m_nNumClasses; }
48 set { m_nNumClasses = value; }
49 }
50
54 [Description("If true, bounding boxe is shared among different classes.")]
55 public bool share_location
56 {
57 get { return m_bShareLocation; }
58 set { m_bShareLocation = value; }
59 }
60
67 [Description("Specifies the background class, set to -1 when there is no background class.")]
69 {
70 get { return m_nBackgroundLabelId; }
71 set { m_nBackgroundLabelId = value; }
72 }
73
77 [Description("Parameter used for non maximum suppression.")]
79 {
80 get { return m_nmsParam; }
81 set { m_nmsParam = value; }
82 }
83
87 [Description("Specifies the parameter used for saving detection results.")]
89 {
90 get { return m_saveOutputParam; }
91 set { m_saveOutputParam = value; }
92 }
93
97 [Description("Specifies the coding method for the bbox.")]
99 {
100 get { return m_codeType; }
101 set { m_codeType = value; }
102 }
103
107 [Description("Specifies whether or not the variance is encoded in the target; otherwise we need to adjust the predicted offset accordingly.")]
109 {
110 get { return m_bVarianceEncodedInTarget; }
111 set { m_bVarianceEncodedInTarget = value; }
112 }
113
117 [Description("Specifies the number of total bboxes to be kept per image after nms step, -1 means keeping all bboxes after nms step.")]
118 public int keep_top_k
119 {
120 get { return m_nKeepTopK; }
121 set { m_nKeepTopK = value; }
122 }
123
127 [Description("Specifies the threshold for deciding which detections to consider - only those which are larger than this threshold.")]
129 {
130 get { return m_fConfidenceThreshold; }
131 set { m_fConfidenceThreshold = value; }
132 }
133
137 [Description("Specifies whether or not to visualize the detection results.")]
138 public bool visualize
139 {
140 get { return m_bVisualize; }
141 set { m_bVisualize = value; }
142 }
143
147 [Description("Specifies the theshold used to visualize detection results.")]
149 {
150 get { return m_fVisualizeThreshold; }
151 set { m_fVisualizeThreshold = value; }
152 }
153
157 [Description("When provided, specifies the outputs to the video file.")]
158 public string save_file
159 {
160 get { return m_strSaveFile; }
161 set { m_strSaveFile = value; }
162 }
163
170 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
171 {
172 RawProto proto = RawProto.Parse(br.ReadString());
174
175 if (!bNewInstance)
176 Copy(p);
177
178 return p;
179 }
180
185 public override void Copy(LayerParameterBase src)
186 {
188
189 m_nNumClasses = p.m_nNumClasses;
190 m_bShareLocation = p.m_bShareLocation;
191 m_nBackgroundLabelId = p.m_nBackgroundLabelId;
192 m_nmsParam = p.m_nmsParam.Clone();
193 m_saveOutputParam = p.save_output_param.Clone() as SaveOutputParameter;
194 m_codeType = p.m_codeType;
195 m_bVarianceEncodedInTarget = p.m_bVarianceEncodedInTarget;
196 m_nKeepTopK = p.m_nKeepTopK;
197 m_fConfidenceThreshold = p.m_fConfidenceThreshold;
198 m_bVisualize = p.m_bVisualize;
199 m_fVisualizeThreshold = p.m_fVisualizeThreshold;
200 m_strSaveFile = p.m_strSaveFile;
201 }
202
207 public override LayerParameterBase Clone()
208 {
210 p.Copy(this);
211 return p;
212 }
213
219 public override RawProto ToProto(string strName)
220 {
221 RawProtoCollection rgChildren = new RawProtoCollection();
222
223 rgChildren.Add(new RawProto("num_classes", num_classes.ToString()));
224 rgChildren.Add(new RawProto("share_location", share_location.ToString()));
225 rgChildren.Add(new RawProto("background_label_id", background_label_id.ToString()));
226
227 if (nms_param != null)
228 rgChildren.Add(nms_param.ToProto("nms_param"));
229
230 if (save_output_param != null)
231 rgChildren.Add(save_output_param.ToProto("save_output_param"));
232
233 rgChildren.Add(new RawProto("code_type", code_type.ToString()));
234 rgChildren.Add(new RawProto("variance_encoded_in_target", variance_encoded_in_target.ToString()));
235 rgChildren.Add(new RawProto("keep_top_k", keep_top_k.ToString()));
236
237 if (confidence_threshold.HasValue)
238 rgChildren.Add(new RawProto("confidence_threshold", confidence_threshold.Value.ToString()));
239
240 rgChildren.Add(new RawProto("visualize", visualize.ToString()));
241
242 if (visualize_threshold.HasValue)
243 rgChildren.Add(new RawProto("visualize_threshold", visualize_threshold.Value.ToString()));
244
245 rgChildren.Add(new RawProto("save_file", save_file));
246
247 return new RawProto(strName, "", rgChildren);
248 }
249
256 {
258 string strVal;
259
260 if ((strVal = rp.FindValue("num_classes")) != null)
261 p.num_classes = uint.Parse(strVal);
262
263 if ((strVal = rp.FindValue("share_location")) != null)
264 p.share_location = bool.Parse(strVal);
265
266 if ((strVal = rp.FindValue("background_label_id")) != null)
267 p.background_label_id = int.Parse(strVal);
268
269 RawProto rpNms = rp.FindChild("nms_param");
270 if (rpNms != null)
272
273 RawProto rpSave = rp.FindChild("save_output_param");
274 if (rpSave != null)
276
277 if ((strVal = rp.FindValue("code_type")) != null)
278 {
279 if (strVal == PriorBoxParameter.CodeType.CENTER_SIZE.ToString())
280 p.code_type = PriorBoxParameter.CodeType.CENTER_SIZE;
281 else if (strVal == PriorBoxParameter.CodeType.CORNER.ToString())
283 else if (strVal == PriorBoxParameter.CodeType.CORNER_SIZE.ToString())
284 p.code_type = PriorBoxParameter.CodeType.CORNER_SIZE;
285 else
286 throw new Exception("Unknown PriorBoxParameter.CodeType '" + strVal + "'!");
287 }
288
289 if ((strVal = rp.FindValue("variance_encoded_in_target")) != null)
290 p.variance_encoded_in_target = bool.Parse(strVal);
291
292 if ((strVal = rp.FindValue("keep_top_k")) != null)
293 p.keep_top_k = int.Parse(strVal);
294
295 if ((strVal = rp.FindValue("confidence_threshold")) != null)
297
298 if ((strVal = rp.FindValue("visualize")) != null)
299 p.visualize = bool.Parse(strVal);
300
301 if ((strVal = rp.FindValue("visualize_threshold")) != null)
303
304 if ((strVal = rp.FindValue("save_file")) != null)
305 p.save_file = strVal;
306
307 return p;
308 }
309 }
310}
static float ParseFloat(string strVal)
Parse float values using the US culture if the decimal separator = '.', then using the native culture...
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
RawProto FindChild(string strName)
Searches for a given node.
Definition: RawProto.cs:231
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 LayerParameterBase is the base class for all other layer specific parameters.
Specifies the parameters for the DetectionOutputLayer.
PriorBoxParameter.CodeType code_type
Specifies the coding method for the bbox.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
bool visualize
Specifies whether or not to visualize the detection results.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
float? confidence_threshold
Specifies the threshold for deciding which detections to consider - only those which are larger than ...
float? visualize_threshold
Specifies the theshold used to visualize detection results.
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
static DetectionOutputParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
NonMaximumSuppressionParameter nms_param
Specifies the parameter used for non maximum suppression.
bool variance_encoded_in_target
Specifies whether or not the variance is encoded in the target; otherwise we need to adjust the predi...
string save_file
When provided, specifies the outputs to the video file.
bool share_location
Specifies whether or not to sare the bounding box is shared among different classes (default = true).
uint num_classes
Specifies the number of classes that are actually predicted - required!
SaveOutputParameter save_output_param
Specifies the parameter used for saving the detection results.
int background_label_id
Specifies the background class.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
int keep_top_k
Specifies the number of total bboxes to be kept per image after nms step, -1 means keeping all bboxes...
Specifies the parameters for the NonMaximumSuppressionParameter used with SSD.
override RawProto ToProto(string strName)
Convert this object to a raw proto.
NonMaximumSuppressionParameter Clone()
Return a clone of the object.
static new NonMaximumSuppressionParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
Specifies the parameters for the PriorBoxParameter.
CodeType
Defines the encode/decode type.
Specifies the parameters for the SaveOutputLayer.
static new SaveOutputParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
SaveOutputParameter Clone()
Return a copy of this object.
override RawProto ToProto(string strName)
Convert this object to a raw proto.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe.param.ssd namespace contains all SSD related parameter objects that correspond to the nat...
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12