MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
TextDataParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.basecode;
7
8namespace MyCaffe.param
9{
13 [Serializable]
14 [TypeConverter(typeof(ExpandableObjectConverter))]
16 {
17 string m_strEncoderSource = null;
18 string m_strDecoderSource = null;
19 uint m_nBatchSize = 1;
20 uint m_nTimeSteps = 80;
21 uint m_nSampleSize = 1000;
22 bool m_bShuffle = true;
23 bool m_bEnableNormalEncoderOutput = true;
24 bool m_bEnableReverseEncoderOutput = true;
25
29 public event EventHandler<VerifyBatchSizeArgs> OnVerifyBatchSize;
30
33 {
34 }
35
41 public override string PrepareRunModelInputs()
42 {
43 string strInput = "";
44 int nBatch = (int)m_nBatchSize;
45
46 strInput += "input: \"idec\"" + Environment.NewLine;
47 strInput += "input_shape { dim: 1 dim: " + nBatch.ToString() + " dim: 1 } " + Environment.NewLine;
48
49 strInput += "input: \"ienc\"" + Environment.NewLine;
50 strInput += "input_shape { dim: " + m_nTimeSteps.ToString() + " dim: " + nBatch.ToString() + " dim: 1 } " + Environment.NewLine;
51
52 strInput += "input: \"iencr\"" + Environment.NewLine;
53 strInput += "input_shape { dim: " + m_nTimeSteps.ToString() + " dim: " + nBatch.ToString() + " dim: 1 } " + Environment.NewLine;
54
55 strInput += "input: \"iencc\"" + Environment.NewLine;
56 strInput += "input_shape { dim: " + m_nTimeSteps.ToString() + " dim: " + nBatch.ToString() + " } " + Environment.NewLine;
57
58 return strInput;
59 }
60
64 public override void PrepareRunModel(LayerParameter p)
65 {
66 p.bottom.Add("idec");
67 p.bottom.Add("ienc");
68 p.bottom.Add("iencr");
69 p.bottom.Add("iencc");
70 }
71
75 [Description("Specifies the encoder data source.")]
76 public string encoder_source
77 {
78 get { return m_strEncoderSource; }
79 set { m_strEncoderSource = value; }
80 }
81
85 [Description("Specifies the decoder data source.")]
86 public string decoder_source
87 {
88 get { return m_strDecoderSource; }
89 set { m_strDecoderSource = value; }
90 }
91
95 [Description("Specifies the batch size of images to collect and train on each iteration of the network. NOTE: Setting the training netorks batch size >= to the testing net batch size will conserve memory by allowing the training net to share its gpu memory with the testing net.")]
96 public virtual uint batch_size
97 {
98 get { return m_nBatchSize; }
99 set
100 {
101 if (OnVerifyBatchSize != null)
102 {
104 OnVerifyBatchSize(this, args);
105 if (args.Error != null)
106 throw args.Error;
107 }
108
109 m_nBatchSize = value;
110 }
111 }
112
116 [Description("Specifies the maximum length for the encoder inputs.")]
117 public uint time_steps
118 {
119 get { return m_nTimeSteps; }
120 set { m_nTimeSteps = value; }
121 }
122
126 [Description("Specifies the sample size to select from the data sources.")]
127 public uint sample_size
128 {
129 get { return m_nSampleSize; }
130 set { m_nSampleSize = value; }
131 }
132
136 [Description("Specifies whether to shuffle the data or not.")]
137 public bool shuffle
138 {
139 get { return m_bShuffle; }
140 set { m_bShuffle = value; }
141 }
142
146 [Description("When enabled, the normal ordered encoder data is output (default = true).")]
148 {
149 get { return m_bEnableNormalEncoderOutput; }
150 set { m_bEnableNormalEncoderOutput = value; }
151 }
152
156 [Description("When enabled, the reverse ordered encoder data is output (default = true).")]
158 {
159 get { return m_bEnableReverseEncoderOutput; }
160 set { m_bEnableReverseEncoderOutput = value; }
161 }
162
164 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
165 {
166 RawProto proto = RawProto.Parse(br.ReadString());
167 TextDataParameter p = FromProto(proto);
168
169 if (!bNewInstance)
170 Copy(p);
171
172 return p;
173 }
174
176 public override void Copy(LayerParameterBase src)
177 {
179 m_strEncoderSource = p.m_strEncoderSource;
180 m_strDecoderSource = p.m_strDecoderSource;
181 m_nBatchSize = p.m_nBatchSize;
182 m_nTimeSteps = p.m_nTimeSteps;
183 m_nSampleSize = p.m_nSampleSize;
184 m_bShuffle = p.m_bShuffle;
185 m_bEnableNormalEncoderOutput = p.m_bEnableNormalEncoderOutput;
186 m_bEnableReverseEncoderOutput = p.m_bEnableReverseEncoderOutput;
187 }
188
190 public override LayerParameterBase Clone()
191 {
193 p.Copy(this);
194 return p;
195 }
196
202 public override RawProto ToProto(string strName)
203 {
204 RawProtoCollection rgChildren = new RawProtoCollection();
205
206 rgChildren.Add("encoder_source", "\"" + encoder_source + "\"");
207 rgChildren.Add("decoder_source", "\"" + decoder_source + "\"");
208 rgChildren.Add("batch_size", batch_size.ToString());
209 rgChildren.Add("time_steps", time_steps.ToString());
210 rgChildren.Add("sample_size", sample_size.ToString());
211 rgChildren.Add("shuffle", shuffle.ToString());
212 rgChildren.Add("enable_normal_encoder_output", enable_normal_encoder_output.ToString());
213 rgChildren.Add("enable_reverse_encoder_output", enable_reverse_encoder_output.ToString());
214
215 return new RawProto(strName, "", rgChildren);
216 }
217
225 {
226 string strVal;
227
228 if (p == null)
229 p = new TextDataParameter();
230
231 if ((strVal = rp.FindValue("encoder_source")) != null)
232 p.encoder_source = strVal.Trim('\"');
233
234 if ((strVal = rp.FindValue("decoder_source")) != null)
235 p.decoder_source = strVal.Trim('\"');
236
237 if ((strVal = rp.FindValue("batch_size")) != null)
238 p.batch_size = uint.Parse(strVal);
239
240 if ((strVal = rp.FindValue("time_steps")) != null)
241 p.time_steps = uint.Parse(strVal);
242
243 if ((strVal = rp.FindValue("shuffle")) != null)
244 p.shuffle = bool.Parse(strVal);
245
246 if ((strVal = rp.FindValue("enable_normal_encoder_output")) != null)
247 p.enable_normal_encoder_output = bool.Parse(strVal);
248
249 if ((strVal = rp.FindValue("enable_reverse_encoder_output")) != null)
250 p.enable_reverse_encoder_output = bool.Parse(strVal);
251
252 return p;
253 }
254 }
255}
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 base parameter for all layers.
List< string > bottom
Specifies the active bottom connections (in the bottom, out the top).
Specifies the parameter for the Text data layer.
TextDataParameter()
Constructor for the parameter.
override void PrepareRunModel(LayerParameter p)
This method gives derivative classes a chance modify the layer parameter for a run model.
bool enable_reverse_encoder_output
When enabled, the reverse ordered encoder data is output (default = true).
uint sample_size
Specifies the sample size to select from the data sources.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
EventHandler< VerifyBatchSizeArgs > OnVerifyBatchSize
This event is, optionally, called to verify the batch size of the TextDataParameter.
uint time_steps
Specifies the maximum length for each encoder input.
override string PrepareRunModelInputs()
This method gives derivative classes a chance specify model inputs required by the run model.
bool shuffle
Specifies the whether to shuffle the data or now.
bool enable_normal_encoder_output
When enabled, the normal ordered encoder data is output (default = true).
string decoder_source
Specifies the decoder data source.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
virtual uint batch_size
Specifies the batch size.
string encoder_source
Specifies the encoder data source.
static TextDataParameter FromProto(RawProto rp, TextDataParameter p=null)
Parses the parameter from a RawProto.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
The VerifyBatchSizeArgs class defines the arguments of the OnVerifyBatchSize event.
Exception Error
Get/set the error value. For example if the receiver of the event determines that the batch size is i...
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
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