MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
SaltPepperParameter.cs
1using System;
2using System.Collections.Generic;
4using System.IO;
5using System.Linq;
6using System.Text;
7using System.Threading.Tasks;
8using MyCaffe.basecode;
9
10namespace MyCaffe.param.ssd
11{
19 [Serializable]
20 [TypeConverter(typeof(ExpandableObjectConverter))]
22 {
23 float m_fFraction = 0;
24 List<float> m_rgValue = new List<float>();
25
30 public SaltPepperParameter(bool bActive) : base(bActive)
31 {
32 }
33
37 [Description("Get/set the percentage of pixels.")]
38 public float fraction
39 {
40 get { return m_fFraction; }
41 set { m_fFraction = value; }
42 }
43
47 [Description("Get/set the values.")]
48 public List<float> value
49 {
50 get { return m_rgValue; }
51 set { m_rgValue = value; }
52 }
53
58 public override void Copy(OptionalParameter src)
59 {
60 base.Copy(src);
61
62 if (src is SaltPepperParameter)
63 {
65 m_fFraction = p.fraction;
66 m_rgValue = new List<float>();
67
68 foreach (float fVal in p.value)
69 {
70 m_rgValue.Add(fVal);
71 }
72 }
73 }
74
80 {
82 p.Copy(this);
83 return p;
84 }
85
91 public override RawProto ToProto(string strName)
92 {
93 RawProto rpBase = base.ToProto("option");
94 RawProtoCollection rgChildren = new RawProtoCollection();
95
96 rgChildren.Add(rpBase);
97 rgChildren.Add(new RawProto("active", Active.ToString()));
98 rgChildren.Add(new RawProto("fraction", m_fFraction.ToString()));
99
100 foreach (float fVal in m_rgValue)
101 {
102 rgChildren.Add(new RawProto("value", fVal.ToString()));
103 }
104
105 return new RawProto(strName, "", rgChildren);
106 }
107
114 {
116 string strVal;
117
118 RawProto rpOption = rp.FindChild("option");
119 if (rpOption != null)
120 ((OptionalParameter)p).Copy(OptionalParameter.FromProto(rpOption));
121
122 if ((strVal = rp.FindValue("fraction")) != null)
124
125 p.value = new List<float>();
126 RawProtoCollection col = rp.FindChildren("value");
127 foreach (RawProto rp1 in col)
128 {
129 if ((strVal = rp.FindValue("value")) != null)
130 p.value.Add(BaseParameter.ParseFloat(strVal));
131 }
132
133 return p;
134 }
135 }
136}
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
RawProto FindChild(string strName)
Searches for a given node.
Definition: RawProto.cs:231
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 OptionalParameter is the base class for parameters that are optional such as the MaskParameter,...
static OptionalParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
OptionalParameter(bool bActive=false)
The constructor.
bool Active
When active, the parameter is used, otherwise it is ignored.
Specifies the parameters for the SaltPepperParameter used with SSD.
override RawProto ToProto(string strName)
Convert this object to a raw proto.
SaltPepperParameter Clone()
Return a clone of the object.
static new SaltPepperParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
SaltPepperParameter(bool bActive)
The constructor.
float fraction
Get/set the percentage of pixels.
override void Copy(OptionalParameter src)
Copy the object.
List< float > value
Get/set the values.
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