MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
KnnParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using MyCaffe.basecode;
7
14namespace MyCaffe.param.beta
15{
19 [Serializable]
20 [TypeConverter(typeof(ExpandableObjectConverter))]
22 {
23 int m_nMaxBatchesToStore = 10;
24 int m_nOutput = 10;
25 int m_nK = 100;
26
28 public KnnParameter()
29 {
30 }
31
35 [Description("Specifies the number of output items (e.g. classes).")]
36 public int num_output
37 {
38 get { return m_nOutput; }
39 set { m_nOutput = value; }
40 }
41
45 [Description("Specifies the number of nearest neighbors to compare per class, selected from items with the shortest distance. The default = 100, which selects the class with the highest count from the 10 shortest distances. It is recommended that K > ((2 * num_output) + 1) or convergence may not occur.")]
46 public int k
47 {
48 get { return m_nK; }
49 set { m_nK = value; }
50 }
51
55 [Description("Specifies the maximum number of batches to store and search for neighbors. Each batch input is stored until the maximum count is reached at which time, the oldest batch is released. A larger max value = more GPU memory used.")]
57 {
58 get { return m_nMaxBatchesToStore; }
59 set { m_nMaxBatchesToStore = value; }
60 }
61
68 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
69 {
70 RawProto proto = RawProto.Parse(br.ReadString());
71 KnnParameter p = FromProto(proto);
72
73 if (!bNewInstance)
74 Copy(p);
75
76 return p;
77 }
78
83 public override void Copy(LayerParameterBase src)
84 {
86 m_nOutput = p.m_nOutput;
87 m_nK = p.m_nK;
88 m_nMaxBatchesToStore = p.m_nMaxBatchesToStore;
89 }
90
95 public override LayerParameterBase Clone()
96 {
97 KnnParameter p = new KnnParameter();
98 p.Copy(this);
99 return p;
100 }
101
107 public override RawProto ToProto(string strName)
108 {
109 RawProtoCollection rgChildren = new RawProtoCollection();
110
111 rgChildren.Add("num_output", num_output.ToString());
112 rgChildren.Add("k", k.ToString());
113 rgChildren.Add("max_stored_batches", max_stored_batches.ToString());
114
115 return new RawProto(strName, "", rgChildren);
116 }
117
124 {
125 string strVal;
126 KnnParameter p = new KnnParameter();
127
128 if ((strVal = rp.FindValue("num_output")) != null)
129 p.num_output = int.Parse(strVal);
130
131 if ((strVal = rp.FindValue("k")) != null)
132 p.k = int.Parse(strVal);
133
134 if ((strVal = rp.FindValue("max_stored_batches")) != null)
135 p.max_stored_batches = int.Parse(strVal);
136
137 return p;
138 }
139 }
140}
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 parameters for the KnnLayer.
Definition: KnnParameter.cs:22
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
Definition: KnnParameter.cs:68
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
Definition: KnnParameter.cs:95
int max_stored_batches
Specifies the maximum number of batches to store before releasing batches.
Definition: KnnParameter.cs:57
int num_output
Specifies the number of output items (e.g. classes)
Definition: KnnParameter.cs:37
override void Copy(LayerParameterBase src)
Copy on parameter to another.
Definition: KnnParameter.cs:83
int k
Specifies the 'k' number of nearest neighbors to compare (per class).
Definition: KnnParameter.cs:47
KnnParameter()
Constructor for the parameter.
Definition: KnnParameter.cs:28
static KnnParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe.param.beta parameters are used by the MyCaffe.layer.beta layers.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12