MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
DropoutParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.basecode;
7
8namespace MyCaffe.param
9{
17 [Serializable]
18 [TypeConverter(typeof(ExpandableObjectConverter))]
20 {
21 double m_dfDropoutRatio = 0.5;
22 long m_lSeed = 0;
23 bool m_bActive = true;
24
27 : base()
28 {
29 }
30
35 public string useCaffeReason()
36 {
37 if (engine == Engine.CAFFE)
38 return "The engine setting is set on CAFFE.";
39
40 if (engine == Engine.DEFAULT)
41 return "The engine setting is set to DEFAULT and, unlike other layers, the DropoutLayer defaults to use CAFFE.";
42
43 return "";
44 }
45
50 public bool useCudnn()
51 {
52 if (engine == EngineParameter.Engine.CUDNN)
53 return true;
54
55 return false; // DEFAULT = CAFFE
56 }
57
61 [Description("Specifies the dropout ratio. (e.g. the probability that values will be dropped out and set to zero. A value of 0.25 = 25% chance that a value is set to 0, and dropped out.)")]
62 public double dropout_ratio
63 {
64 get { return m_dfDropoutRatio; }
65 set { m_dfDropoutRatio = value; }
66 }
67
71 [Description("Specifies the random number generator seed used with the cuDnn dropout - the default value of '0' uses a random seed.")]
72 public long seed
73 {
74 get { return m_lSeed; }
75 set { m_lSeed = value; }
76 }
77
81 [Description("Specifies whether or not the dropout is active or not. When inactive and training, the dropout acts the same as it does during testing and is ignored.")]
82 public bool active
83 {
84 get { return m_bActive; }
85 set { m_bActive = value; }
86 }
87
89 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
90 {
91 RawProto proto = RawProto.Parse(br.ReadString());
92 DropoutParameter p = FromProto(proto);
93
94 if (!bNewInstance)
95 Copy(p);
96
97 return p;
98 }
99
101 public override void Copy(LayerParameterBase src)
102 {
103 base.Copy(src);
104
105 if (src is DropoutParameter)
106 {
108 m_dfDropoutRatio = p.m_dfDropoutRatio;
109 m_lSeed = p.m_lSeed;
110 m_bActive = p.m_bActive;
111 }
112 }
113
115 public override LayerParameterBase Clone()
116 {
118 p.Copy(this);
119 return p;
120 }
121
123 public override RawProto ToProto(string strName)
124 {
125 RawProto rpBase = base.ToProto("engine");
126 RawProtoCollection rgChildren = new RawProtoCollection();
127
128 rgChildren.Add(rpBase.Children);
129
130 if (dropout_ratio != 0.5)
131 rgChildren.Add("dropout_ratio", dropout_ratio.ToString());
132
133 if (seed != 0)
134 rgChildren.Add("seed", seed.ToString());
135
136 if (!active)
137 rgChildren.Add("active", active.ToString());
138
139 return new RawProto(strName, "", rgChildren);
140 }
141
143 public static new DropoutParameter FromProto(RawProto rp)
144 {
145 string strVal;
147
149
150 if ((strVal = rp.FindValue("dropout_ratio")) != null)
151 p.dropout_ratio = ParseDouble(strVal);
152
153 if ((strVal = rp.FindValue("seed")) != null)
154 p.seed = long.Parse(strVal);
155
156 if ((strVal = rp.FindValue("active")) != null)
157 p.active = bool.Parse(strVal);
158
159 return p;
160 }
161 }
162}
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
RawProtoCollection Children
Returns a collection of this nodes child nodes.
Definition: RawProto.cs:96
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
Specifies the parameters of the DropoutLayer.
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
string useCaffeReason()
Returns the reason that Caffe version was used instead of NVIDIA's cuDnn.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
DropoutParameter()
Constructor for the parameter.
double dropout_ratio
Specifies the dropout ratio. (e.g. the probability that values will be dropped out and set to zero....
static new DropoutParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
long seed
Specifies the seed used by cuDnn for random number generation.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
bool active
Specifies whether or not the dropout is active or not. When inactive and training,...
bool useCudnn()
Queries whether or not to use NVIDIA's cuDnn.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
Specifies whether to use the NVIDIA cuDnn version or Caffe version of a given forward/backward operat...
Engine engine
Specifies the Engine in use.
EngineParameter()
Constructor for the parameter.
static EngineParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
Engine
Defines the type of engine to use.
The LayerParameterBase is the base class for all other layer specific parameters.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe.param namespace contains parameters used to create models.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12