MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
ScalarParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using MyCaffe.basecode;
7
8namespace MyCaffe.param.nt
9{
13 [Serializable]
14 [TypeConverter(typeof(ExpandableObjectConverter))]
16 {
17 double m_dfVal;
18 ScalarOp m_op;
19 bool m_bPassthroughGradient = false;
20
24 public enum ScalarOp
25 {
29 MUL,
33 ADD
34 }
35
40 {
41 }
42
46 [Description("Specifies the scalar value to apply.")]
47 public double value
48 {
49 get { return m_dfVal; }
50 set { m_dfVal = value; }
51 }
52
56 [Description("Specifies the scalar operatioon to apply (mul, add, etc).")]
58 {
59 get { return m_op; }
60 set { m_op = value; }
61 }
62
67 {
68 get { return m_bPassthroughGradient; }
69 set { m_bPassthroughGradient = value; }
70 }
71
78 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
79 {
80 RawProto proto = RawProto.Parse(br.ReadString());
81 ScalarParameter p = FromProto(proto);
82
83 if (!bNewInstance)
84 Copy(p);
85
86 return p;
87 }
88
93 public override void Copy(LayerParameterBase src)
94 {
96 m_dfVal = p.m_dfVal;
97 m_op = p.m_op;
98 m_bPassthroughGradient = p.m_bPassthroughGradient;
99 }
100
105 public override LayerParameterBase Clone()
106 {
108 p.Copy(this);
109 return p;
110 }
111
117 public override RawProto ToProto(string strName)
118 {
119 RawProtoCollection rgChildren = new RawProtoCollection();
120
121 rgChildren.Add("value", m_dfVal.ToString());
122 rgChildren.Add("operation", m_op.ToString());
123 rgChildren.Add("passthrough_gradient", passthrough_gradient.ToString());
124
125 return new RawProto(strName, "", rgChildren);
126 }
127
134 {
135 string strVal;
137
138 if ((strVal = rp.FindValue("value")) != null)
139 p.value = ParseDouble(strVal);
140
141 if ((strVal = rp.FindValue("operation")) != null)
142 {
143 if (strVal == ScalarOp.MUL.ToString())
144 p.m_op = ScalarOp.MUL;
145 else if (strVal == ScalarOp.ADD.ToString())
146 p.m_op = ScalarOp.ADD;
147 else
148 throw new Exception("Unknown scalar operation '" + strVal + "'");
149 }
150
151 if ((strVal = rp.FindValue("passthrough_gradient")) != null)
152 p.passthrough_gradient = bool.Parse(strVal);
153
154 return p;
155 }
156 }
157}
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
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
The LayerParameterBase is the base class for all other layer specific parameters.
Specifies the parameters for the ScalarLayer
double value
Specifies the scalar value to apply.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
ScalarOp operation
Specifies the scalar operation to apply (mul, add, etc).
bool passthrough_gradient
Specifies whether or not to pass-through the gradient without performing the back-prop calculation (d...
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
ScalarOp
Defines the scalar operations that may be performed.
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
static ScalarParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe.param.nt namespace defines the parameters used by the Nerual Style Transfer layers.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12