MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
SamplerConstraint.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.IO;
6using MyCaffe.basecode;
7using MyCaffe.common;
9
10namespace MyCaffe.param.ssd
11{
19 [Serializable]
20 [TypeConverter(typeof(ExpandableObjectConverter))]
21 public class SamplerConstraint : BaseParameter, ICloneable, IComparable, IBinaryPersist
22 {
23 float? m_fMinJaccardOverlap = null;
24 float? m_fMaxJaccardOverlap = null;
25 float? m_fMinSampleCoverage = null;
26 float? m_fMaxSampleCoverage = null;
27 float? m_fMinObjectCoverage = null;
28 float? m_fMaxObjectCoverage = null;
29
34 {
35 }
36
37 private void save(BinaryWriter bw, float? f)
38 {
39 bw.Write(f.HasValue);
40 if (f.HasValue)
41 bw.Write(f.Value);
42 }
43
44 private float? load(BinaryReader br)
45 {
46 if (br.ReadBoolean())
47 return br.ReadSingle();
48 else
49 return null;
50 }
51
56 public void Save(BinaryWriter bw)
57 {
58 save(bw, m_fMinJaccardOverlap);
59 save(bw, m_fMaxJaccardOverlap);
60 save(bw, m_fMinSampleCoverage);
61 save(bw, m_fMaxSampleCoverage);
62 save(bw, m_fMinObjectCoverage);
63 save(bw, m_fMaxSampleCoverage);
64 }
65
72 public object Load(BinaryReader br, bool bNewInstance)
73 {
74 SamplerConstraint b = this;
75
76 if (bNewInstance)
77 b = new SamplerConstraint();
78
79 b.m_fMinJaccardOverlap = load(br);
80 b.m_fMaxJaccardOverlap = load(br);
81 b.m_fMinSampleCoverage = load(br);
82 b.m_fMaxSampleCoverage = load(br);
83 b.m_fMinObjectCoverage = load(br);
84 b.m_fMaxObjectCoverage = load(br);
85
86 return b;
87 }
88
94 public static SamplerConstraint Load(BinaryReader br)
95 {
97 return (SamplerConstraint)b.Load(br, true);
98 }
99
104 {
105 get { return m_fMinJaccardOverlap; }
106 set { m_fMinJaccardOverlap = value; }
107 }
108
113 {
114 get { return m_fMaxJaccardOverlap; }
115 set { m_fMaxJaccardOverlap = value; }
116 }
117
122 {
123 get { return m_fMinSampleCoverage; }
124 set { m_fMinSampleCoverage = value; }
125 }
126
131 {
132 get { return m_fMaxSampleCoverage; }
133 set { m_fMaxSampleCoverage = value; }
134 }
135
140 {
141 get { return m_fMinObjectCoverage; }
142 set { m_fMinObjectCoverage = value; }
143 }
144
149 {
150 get { return m_fMaxObjectCoverage; }
151 set { m_fMaxObjectCoverage = value; }
152 }
153
159 {
161
162 bs.m_fMinJaccardOverlap = m_fMinJaccardOverlap;
163 bs.m_fMaxJaccardOverlap = m_fMaxJaccardOverlap;
164 bs.m_fMinSampleCoverage = m_fMinSampleCoverage;
165 bs.m_fMaxSampleCoverage = m_fMaxSampleCoverage;
166 bs.m_fMinObjectCoverage = m_fMinObjectCoverage;
167 bs.m_fMaxObjectCoverage = m_fMaxObjectCoverage;
168
169 return bs;
170 }
171
176 object ICloneable.Clone()
177 {
178 return Clone();
179 }
180
187 {
188 if (bs.m_fMinJaccardOverlap != m_fMinJaccardOverlap)
189 return false;
190 if (bs.m_fMaxJaccardOverlap != m_fMaxJaccardOverlap)
191 return false;
192
193 if (bs.m_fMinSampleCoverage != m_fMinSampleCoverage)
194 return false;
195 if (bs.m_fMaxSampleCoverage != m_fMaxSampleCoverage)
196 return false;
197
198 if (bs.m_fMinObjectCoverage != m_fMinObjectCoverage)
199 return false;
200 if (bs.m_fMaxObjectCoverage != m_fMaxObjectCoverage)
201 return false;
202
203 return true;
204 }
205
211 public int CompareTo(object obj)
212 {
214
215 if (bs == null)
216 return 1;
217
218 if (!Compare(bs))
219 return 1;
220
221 return 0;
222 }
223
229 public override RawProto ToProto(string strName)
230 {
231 RawProtoCollection rgChildren = new RawProtoCollection();
232
233 if (m_fMinJaccardOverlap.HasValue)
234 rgChildren.Add(new RawProto("min_jaccard_overlap", m_fMinJaccardOverlap.Value.ToString()));
235 if (m_fMaxJaccardOverlap.HasValue)
236 rgChildren.Add(new RawProto("max_jaccard_overlap", m_fMaxJaccardOverlap.Value.ToString()));
237
238 if (m_fMinSampleCoverage.HasValue)
239 rgChildren.Add(new RawProto("min_sample_coverage", m_fMinSampleCoverage.Value.ToString()));
240 if (m_fMaxSampleCoverage.HasValue)
241 rgChildren.Add(new RawProto("max_sample_coverage", m_fMaxSampleCoverage.Value.ToString()));
242
243 if (m_fMinObjectCoverage.HasValue)
244 rgChildren.Add(new RawProto("min_object_coverage", m_fMinObjectCoverage.Value.ToString()));
245 if (m_fMaxObjectCoverage.HasValue)
246 rgChildren.Add(new RawProto("max_object_coverage", m_fMaxObjectCoverage.Value.ToString()));
247
248 return new RawProto(strName, "", rgChildren);
249 }
250
257 {
258 string strVal;
260
261 if ((strVal = rp.FindValue("min_jaccard_overlap")) != null)
263 if ((strVal = rp.FindValue("max_jaccard_overlap")) != null)
265
266 if ((strVal = rp.FindValue("min_sample_coverage")) != null)
268 if ((strVal = rp.FindValue("max_sample_coverage")) != null)
270
271 if ((strVal = rp.FindValue("min_object_coverage")) != null)
273 if ((strVal = rp.FindValue("max_object_coverage")) != null)
275
276 return p;
277 }
278
283 public override string ToString()
284 {
285 string strOut = "";
286
287 if (min_jaccard_overlap.HasValue)
288 strOut += "min_jaccard_overlap = " + min_jaccard_overlap.Value.ToString() + Environment.NewLine;
289 if (max_jaccard_overlap.HasValue)
290 strOut += "max_jaccard_overlap = " + max_jaccard_overlap.Value.ToString() + Environment.NewLine;
291
292 if (min_sample_coverage.HasValue)
293 strOut += "min_sample_coverage = " + min_sample_coverage.Value.ToString() + Environment.NewLine;
294 if (max_sample_coverage.HasValue)
295 strOut += "max_sample_coverage = " + max_sample_coverage.Value.ToString() + Environment.NewLine;
296
297 if (min_object_coverage.HasValue)
298 strOut += "min_object_coverage = " + min_object_coverage.Value.ToString() + Environment.NewLine;
299 if (max_object_coverage.HasValue)
300 strOut += "max_object_coverage = " + max_object_coverage.Value.ToString() + Environment.NewLine;
301
302 return strOut;
303 }
304 }
305}
The BaseParameter class is the base class for all other parameter classes.
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
string FindValue(string strName)
Searches for a falue of a node within this nodes children.
Definition: RawProto.cs:105
Specifies the constratins for selecting sampled bbox used in SSD.
static SamplerConstraint FromProto(RawProto rp)
Parse a new SampleConstraint from a RawProto.
float? max_object_coverage
Get/set the maximum Object coverage between sampled bbox and all boxes in AnnotationGroup.
float? min_object_coverage
Get/set the minimum Object coverage between sampled bbox and all boxes in AnnotationGroup.
SamplerConstraint()
The SampleConstraint constructor.
float? max_jaccard_overlap
Get/set the maximum Jaccard overlap between sampled bbox and all boxes in AnnotationGroup.
float? min_sample_coverage
Get/set the minimum Sample coverage between sampled bbox and all boxes in AnnotationGroup.
int CompareTo(object obj)
Compares this SampleConstraint to another.
float? max_sample_coverage
Get/set the maximum Sample coverage between sampled bbox and all boxes in AnnotationGroup.
override RawProto ToProto(string strName)
Converts the SampleConstraint to a RawProto.
void Save(BinaryWriter bw)
Save the SampleConstraint to a binary writer.
override string ToString()
Return the string representation of the shape.
static SamplerConstraint Load(BinaryReader br)
Load the SampleConstraint from a binary reader.
object Load(BinaryReader br, bool bNewInstance)
Load the SampleConstraint from a binary reader.
SamplerConstraint Clone()
Creates a copy of the SampleConstraint.
float? min_jaccard_overlap
Get/set the minimum Jaccard overlap between sampled bbox and all boxes in AnnotationGroup.
bool Compare(SamplerConstraint bs)
Compares this SampleConstraint to another.
The IBinaryPersist interface provides generic save and load functionality.
Definition: Utility.cs:16
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe.common namespace contains common MyCaffe classes.
Definition: BatchInput.cs:8
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