MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
ReLUParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.basecode;
7
8namespace MyCaffe.param
9{
18 [Serializable]
19 [TypeConverter(typeof(ExpandableObjectConverter))]
21 {
22 double m_dfNegativeSlope = 0;
23
26 : base()
27 {
28 }
29
34 public string useCaffeReason()
35 {
36 if (engine == Engine.CAFFE)
37 return "The engine setting is set on CAFFE.";
38
39 if (negative_slope != 0)
40 return "Leaky ReLU (negative slope != 0) currently not supported with cuDnn.";
41
42 return "";
43 }
44
49 public bool useCudnn()
50 {
51 if (engine == EngineParameter.Engine.CAFFE ||
52 negative_slope != 0)
53 return false;
54
55 return true;
56 }
57
61 [Description("Specifies the negative slope. Allow non-zero slope for negative inputs to speed up optimization.")]
62 public double negative_slope
63 {
64 get { return m_dfNegativeSlope; }
65 set { m_dfNegativeSlope = value; }
66 }
67
69 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
70 {
71 RawProto proto = RawProto.Parse(br.ReadString());
72 ReLUParameter p = FromProto(proto);
73
74 if (!bNewInstance)
75 Copy(p);
76
77 return p;
78 }
79
81 public override void Copy(LayerParameterBase src)
82 {
83 base.Copy(src);
84
85 if (src is ReLUParameter)
86 {
88 m_dfNegativeSlope = p.m_dfNegativeSlope;
89 }
90 }
91
93 public override LayerParameterBase Clone()
94 {
96 p.Copy(this);
97 return p;
98 }
99
101 public override RawProto ToProto(string strName)
102 {
103 RawProto rpBase = base.ToProto("engine");
104 RawProtoCollection rgChildren = new RawProtoCollection();
105
106 rgChildren.Add(rpBase.Children);
107
108 if (negative_slope != 0)
109 rgChildren.Add("negative_slope", negative_slope.ToString());
110
111 return new RawProto(strName, "", rgChildren);
112 }
113
115 public static new ReLUParameter FromProto(RawProto rp)
116 {
117 string strVal;
119
121
122 if ((strVal = rp.FindValue("negative_slope")) != null)
123 p.negative_slope = ParseDouble(strVal);
124
125 return p;
126 }
127 }
128}
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 whether to use the NVIDIA cuDnn version or Caffe version of a given forward/backward operat...
Engine engine
Specifies the Engine in use.
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.
Specifies the parameters for the ReLULayer
override void Copy(LayerParameterBase src)
Copy on parameter to another.
static new ReLUParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
double negative_slope
Specifies the negative slope. Allow non-zero slope for negative inputs to speed up optimization.
bool useCudnn()
Queries whether or not to use NVIDIA's cuDnn.
ReLUParameter()
Constructor for the parameter.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
string useCaffeReason()
Returns the reason that Caffe version was used instead of NVIDIA's cuDnn.
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