MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
GramParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using MyCaffe.basecode;
7
18{
26 [Serializable]
27 [TypeConverter(typeof(ExpandableObjectConverter))]
29 {
30 int m_nAxis = 2;
31 double m_dfAlpha = 1.0;
32 double m_dfBeta = 1.0;
33 bool m_bDisableScalingOnGradient = false;
34
39 {
40 }
41
49 [Description("The first axis to be lumped into a single Gram matrix computation -- may be negative to index from end (e.g., -1 for the last axis). For example, if axis == 2 and the input is (N x C x H x W), the output will be (N x C x C).")]
50 public int axis
51 {
52 get { return m_nAxis; }
53 set { m_nAxis = value; }
54 }
55
59 public double alpha
60 {
61 get { return m_dfAlpha; }
62 set { m_dfAlpha = value; }
63 }
64
68 public double beta
69 {
70 get { return m_dfBeta; }
71 set { m_dfBeta = value; }
72 }
73
78 {
79 get { return m_bDisableScalingOnGradient; }
80 set { m_bDisableScalingOnGradient = value; }
81 }
82
89 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
90 {
91 RawProto proto = RawProto.Parse(br.ReadString());
92 GramParameter p = FromProto(proto);
93
94 if (!bNewInstance)
95 Copy(p);
96
97 return p;
98 }
99
104 public override void Copy(LayerParameterBase src)
105 {
107 m_nAxis = p.m_nAxis;
108 m_dfAlpha = p.m_dfAlpha;
109 m_dfBeta = p.m_dfBeta;
110 m_bDisableScalingOnGradient = p.m_bDisableScalingOnGradient;
111 }
112
117 public override LayerParameterBase Clone()
118 {
120 p.Copy(this);
121 return p;
122 }
123
129 public override RawProto ToProto(string strName)
130 {
131 RawProtoCollection rgChildren = new RawProtoCollection();
132
133 rgChildren.Add("axis", axis.ToString());
134 rgChildren.Add("alpha", alpha.ToString());
135 rgChildren.Add("beta", beta.ToString());
136 rgChildren.Add("disable_scaling_on_gradient", disable_scaling_on_gradient.ToString());
137
138 return new RawProto(strName, "", rgChildren);
139 }
140
147 {
148 string strVal;
150
151 if ((strVal = rp.FindValue("axis")) != null)
152 p.axis = int.Parse(strVal);
153
154 if ((strVal = rp.FindValue("alpha")) != null)
155 p.alpha = ParseDouble(strVal);
156
157 if ((strVal = rp.FindValue("beta")) != null)
158 p.beta = ParseDouble(strVal);
159
160 if ((strVal = rp.FindValue("disable_scaling_on_gradient")) != null)
161 p.disable_scaling_on_gradient = bool.Parse(strVal);
162
163 return p;
164 }
165 }
166}
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 GramLayer
static GramParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
double beta
Specifies the scaling factor applied after the gram operation.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
bool disable_scaling_on_gradient
Specifies whether or not to apply the un-scaling of the alpha and beta values during the during the b...
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
double alpha
Specifies the scaling factor applied before the gram operation.
GramParameter()
The constructor.
int axis
The first axis to be lumped into a single Gram matrix computation; all preceding axes are retained in...
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