MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
DataLabelMappingParameter.cs
1using MyCaffe.basecode;
2using System;
3using System.Collections.Generic;
5using System.IO;
6using System.Linq;
7using System.Text;
8using System.Threading.Tasks;
9
10namespace MyCaffe.param
11{
15 [Serializable]
16 [TypeConverter(typeof(ExpandableObjectConverter))]
18 {
20
25 public DataLabelMappingParameter(bool bActive) : base(bActive)
26 {
27 }
28
32 [Description("Specifies the label mapping where the original label is mapped to the new label specified.")]
33 public List<LabelMapping> mapping
34 {
35 get { return m_rgMapping.Mappings; }
36 set { m_rgMapping.Mappings = value; }
37 }
38
45 public int MapLabel(int nLabel, int nBoost)
46 {
47 return m_rgMapping.MapLabel(nLabel, nBoost);
48 }
49
56 public DataLabelMappingParameter Load(BinaryReader br, bool bNewInstance = true)
57 {
58 RawProto proto = RawProto.Parse(br.ReadString());
60
61 if (!bNewInstance)
62 Copy(p);
63
64 return p;
65 }
66
71 public override void Copy(OptionalParameter src)
72 {
73 base.Copy(src);
74
76 {
78 m_rgMapping = p.m_rgMapping.Clone();
79 }
80 }
81
87 {
89 p.Copy(this);
90 return p;
91 }
92
93
99 public override RawProto ToProto(string strName)
100 {
101 RawProto rpBase = base.ToProto("option");
102 RawProtoCollection rgChildren = new RawProtoCollection();
103
104 rgChildren.Add(rpBase);
105 rgChildren.Add<string>("mapping", m_rgMapping.ToStringList());
106
107 return new RawProto(strName, "", rgChildren);
108 }
109
110
117 {
119
120 RawProto rpOption = rp.FindChild("option");
121 if (rpOption != null)
122 ((OptionalParameter)p).Copy(OptionalParameter.FromProto(rpOption));
123
124 p.m_rgMapping = LabelMappingCollection.Parse(rp.FindArray<string>("mapping"));
125
126 return p;
127 }
128 }
129}
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
int MapLabel(int nLabel, int nBoost)
Returns the mapped label associated with a given label and boost (if a boost condition is used).
LabelMappingCollection Clone()
Returns a copy of the label mapping collection.
Definition: LabelMapping.cs:83
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
Specifies the parameters for the DataLabelMappingParameter used to map labels by the DataTransformer....
DataLabelMappingParameter Clone()
Return a copy of this object.
override RawProto ToProto(string strName)
Convert the DataLabelMappingParameter into a RawProto.
List< LabelMapping > mapping
Specifies the label mapping where the original label is mapped to the new label specified.
DataLabelMappingParameter(bool bActive)
The constructor.
static new DataLabelMappingParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
DataLabelMappingParameter Load(BinaryReader br, bool bNewInstance=true)
Load the and return a new DataLabelMappingParameter.
override void Copy(OptionalParameter src)
Copies the specified source data label mapping parameter to this one.
int MapLabel(int nLabel, int nBoost)
Queries the mapped label for a given label.
The OptionalParameter is the base class for parameters that are optional such as the MaskParameter,...
static OptionalParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
OptionalParameter(bool bActive=false)
The constructor.
bool Active
When active, the parameter is used, otherwise it is ignored.
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