MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
HDF5DataParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.basecode;
7
8namespace MyCaffe.param
9{
17 [Serializable]
18 [TypeConverter(typeof(ExpandableObjectConverter))]
20 {
21 string m_strSource = null;
22 uint m_nBatchSize;
23 bool m_bShuffle;
24 List<BlobShape> m_rgExpectedTopShapes = new List<BlobShape>();
25
29 public event EventHandler<VerifyBatchSizeArgs> OnVerifyBatchSize;
30
33 {
34 }
35
39 [Description("Specifies the data source.")]
40 public string source
41 {
42 get { return m_strSource; }
43 set { m_strSource = value; }
44 }
45
49 [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.")]
50 public virtual uint batch_size
51 {
52 get { return m_nBatchSize; }
53 set
54 {
55 if (OnVerifyBatchSize != null)
56 {
58 OnVerifyBatchSize(this, args);
59 if (args.Error != null)
60 throw args.Error;
61 }
62
63 m_nBatchSize = value;
64 }
65 }
66
70 [Description("Specifies the expected top shapes. Only used to verify input shapes, if the shape is -1 or does not exist the verification test is ignored for the shape.")]
71 public List<BlobShape> expected_top_shapes
72 {
73 get { return m_rgExpectedTopShapes; }
74 set { m_rgExpectedTopShapes = value; }
75 }
76
80 [Description("Specifies whether to shuffle the data or now.")]
81 public bool shuffle
82 {
83 get { return m_bShuffle; }
84 set { m_bShuffle = value; }
85 }
86
88 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
89 {
90 RawProto proto = RawProto.Parse(br.ReadString());
92
93 if (!bNewInstance)
94 Copy(p);
95
96 return p;
97 }
98
100 public override void Copy(LayerParameterBase src)
101 {
103 m_strSource = p.m_strSource;
104 m_nBatchSize = p.m_nBatchSize;
105 m_bShuffle = p.m_bShuffle;
106
107 m_rgExpectedTopShapes = new List<BlobShape>();
108 foreach (BlobShape shape in p.m_rgExpectedTopShapes)
109 {
110 m_rgExpectedTopShapes.Add(shape.Clone());
111 }
112 }
113
115 public override LayerParameterBase Clone()
116 {
118 p.Copy(this);
119 return p;
120 }
121
127 public override RawProto ToProto(string strName)
128 {
129 RawProtoCollection rgChildren = new RawProtoCollection();
130
131 rgChildren.Add("source", "\"" + source + "\"");
132 rgChildren.Add("batch_size", batch_size.ToString());
133 rgChildren.Add("shuffle", shuffle.ToString());
134
135 for (int i = 0; i < m_rgExpectedTopShapes.Count; i++)
136 {
137 rgChildren.Add(m_rgExpectedTopShapes[i].ToProto("expected_top_shape"));
138 }
139
140 return new RawProto(strName, "", rgChildren);
141 }
142
150 {
151 string strVal;
152
153 if (p == null)
154 p = new HDF5DataParameter();
155
156 if ((strVal = rp.FindValue("source")) != null)
157 p.source = strVal.Trim('\"');
158
159 if ((strVal = rp.FindValue("batch_size")) != null)
160 p.batch_size = uint.Parse(strVal);
161
162 if ((strVal = rp.FindValue("shuffle")) != null)
163 p.shuffle = bool.Parse(strVal);
164
165 p.m_rgExpectedTopShapes = new List<BlobShape>();
166 RawProtoCollection colExpectedTopShapes = rp.FindChildren("expected_top_shape");
167 foreach (RawProto rp1 in colExpectedTopShapes)
168 {
169 p.m_rgExpectedTopShapes.Add(BlobShape.FromProto(rp1));
170 }
171
172 return p;
173 }
174 }
175}
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
RawProtoCollection FindChildren(params string[] rgstrName)
Searches for all children with a given name in this node's children.
Definition: RawProto.cs:263
Specifies the shape of a Blob.
Definition: BlobShape.cs:15
BlobShape Clone()
Creates a copy of the BlobShape.
Definition: BlobShape.cs:102
static BlobShape FromProto(RawProto rp)
Parse a new BlobShape from a RawProto.
Definition: BlobShape.cs:167
Specifies the parameter for the HDF5 data layer.
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.
string source
Specifies the data source.
virtual uint batch_size
Specifies the batch size.
HDF5DataParameter()
Constructor for the parameter.
static HDF5DataParameter FromProto(RawProto rp, HDF5DataParameter p=null)
Parses the parameter from a RawProto.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
bool shuffle
Specifies the whether to shuffle the data or now.
EventHandler< VerifyBatchSizeArgs > OnVerifyBatchSize
This event is, optionally, called to verify the batch size of the HDF5DataParameter.
List< BlobShape > expected_top_shapes
Specifies the expected top shapes. Only used to verify input shapes, if the shape is -1 or does not e...
The LayerParameterBase is the base class for all other layer specific parameters.
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