MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
LabelMappingParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.db.image;
7using MyCaffe.basecode;
8
9namespace MyCaffe.param
10{
14 [Serializable]
15 [TypeConverter(typeof(ExpandableObjectConverter))]
17 {
19 bool m_bUpdateDatabase = false;
20 bool m_bResetDatabaseLabels = false;
21 string m_strLabelBoosts = "";
22
25 {
26 }
27
31 [Description("Specifies the label mapping where the original label is mapped to the new label specified.")]
32 public List<LabelMapping> mapping
33 {
34 get { return m_rgMapping.Mappings; }
35 set { m_rgMapping.Mappings = value; }
36 }
37
41 [Description("Specifies whether or not to directly update the database with the label mapping for the data source used - when 'false' only the 'in-memory' labels are updated. WARNING: Updating the database sets the label mapping globally and will impact all other projects using this data source.")]
42 public bool update_database
43 {
44 get { return m_bUpdateDatabase; }
45 set { m_bUpdateDatabase = value; }
46 }
47
51 [Description("Specifies whether or not to reset the database labels to the original label values for the data source used. WARNING: This resets the labels globally to their original setting and will impact all other projects using this data source.")]
53 {
54 get { return m_bResetDatabaseLabels; }
55 set { m_bResetDatabaseLabels = value; }
56 }
57
61 [Description("DEPRECIATED: Specifies the labels for which the label boost is to be set. When set, all labels specified are given a boost such that images are selected with equal probability between all labels specified.")]
62 public string label_boosts
63 {
64 get { return m_strLabelBoosts; }
65 set { m_strLabelBoosts = value; }
66 }
67
73 public int MapLabel(int nLabel)
74 {
75 return m_rgMapping.MapLabelWithoutBoost(nLabel);
76 }
77
79 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
80 {
81 RawProto proto = RawProto.Parse(br.ReadString());
83
84 if (!bNewInstance)
85 Copy(p);
86
87 return p;
88 }
89
91 public override void Copy(LayerParameterBase src)
92 {
94
95 m_rgMapping = p.m_rgMapping.Clone();
96 m_bUpdateDatabase = p.m_bUpdateDatabase;
97 m_bResetDatabaseLabels = p.m_bResetDatabaseLabels;
98 m_strLabelBoosts = p.m_strLabelBoosts;
99 }
100
102 public override LayerParameterBase Clone()
103 {
105 p.Copy(this);
106 return p;
107 }
108
114 public override RawProto ToProto(string strName)
115 {
116 RawProtoCollection rgChildren = new RawProtoCollection();
117
118 rgChildren.Add<string>("mapping", m_rgMapping.ToStringList());
119
120 if (m_bUpdateDatabase)
121 rgChildren.Add(new RawProto("update_database", (m_bUpdateDatabase) ? "true" : "false"));
122
123 if (m_bResetDatabaseLabels)
124 rgChildren.Add(new RawProto("reset_database_labels", (m_bResetDatabaseLabels) ? "true" : "false"));
125
126 if (m_strLabelBoosts != null && m_strLabelBoosts.Length > 0)
127 rgChildren.Add(new RawProto("label_boosts", m_strLabelBoosts));
128
129 return new RawProto(strName, "", rgChildren);
130 }
131
138 {
140
141 p.m_rgMapping = LabelMappingCollection.Parse(rp.FindArray<string>("mapping"));
142
143 string strUpdateDb = rp.FindValue("update_database");
144 if (strUpdateDb != null && strUpdateDb.ToLower() == "true")
145 p.m_bUpdateDatabase = true;
146
147 string strReset = rp.FindValue("reset_database_labels");
148 if (strReset != null && strReset.ToLower() == "true")
149 p.m_bResetDatabaseLabels = true;
150
151 p.m_strLabelBoosts = rp.FindValue("label_boosts");
152 if (p.m_strLabelBoosts == null)
153 p.m_strLabelBoosts = "";
154
155 return p;
156 }
157 }
158}
The LabelMappingCollection manages a collection of LabelMapping's.
Definition: LabelMapping.cs:15
List< string > ToStringList()
Returns a list of strings where each entry represents a mapping.
static LabelMappingCollection Parse(string strMappings)
Parses a label mapping string into a collection of label mappings.
List< LabelMapping > Mappings
Returns the label mapping list.
Definition: LabelMapping.cs:37
LabelMappingCollection Clone()
Returns a copy of the label mapping collection.
Definition: LabelMapping.cs:83
int MapLabelWithoutBoost(int nLabel)
Returns the mapped label associated with a given label.
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
/b DEPRECIATED (use DataLayer DataLabelMappingParameter instead) Specifies the parameters for the Lab...
static LabelMappingParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
string label_boosts
DEPRECIATED: Specifies the labels for which the label boost is to be set. When set,...
bool reset_database_labels
Specifies whether or not to reset the database labels to the original label values for the data sourc...
LabelMappingParameter()
Constructor for the parameter.
override void Copy(LayerParameterBase src)
Copy on parameter to another.
List< LabelMapping > mapping
Specifies the label mapping where the original label is mapped to the new label specified.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
bool update_database
Specifies whether or not to directly update the database with the label mapping for the data source u...
int MapLabel(int nLabel)
Queries the mapped label for a given label.
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.db.image namespace contains all image database related classes.
Definition: Database.cs:18
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