MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
LossParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using MyCaffe.basecode;
7
8namespace MyCaffe.param
9{
13 [Serializable]
14 [TypeConverter(typeof(ExpandableObjectConverter))]
16 {
17 int? m_nIgnoreLabel = null;
18 NormalizationMode? m_normalization = NormalizationMode.VALID;
19 bool m_bNormalize = false;
20
27 {
33 FULL = 0,
34
39 VALID = 1,
40
44 BATCH_SIZE = 2,
45
49 NONE = 3
50 }
51
62 {
63 m_normalization = norm;
64 }
65
69 [Description("Ignore instances with the given label, when specified.")]
70 public int? ignore_label
71 {
72 get { return m_nIgnoreLabel; }
73 set { m_nIgnoreLabel = value; }
74 }
75
79 [Description("Specifies the normalization mode to use (default = VALID).")]
81 {
82 get { return m_normalization; }
83 set { m_normalization = value; }
84 }
85
91 [Description("DEPRECIATED - use 'normalization == BATCH_SIZE' instead.")]
92 [Browsable(false)]
93 public bool normalize
94 {
95 get { return m_bNormalize; }
96 set { m_bNormalize = value; }
97 }
98
100 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
101 {
102 RawProto proto = RawProto.Parse(br.ReadString());
103 LossParameter p = FromProto(proto);
104
105 if (!bNewInstance)
106 Copy(p);
107
108 return p;
109 }
110
112 public override void Copy(LayerParameterBase src)
113 {
115
116 m_nIgnoreLabel = p.m_nIgnoreLabel;
117 m_normalization = p.m_normalization;
118 m_bNormalize = p.m_bNormalize;
119 }
120
122 public override LayerParameterBase Clone()
123 {
125 p.Copy(this);
126 return p;
127 }
128
134 public override RawProto ToProto(string strName)
135 {
136 RawProtoCollection rgChildren = new RawProtoCollection();
137
138 if (ignore_label.HasValue)
139 rgChildren.Add("ignore_label", ignore_label);
140
141 rgChildren.Add("normalization", normalization.ToString());
142
143 if (normalization == NormalizationMode.NONE && normalize != false)
144 rgChildren.Add("normalize", normalize.ToString());
145
146 return new RawProto(strName, "", rgChildren);
147 }
148
155 {
156 string strVal;
158
159 p.ignore_label = (int?)rp.FindValue("ignore_label", typeof(int));
160
161 if ((strVal = rp.FindValue("normalization")) != null)
162 {
163 switch (strVal)
164 {
165 case "FULL":
167 break;
168
169 case "VALID":
171 break;
172
173 case "BATCH_SIZE":
174 p.normalization = NormalizationMode.BATCH_SIZE;
175 break;
176
177 case "NONE":
179 break;
180
181 default:
182 throw new Exception("Unknown 'normalization' value: " + strVal);
183 }
184 }
185
186 if ((strVal = rp.FindValue("normalize")) != null)
187 p.normalize = bool.Parse(strVal);
188
189 return p;
190 }
191 }
192}
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.
Stores the parameters used by loss layers.
NormalizationMode
How to normalize the loss for loss layers that aggregate across batches, spatial dimensions,...
static LossParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
bool normalize
DEPRECIATED. Ignore if normalization is specified. If normalization is not specified,...
NormalizationMode? normalization
Specifies the normalization mode (default = VALID).
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
LossParameter(NormalizationMode norm=NormalizationMode.VALID)
The constructor for the LossParameter.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
int? ignore_label
If specified, the ignore instances with the given label.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
@ NONE
No training category specified.
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