MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
Sampler.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 Sampler : BaseParameter, ICloneable, IComparable, IBinaryPersist
22 {
23 float m_fMinScale = 1.0f;
24 float m_fMaxScale = 1.0f;
25 float m_fMinAspectRatio = 1.0f;
26 float m_fMaxAspectRatio = 1.0f;
27
31 public Sampler()
32 {
33 }
34
39 public void Save(BinaryWriter bw)
40 {
41 bw.Write(m_fMinScale);
42 bw.Write(m_fMaxScale);
43 bw.Write(m_fMinAspectRatio);
44 bw.Write(m_fMaxAspectRatio);
45 }
46
53 public object Load(BinaryReader br, bool bNewInstance)
54 {
55 Sampler b = this;
56
57 if (bNewInstance)
58 b = new Sampler();
59
60 b.m_fMinScale = br.ReadSingle();
61 b.m_fMaxScale = br.ReadSingle();
62 b.m_fMinAspectRatio = br.ReadSingle();
63 b.m_fMaxAspectRatio = br.ReadSingle();
64
65 return b;
66 }
67
73 public static Sampler Load(BinaryReader br)
74 {
75 Sampler b = new Sampler();
76 return (Sampler)b.Load(br, true);
77 }
78
82 public float min_scale
83 {
84 get { return m_fMinScale; }
85 set { m_fMinScale = value; }
86 }
87
91 public float max_scale
92 {
93 get { return m_fMaxScale; }
94 set { m_fMaxScale = value; }
95 }
96
100 public float min_aspect_ratio
101 {
102 get { return m_fMinAspectRatio; }
103 set { m_fMinAspectRatio = value; }
104 }
105
109 public float max_aspect_ratio
110 {
111 get { return m_fMaxAspectRatio; }
112 set { m_fMaxAspectRatio = value; }
113 }
114
119 public Sampler Clone()
120 {
121 Sampler bs = new Sampler();
122
123 bs.m_fMinScale = m_fMinScale;
124 bs.m_fMaxScale = m_fMaxScale;
125 bs.m_fMinAspectRatio = m_fMinAspectRatio;
126 bs.m_fMaxAspectRatio = m_fMaxAspectRatio;
127
128 return bs;
129 }
130
135 object ICloneable.Clone()
136 {
137 return Clone();
138 }
139
145 public bool Compare(Sampler bs)
146 {
147 if (bs.m_fMinScale != m_fMinScale)
148 return false;
149 if (bs.m_fMaxScale != m_fMaxScale)
150 return false;
151
152 if (bs.m_fMinAspectRatio != m_fMinAspectRatio)
153 return false;
154 if (bs.m_fMaxAspectRatio != m_fMaxAspectRatio)
155 return false;
156
157 return true;
158 }
159
165 public int CompareTo(object obj)
166 {
167 Sampler bs = obj as Sampler;
168
169 if (bs == null)
170 return 1;
171
172 if (!Compare(bs))
173 return 1;
174
175 return 0;
176 }
177
183 public override RawProto ToProto(string strName)
184 {
185 RawProtoCollection rgChildren = new RawProtoCollection();
186
187 rgChildren.Add(new RawProto("min_scale", m_fMinScale.ToString()));
188 rgChildren.Add(new RawProto("max_scale", m_fMaxScale.ToString()));
189 rgChildren.Add(new RawProto("min_aspect_ratio", m_fMinAspectRatio.ToString()));
190 rgChildren.Add(new RawProto("max_aspect_ratio", m_fMaxAspectRatio.ToString()));
191
192 return new RawProto(strName, "", rgChildren);
193 }
194
200 public static Sampler FromProto(RawProto rp)
201 {
202 string strVal;
203 Sampler p = new Sampler();
204
205 if ((strVal = rp.FindValue("min_scale")) != null)
207 if ((strVal = rp.FindValue("max_scale")) != null)
209
210 if ((strVal = rp.FindValue("min_aspect_ratio")) != null)
212 if ((strVal = rp.FindValue("max_aspect_ratio")) != null)
214
215 return p;
216 }
217
222 public override string ToString()
223 {
224 string strOut = "";
225
226 strOut += "min_scale = " + min_scale.ToString() + Environment.NewLine;
227 strOut += "max_scale = " + max_scale.ToString() + Environment.NewLine;
228 strOut += "min_aspect_ratio = " + min_aspect_ratio.ToString() + Environment.NewLine;
229 strOut += "max_aspect_ratio = " + max_aspect_ratio.ToString() + Environment.NewLine;
230
231 return strOut;
232 }
233 }
234}
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 sample of a bbox in the normalized space [0,1] with provided constraints used in SSD.
Definition: Sampler.cs:22
override string ToString()
Return the string representation of the shape.
Definition: Sampler.cs:222
void Save(BinaryWriter bw)
Save the Sample to a binary writer.
Definition: Sampler.cs:39
bool Compare(Sampler bs)
Compares this Sample to another.
Definition: Sampler.cs:145
int CompareTo(object obj)
Compares this Sample to another.
Definition: Sampler.cs:165
Sampler Clone()
Creates a copy of the Sample.
Definition: Sampler.cs:119
static Sampler Load(BinaryReader br)
Load the Sample from a binary reader.
Definition: Sampler.cs:73
float max_scale
Get/set the maximum scale of the sampled bbox.
Definition: Sampler.cs:92
float max_aspect_ratio
Get/set the maximum aspect ratio of the sampled bbox.
Definition: Sampler.cs:110
float min_scale
Get/set the minimum scale of the sampled bbox.
Definition: Sampler.cs:83
override RawProto ToProto(string strName)
Converts the Sample to a RawProto.
Definition: Sampler.cs:183
object Load(BinaryReader br, bool bNewInstance)
Load the Sample from a binary reader.
Definition: Sampler.cs:53
float min_aspect_ratio
Get/set the minimum aspect ratio of the sampled bbox.
Definition: Sampler.cs:101
static Sampler FromProto(RawProto rp)
Parse a new Sample from a RawProto.
Definition: Sampler.cs:200
Sampler()
The Sample constructor.
Definition: Sampler.cs:31
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