4using System.Collections.Generic;
8using System.Threading.Tasks;
20 [TypeConverter(typeof(ExpandableObjectConverter))]
23 List<LabelMapItem> m_rgItems =
new List<LabelMapItem>();
41 if (li.
label == nLabel)
57 if (li.
name == strName)
71 public Dictionary<int, string>
MapToName(
Log log,
bool bStrict,
bool bDisplayName)
73 Dictionary<int, string> rgLabelToName =
new Dictionary<int, string>();
75 for (
int i = 0; i < m_rgItems.Count; i++)
77 string strName = (bDisplayName) ? m_rgItems[i].display : m_rgItems[i].name;
78 int nLabel = m_rgItems[i].label;
82 if (rgLabelToName.ContainsKey(nLabel))
83 log.
FAIL(
"There are duplicates of the label: " + nLabel.ToString());
85 rgLabelToName.Add(nLabel, strName);
89 if (rgLabelToName.ContainsKey(nLabel))
90 rgLabelToName[nLabel] = strName;
92 rgLabelToName.Add(nLabel, strName);
107 Dictionary<string, int> rgNameToLabel =
new Dictionary<string, int>();
109 for (
int i = 0; i < m_rgItems.Count; i++)
111 string strName = m_rgItems[i].name;
112 int nLabel = m_rgItems[i].label;
116 if (rgNameToLabel.ContainsKey(strName))
117 log.
FAIL(
"There are duplicates of the name: " + strName.ToLower());
119 rgNameToLabel.Add(strName, nLabel);
123 if (rgNameToLabel.ContainsKey(strName))
124 rgNameToLabel[strName] = nLabel;
126 rgNameToLabel.Add(strName, nLabel);
130 return rgNameToLabel;
138 get {
return m_rgItems; }
147 m_rgItems =
new List<LabelMapItem>();
151 m_rgItems.Add(
item.Clone());
178 col.Add(
item.ToProto(
"item"));
183 return new RawProto(strName,
"", rgChildren);
221 public LabelMapItem(
int nLabel = 0,
string strName =
null,
string strDisplay =
null)
225 m_strDisplay = strDisplay;
233 get {
return m_strName; }
234 set { m_strName = value; }
242 get {
return m_strDisplay; }
243 set { m_strDisplay = value; }
251 get {
return m_nLabel; }
252 set { m_nLabel = value; }
261 m_strName = src.m_strName;
262 m_strDisplay = src.m_strDisplay;
263 m_nLabel = src.m_nLabel;
272 return new LabelMapItem(m_nLabel, m_strName, m_strDisplay);
285 rgChildren.
Add(
new RawProto(
"label", m_nLabel.ToString()));
287 if (!
string.IsNullOrEmpty(m_strDisplay))
288 rgChildren.
Add(
new RawProto(
"display", m_strDisplay));
290 return new RawProto(strName,
"", rgChildren);
303 if ((strVal = rp.
FindValue(
"name")) !=
null)
306 if ((strVal = rp.
FindValue(
"label")) !=
null)
307 item.
label =
int.Parse(strVal);
309 if ((strVal = rp.
FindValue(
"display")) !=
null)
The Log class provides general output in text form.
void FAIL(string str)
Causes a failure which throws an exception with the desciptive text.
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.
string FindValue(string strName)
Searches for a falue of a node within this nodes children.
RawProtoCollection FindChildren(params string[] rgstrName)
Searches for all children with a given name in this node's children.
Specifies the LabelMap used with SSD.
Dictionary< string, int > MapToLabel(Log log, bool bStrict)
Map the names to their labels.
LabelMap()
The constructor.
LabelMapItem FindByLabel(int nLabel)
Find a label with its label id.
Dictionary< int, string > MapToName(Log log, bool bStrict, bool bDisplayName)
Map the labels into a dictionary.
List< LabelMapItem > item
Specifies the list of label items.
RawProto ToProto(string strName)
Convert this object to a raw proto.
LabelMapItem FindByName(string strName)
Find a label with a given name.
static LabelMap FromProto(RawProto rp)
Parses the parameter from a RawProto.
LabelMap Clone()
Return a copy of this object.
void Copy(LabelMap src)
Copy the source object.
The LabelMapItem class stores the information for a single label.
int label
Get/set the label id.
LabelMapItem Clone()
Return a copy of this object.
string name
Get/set the label name.
RawProto ToProto(string strName)
Convert this object to a raw proto.
void Copy(LabelMapItem src)
Copy the source object.
LabelMapItem(int nLabel=0, string strName=null, string strDisplay=null)
The constructor.
static LabelMapItem FromProto(RawProto rp)
Parses the parameter from a RawProto.
string display
Optionally, get/set the display name for the label.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
The MyCaffe.param.ssd namespace contains all SSD related parameter objects that correspond to the nat...
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...