MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
SoftmaxParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.basecode;
7using MyCaffe.common;
8
9namespace MyCaffe.param
10{
20 [Serializable]
21 [TypeConverter(typeof(ExpandableObjectConverter))]
23 {
24 int m_nAxis = 1;
25 SOFTMAX_ALGORITHM? m_TrainAlgorithm = null;
26 SOFTMAX_ALGORITHM m_RunAlgorithm = SOFTMAX_ALGORITHM.DEFAULT;
27
30 : base()
31 {
32 }
33
38 public string useCaffeReason()
39 {
40 if (engine == Engine.CAFFE)
41 return "The engine setting is set on CAFFE.";
42
43 return "";
44 }
45
50 public bool useCudnn()
51 {
52 if (engine == EngineParameter.Engine.CAFFE)
53 return false;
54
55 return true;
56 }
57
62 {
63 get { return m_TrainAlgorithm; }
64 set { m_TrainAlgorithm = value; }
65 }
66
71 {
72 get { return m_RunAlgorithm; }
73 set { m_RunAlgorithm = value; }
74 }
75
81 [Description("Specifies the axis along which to perform the softmax - may be negative to index from the end (e.g., -1 for the last axis).")]
82 public int axis
83 {
84 get { return m_nAxis; }
85 set { m_nAxis = value; }
86 }
87
89 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
90 {
91 RawProto proto = RawProto.Parse(br.ReadString());
92 SoftmaxParameter 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 SoftmaxParameter)
106 {
108 m_nAxis = p.m_nAxis;
109 m_TrainAlgorithm = p.m_TrainAlgorithm;
110 m_RunAlgorithm = p.m_RunAlgorithm;
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 rgChildren.Add("axis", axis.ToString());
130 rgChildren.Add("algorithm", algorithm.ToString());
131 if (algorithm_train.HasValue)
132 rgChildren.Add("algorithm_train", algorithm_train.Value.ToString());
133
134 return new RawProto(strName, "", rgChildren);
135 }
136
142 public static new SoftmaxParameter FromProto(RawProto rp)
143 {
144 string strVal;
146
148
149 if ((strVal = rp.FindValue("axis")) != null)
150 p.axis = int.Parse(strVal);
151
152 if ((strVal = rp.FindValue("algorithm")) != null)
153 {
154 if (strVal == SOFTMAX_ALGORITHM.LOG.ToString())
156 else if (strVal == SOFTMAX_ALGORITHM.ACCURATE.ToString())
157 p.algorithm = SOFTMAX_ALGORITHM.ACCURATE;
158 else if (strVal == SOFTMAX_ALGORITHM.FAST.ToString())
160 else
161 p.algorithm = SOFTMAX_ALGORITHM.DEFAULT;
162 }
163
164 if ((strVal = rp.FindValue("algorithm_train")) != null)
165 {
166 if (strVal == SOFTMAX_ALGORITHM.LOG.ToString())
168 else if (strVal == SOFTMAX_ALGORITHM.ACCURATE.ToString())
170 else if (strVal == SOFTMAX_ALGORITHM.FAST.ToString())
172 else
174 }
175 else
176 {
177 p.algorithm_train = null;
178 }
179
180 return p;
181 }
182 }
183}
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 SoftmaxLayer
SOFTMAX_ALGORITHM algorithm
Specifies the softmax algorithm to use during the running and testing.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
bool useCudnn()
Queries whether or not to use NVIDIA's cuDnn. Softmax uses cuDNN as the default.
string useCaffeReason()
Returns the reason that Caffe version was used instead of NVIDIA's cuDnn.
SOFTMAX_ALGORITHM? algorithm_train
Optionally, specifies the softmax algorithm to use during the training phase, when null,...
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
SoftmaxParameter()
Constructor for the parameter.
static new SoftmaxParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
int axis
The axis along which to perform the softmax – may be negative to index from the end (e....
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
SOFTMAX_ALGORITHM
Specifies the SOFTMAX algorithm to use.
Definition: CudaDnn.cs:701
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