MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
ModelDataParameter.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 List<string> m_rgstrSource = new List<string>();
18 uint m_nBatchSize = 1;
19 uint m_nTimeSteps = 80;
20 uint m_nInputDim = 5;
21 uint m_nSampleSize = 1000;
22 bool m_bShuffle = true;
23
27 public event EventHandler<VerifyBatchSizeArgs> OnVerifyBatchSize;
28
31 {
32 }
33
39 public override string PrepareRunModelInputs()
40 {
41 string strInput = "";
42 int nBatch = (int)m_nBatchSize;
43 int nInput = (int)m_nInputDim;
44
45 strInput += "input: \"idec\"" + Environment.NewLine;
46 strInput += "input_shape { dim: 1 dim: " + nBatch.ToString() + " dim: 1 } " + Environment.NewLine;
47
48 strInput += "input: \"ienc\"" + Environment.NewLine;
49 strInput += "input_shape { dim: " + m_nTimeSteps.ToString() + " dim: " + nBatch.ToString() + " dim: " + nInput.ToString() + " } " + Environment.NewLine;
50
51 strInput += "input: \"iencc\"" + Environment.NewLine;
52 strInput += "input_shape { dim: " + m_nTimeSteps.ToString() + " dim: " + nBatch.ToString() + " } " + Environment.NewLine;
53
54 return strInput;
55 }
56
60 public override void PrepareRunModel(LayerParameter p)
61 {
62 p.bottom.Add("idec");
63 p.bottom.Add("ienc");
64 p.bottom.Add("iencc");
65 }
66
70 [Description("Specifies the data 'sources' within the database. Each source must already have pre-calculated RawImageResult data within the RawImageResults table including both Results for encoder input and ExtraData for decoder input.")]
71 public List<string> source
72 {
73 get { return m_rgstrSource; }
74 set { m_rgstrSource = value; }
75 }
76
80 [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.")]
81 public virtual uint batch_size
82 {
83 get { return m_nBatchSize; }
84 set
85 {
86 if (OnVerifyBatchSize != null)
87 {
89 OnVerifyBatchSize(this, args);
90 if (args.Error != null)
91 throw args.Error;
92 }
93
94 m_nBatchSize = value;
95 }
96 }
97
101 [Description("Specifies the maximum length for the encoder inputs.")]
102 public uint time_steps
103 {
104 get { return m_nTimeSteps; }
105 set { m_nTimeSteps = value; }
106 }
107
111 [Description("Specifies the input dimension the encoder inputs.")]
112 public uint input_dim
113 {
114 get { return m_nInputDim; }
115 set { m_nInputDim = value; }
116 }
117
121 [Description("Specifies the sample size to select from the data sources.")]
122 public uint sample_size
123 {
124 get { return m_nSampleSize; }
125 set { m_nSampleSize = value; }
126 }
127
131 [Description("Specifies whether to shuffle the data or now.")]
132 public bool shuffle
133 {
134 get { return m_bShuffle; }
135 set { m_bShuffle = value; }
136 }
137
139 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
140 {
141 RawProto proto = RawProto.Parse(br.ReadString());
142 ModelDataParameter p = FromProto(proto);
143
144 if (!bNewInstance)
145 Copy(p);
146
147 return p;
148 }
149
151 public override void Copy(LayerParameterBase src)
152 {
154 m_rgstrSource = Utility.Clone<string>(p.source);
155 m_nBatchSize = p.m_nBatchSize;
156 m_nTimeSteps = p.m_nTimeSteps;
157 m_nInputDim = p.m_nInputDim;
158 m_nSampleSize = p.m_nSampleSize;
159 m_bShuffle = p.m_bShuffle;
160 }
161
163 public override LayerParameterBase Clone()
164 {
166 p.Copy(this);
167 return p;
168 }
169
175 public override RawProto ToProto(string strName)
176 {
177 RawProtoCollection rgChildren = new RawProtoCollection();
178
179 rgChildren.Add<string>("source", m_rgstrSource);
180 rgChildren.Add("batch_size", batch_size.ToString());
181 rgChildren.Add("time_steps", time_steps.ToString());
182 rgChildren.Add("input_dim", input_dim.ToString());
183 rgChildren.Add("sample_size", sample_size.ToString());
184 rgChildren.Add("shuffle", shuffle.ToString());
185
186 return new RawProto(strName, "", rgChildren);
187 }
188
196 {
197 string strVal;
198
199 if (p == null)
200 p = new ModelDataParameter();
201
202 p.source = rp.FindArray<string>("source");
203
204 if ((strVal = rp.FindValue("batch_size")) != null)
205 p.batch_size = uint.Parse(strVal);
206
207 if ((strVal = rp.FindValue("time_steps")) != null)
208 p.time_steps = uint.Parse(strVal);
209
210 if ((strVal = rp.FindValue("input_dim")) != null)
211 p.input_dim = uint.Parse(strVal);
212
213 if ((strVal = rp.FindValue("shuffle")) != null)
214 p.shuffle = bool.Parse(strVal);
215
216 return p;
217 }
218 }
219}
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 Utility class provides general utility funtions.
Definition: Utility.cs:35
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 model data layer.
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
bool shuffle
Specifies the whether to shuffle the data or now.
uint time_steps
Specifies the maximum length for each encoder input.
virtual uint batch_size
Specifies the batch size.
override void PrepareRunModel(LayerParameter p)
This method gives derivative classes a chance modify the layer parameter for a run model.
override string PrepareRunModelInputs()
This method gives derivative classes a chance specify model inputs required by the run model.
List< string > source
Specifies the data 'sources' within the database. Each source must already have pre-calculated RawIma...
ModelDataParameter()
Constructor for the parameter.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
uint input_dim
Specifies the input dimension for each encoder input.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
EventHandler< VerifyBatchSizeArgs > OnVerifyBatchSize
This event is, optionally, called to verify the batch size of the TextDataParameter.
static ModelDataParameter FromProto(RawProto rp, ModelDataParameter p=null)
Parses the parameter from a RawProto.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
uint sample_size
Specifies the sample size to select from the data sources.
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