MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
BlobShape.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.IO;
6using MyCaffe.basecode;
7using MyCaffe.common;
8
9namespace MyCaffe.param
10{
14 public class BlobShape : BaseParameter, ICloneable, IComparable, IBinaryPersist
15 {
16 List<int> m_rgDim = new List<int>();
17
21 public BlobShape()
22 {
23 }
24
32 public BlobShape(int nNum, int nC, int nH, int nW)
33 {
34 m_rgDim = new List<int>() { nNum, nC, nH, nW };
35 }
36
41 public BlobShape(List<int> rgShape)
42 {
43 m_rgDim = new List<int>();
44
45 for (int i = 0; i < rgShape.Count; i++)
46 {
47 m_rgDim.Add(rgShape[i]);
48 }
49 }
50
55 public void Save(BinaryWriter bw)
56 {
57 Utility.Save<int>(bw, m_rgDim);
58 }
59
66 public object Load(BinaryReader br, bool bNewInstance)
67 {
68 BlobShape b = this;
69
70 if (bNewInstance)
71 b = new BlobShape();
72
73 b.m_rgDim = Utility.Load<int>(br);
74
75 return b;
76 }
77
83 public static BlobShape Load(BinaryReader br)
84 {
85 BlobShape b = new BlobShape();
86 return (BlobShape)b.Load(br, true);
87 }
88
92 public List<int> dim
93 {
94 get { return m_rgDim; }
95 set { m_rgDim = new List<int>(value); }
96 }
97
103 {
104 BlobShape bs = new BlobShape();
105
106 bs.m_rgDim = Utility.Clone<int>(m_rgDim);
107
108 return bs;
109 }
110
115 object ICloneable.Clone()
116 {
117 return Clone();
118 }
119
125 public bool Compare(BlobShape bs)
126 {
127 return Utility.Compare<int>(m_rgDim, bs.m_rgDim);
128 }
129
135 public int CompareTo(object obj)
136 {
137 BlobShape bs = obj as BlobShape;
138
139 if (bs == null)
140 return 1;
141
142 if (!Compare(bs))
143 return 1;
144
145 return 0;
146 }
147
153 public override RawProto ToProto(string strName)
154 {
155 RawProtoCollection rgChildren = new RawProtoCollection();
156
157 rgChildren.Add<int>("dim", m_rgDim);
158
159 return new RawProto(strName, "", rgChildren);
160 }
161
167 public static BlobShape FromProto(RawProto rp)
168 {
169 return new BlobShape(rp.FindArray<int>("dim"));
170 }
171
176 public override string ToString()
177 {
178 string strOut = "{";
179
180 for (int i = 0; i < m_rgDim.Count; i++)
181 {
182 strOut += m_rgDim[i].ToString();
183 strOut += ",";
184 }
185
186 strOut = strOut.TrimEnd(',');
187 strOut += "}";
188
189 return strOut;
190 }
191 }
192}
The BaseParameter class is the base class for all other parameter classes.
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
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 the shape of a Blob.
Definition: BlobShape.cs:15
override string ToString()
Return the string representation of the shape.
Definition: BlobShape.cs:176
BlobShape(int nNum, int nC, int nH, int nW)
The BlobShape constructor.
Definition: BlobShape.cs:32
override RawProto ToProto(string strName)
Converts the BlobShape to a RawProto.
Definition: BlobShape.cs:153
bool Compare(BlobShape bs)
Compares this BlobShape to another.
Definition: BlobShape.cs:125
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
BlobShape()
The BlobShape constructor.
Definition: BlobShape.cs:21
object Load(BinaryReader br, bool bNewInstance)
Load the BlobShape from a binary reader.
Definition: BlobShape.cs:66
List< int > dim
The blob shape dimensions.
Definition: BlobShape.cs:93
static BlobShape Load(BinaryReader br)
Load the BlobShape from a binary reader.
Definition: BlobShape.cs:83
int CompareTo(object obj)
Compares this BlobShape to another.
Definition: BlobShape.cs:135
void Save(BinaryWriter bw)
Save the BlobShape to a binary writer.
Definition: BlobShape.cs:55
BlobShape(List< int > rgShape)
The BlobShape constructor.
Definition: BlobShape.cs:41
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
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