MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
ConstantParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using MyCaffe.basecode;
7using System.Configuration;
8
9namespace MyCaffe.param
10{
14 [Serializable]
15 [TypeConverter(typeof(ExpandableObjectConverter))]
17 {
18 BlobShape m_outputShape = new BlobShape();
19 List<float> m_rgF = new List<float>();
20 string m_strBinaryDataFile = null;
21
24 {
25 }
26
30 [Description("Specifies the output shape.")]
32 {
33 get { return m_outputShape; }
34 set { m_outputShape = value; }
35 }
36
48 [Description("Specifies a binary data file containing the values to load.")]
49 public string binary_data_file
50 {
51 get { return m_strBinaryDataFile; }
52 set { m_strBinaryDataFile = value; }
53 }
54
58 [Description("Specifies a set of float values used to fill the output. When only one item is specified, all outputs are set to that value.")]
59 public List<float> values_f
60 {
61 get { return m_rgF; }
62 set { m_rgF = value; }
63 }
64
71 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
72 {
73 RawProto proto = RawProto.Parse(br.ReadString());
75
76 if (!bNewInstance)
77 Copy(p);
78
79 return p;
80 }
81
86 public override void Copy(LayerParameterBase src)
87 {
89 m_outputShape = p.output_shape.Clone();
90 m_rgF = new List<float>(p.m_rgF);
91 m_strBinaryDataFile = p.binary_data_file;
92 }
93
98 public override LayerParameterBase Clone()
99 {
101 p.Copy(this);
102 return p;
103 }
104
105 private static string replace(string str, char chTarget, char chReplace)
106 {
107 string strOut = "";
108
109 foreach (char ch in str)
110 {
111 if (ch == chTarget)
112 strOut += chReplace;
113 else
114 strOut += ch;
115 }
116
117 return strOut;
118 }
119
120
126 public override RawProto ToProto(string strName)
127 {
128 RawProtoCollection rgChildren = new RawProtoCollection();
129
130 rgChildren.Add(m_outputShape.ToProto("output_shape"));
131 rgChildren.Add<float>("valuef", m_rgF);
132
133 if (!string.IsNullOrEmpty(m_strBinaryDataFile))
134 rgChildren.Add("binary_data_file", replace(m_strBinaryDataFile, ' ', '~'));
135
136 return new RawProto(strName, "", rgChildren);
137 }
138
145 {
146 string strVal;
148
149 RawProto shape = rp.FindChild("output_shape");
150 if (shape != null)
151 p.m_outputShape = BlobShape.FromProto(shape);
152
153 p.m_rgF = rp.FindArray<float>("valuef");
154
155 strVal = rp.FindValue("binary_data_file");
156 if (strVal != null)
157 p.m_strBinaryDataFile = replace(strVal, '~', ' ');
158
159 return p;
160 }
161 }
162}
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
RawProto FindChild(string strName)
Searches for a given node.
Definition: RawProto.cs:231
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
Specifies the shape of a Blob.
Definition: BlobShape.cs:15
override RawProto ToProto(string strName)
Converts the BlobShape to a RawProto.
Definition: BlobShape.cs:153
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 parameters for the ConstantLayer.
BlobShape output_shape
Specifies the output shape.
ConstantParameter()
Constructor for the parameter.
static ConstantParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
string binary_data_file
Specifies a binary data file containing the values to load.
List< float > values_f
Specifies a set of float values used to fill the output. When only one item is specified,...
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
The LayerParameterBase is the base class for all other layer specific parameters.
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