MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
NetStateRule.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.IO;
7using MyCaffe.basecode;
8using MyCaffe.common;
9using System.Drawing.Design;
10using MyCaffe.param.ui;
11
12namespace MyCaffe.param
13{
17 [Serializable]
18 [TypeConverter(typeof(ExpandableObjectConverter))]
19 public class NetStateRule : BaseParameter, ICloneable, IComparable, IBinaryPersist
20 {
21 Phase m_phase = Phase.NONE;
22 int? m_nMinLevel = null;
23 int? m_nMaxLevel = null;
24 List<string> m_rgStage = new List<string>();
25 List<string> m_rgNotStage = new List<string>();
26
30 public NetStateRule()
31 {
32 }
33
39 {
40 m_phase = p;
41 }
42
47 public void Save(BinaryWriter bw)
48 {
49 bw.Write((int)m_phase);
50
51 bw.Write(m_nMinLevel.HasValue);
52 if (m_nMinLevel.HasValue)
53 bw.Write(m_nMinLevel.Value);
54
55 bw.Write(m_nMaxLevel.HasValue);
56 if (m_nMaxLevel.HasValue)
57 bw.Write(m_nMaxLevel.Value);
58
59 Utility.Save<string>(bw, m_rgStage);
60 Utility.Save<string>(bw, m_rgNotStage);
61 }
62
69 public object Load(BinaryReader br, bool bNewInstance)
70 {
71 NetStateRule p = this;
72
73 if (bNewInstance)
74 p = new NetStateRule();
75
76 p.m_phase = (Phase)br.ReadInt32();
77
78 if (br.ReadBoolean())
79 p.m_nMinLevel = br.ReadInt32();
80
81 if (br.ReadBoolean())
82 p.m_nMaxLevel = br.ReadInt32();
83
84 p.m_rgStage = Utility.Load<string>(br);
85 p.m_rgNotStage = Utility.Load<string>(br);
86
87 return p;
88 }
89
97 [Description("Specifies the phase required to meet this rule.")]
98 public Phase phase
99 {
100 get { return m_phase; }
101 set { m_phase = value; }
102 }
103
108 [Description("Specifies the minimum level in which the layer should be used.")]
109 public int? min_level
110 {
111 get { return m_nMinLevel; }
112 set { m_nMinLevel = value; }
113 }
114
119 [Description("Specifies the maximum level in which the layer should be used.")]
120 public int? max_level
121 {
122 get { return m_nMaxLevel; }
123 set { m_nMaxLevel = value; }
124 }
125
132 [Description("Specifies the stage required to meet this rule.")]
133 [Editor(@"System.Windows.Forms.Design.StringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(System.Drawing.Design.UITypeEditor))]
134 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
135 [TypeConverter(typeof(CsvConverter))]
136 public List<string> stage
137 {
138 get { return m_rgStage; }
139 set { m_rgStage = value; }
140 }
141
148 [Description("Specifies the 'not_stage' that cannot be specified to meet this rule.")]
149 [Editor(@"System.Windows.Forms.Design.StringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(System.Drawing.Design.UITypeEditor))]
150 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
151 [TypeConverter(typeof(CsvConverter))]
152 public List<string> not_stage
153 {
154 get { return m_rgNotStage; }
155 set { m_rgNotStage = value; }
156 }
157
162 public object Clone()
163 {
164 NetStateRule ns = new NetStateRule();
165
166 ns.m_nMaxLevel = m_nMaxLevel;
167 ns.m_nMinLevel = m_nMinLevel;
168 ns.m_phase = m_phase;
169 ns.m_rgNotStage = Utility.Clone<string>(m_rgNotStage);
170 ns.m_rgStage = Utility.Clone<string>(m_rgStage);
171
172 return ns;
173 }
174
180 public override RawProto ToProto(string strName)
181 {
182 RawProtoCollection rgChildren = new RawProtoCollection();
183
184 rgChildren.Add("phase", phase.ToString());
185
186 if (min_level.HasValue)
187 rgChildren.Add("min_level", min_level);
188
189 if (max_level.HasValue)
190 rgChildren.Add("max_level", max_level);
191
192 if (stage.Count > 0)
193 rgChildren.Add<string>("stage", stage);
194
195 if (not_stage.Count > 0)
196 rgChildren.Add<string>("not_stage", not_stage);
197
198 return new RawProto(strName, "", rgChildren);
199 }
200
207 {
208 string strVal;
209 NetStateRule p = new NetStateRule();
210
211 if ((strVal = rp.FindValue("phase")) != null)
212 {
213 switch (strVal)
214 {
215 case "TEST":
216 p.phase = Phase.TEST;
217 break;
218
219 case "TRAIN":
220 p.phase = Phase.TRAIN;
221 break;
222
223 case "RUN":
224 p.phase = Phase.RUN;
225 break;
226
227 case "NONE":
228 p.phase = Phase.NONE;
229 break;
230
231 case "ALL":
232 p.phase = Phase.ALL;
233 break;
234
235 default:
236 throw new Exception("Unknown 'phase' value: " + strVal);
237 }
238 }
239
240 p.min_level = (int?)rp.FindValue("min_level", typeof(int));
241 p.max_level = (int?)rp.FindValue("max_level", typeof(int));
242 p.stage = rp.FindArray<string>("stage");
243 p.not_stage = rp.FindArray<string>("not_stage");
244
245 return p;
246 }
247
253 public int CompareTo(object obj)
254 {
255 NetStateRule nsr = obj as NetStateRule;
256
257 if (nsr == null)
258 return 1;
259
260 if (!Compare(nsr))
261 return 1;
262
263 return 0;
264 }
265 }
266}
The BaseParameter class is the base class for all other parameter classes.
virtual bool Compare(BaseParameter p)
Compare this parameter to another parameter.
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
string FindValue(string strName)
Searches for a falue of a node within this nodes children.
Definition: RawProto.cs:105
The Utility class provides general utility funtions.
Definition: Utility.cs:35
static void Save(BinaryWriter bw, List< double > rg)
Save a list of double to a binary writer.
Definition: Utility.cs:337
Specifies a NetStateRule used to determine whether a Net falls within a given include or exclude patt...
Definition: NetStateRule.cs:20
override RawProto ToProto(string strName)
Converts a NetStateRule into a RawProto.
NetStateRule(Phase p)
Specifies the NetStateRule constructor.
Definition: NetStateRule.cs:38
NetStateRule()
Specifies the NetStateRule constructor.
Definition: NetStateRule.cs:30
List< string > stage
Customizable sets of stages to include. The net must have ALL of the specified stages and NONE of the...
static NetStateRule FromProto(RawProto rp)
Parses a RawProto representing a NetStateRule and creates a new instance of a NetStateRule from it.
object Load(BinaryReader br, bool bNewInstance)
Loads a NetStateRule from a binary reader.
Definition: NetStateRule.cs:69
int? min_level
Set the minimum levels in which the layer should be used. Leave undefined to meet the rule regardless...
Phase phase
Set phase to require the NetState to have a particular phase (TRAIN or TEST) to meet this rule.
Definition: NetStateRule.cs:99
object Clone()
Creates a new copy of a NetStateRule instance.
int? max_level
Set the maximum levels in which the layer should be used. Leave undefined to meet the rule regardless...
List< string > not_stage
Customizable sets of stages to exclude. The net must have ALL of the specified stages and NONE of the...
void Save(BinaryWriter bw)
Saves the NetStateRule to a given binary writer.
Definition: NetStateRule.cs:47
int CompareTo(object obj)
Compares this NetStateRule to another one.
The CsvConverter is used to display string lists on a single line in a property grid.
Definition: CsvConverter.cs:15
The IBinaryPersist interface provides generic save and load functionality.
Definition: Utility.cs:16
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
Phase
Defines the Phase under which to run a Net.
Definition: Interfaces.cs:61
The MyCaffe.common namespace contains common MyCaffe classes.
Definition: BatchInput.cs:8
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