Commit 261d6a83acc8d8a3beb621f98c587385acc04206

Authored by Charles Otto
1 parent ddd731c7

Take the ground truth metadata key as input to evalClustering, default to Label

Defaulting to ClusterID did not make much sense, since the key being indexed is
in fact the ground truth, not the cluster labels (cluster labels are stored as
indices in a csv file, not a gallery).

Also, use Format to read similarity matrices instead of assuming mtx is in use.
app/br/br.cpp
@@ -138,8 +138,8 @@ public: @@ -138,8 +138,8 @@ public:
138 check(parc >= 2 && parc <= 4, "Incorrect parameter count for 'evalClassification'."); 138 check(parc >= 2 && parc <= 4, "Incorrect parameter count for 'evalClassification'.");
139 br_eval_classification(parv[0], parv[1], parc >= 3 ? parv[2] : "", parc >= 4 ? parv[3] : ""); 139 br_eval_classification(parv[0], parv[1], parc >= 3 ? parv[2] : "", parc >= 4 ? parv[3] : "");
140 } else if (!strcmp(fun, "evalClustering")) { 140 } else if (!strcmp(fun, "evalClustering")) {
141 - check(parc == 2, "Incorrect parameter count for 'evalClustering'.");  
142 - br_eval_clustering(parv[0], parv[1]); 141 + check((parc >= 2) && (parc <= 3), "Incorrect parameter count for 'evalClustering'.");
  142 + br_eval_clustering(parv[0], parv[1], parc == 3 ? parv[2] : "");
143 } else if (!strcmp(fun, "evalDetection")) { 143 } else if (!strcmp(fun, "evalDetection")) {
144 check((parc >= 2) && (parc <= 3), "Incorrect parameter count for 'evalDetection'."); 144 check((parc >= 2) && (parc <= 3), "Incorrect parameter count for 'evalDetection'.");
145 br_eval_detection(parv[0], parv[1], parc == 3 ? parv[2] : ""); 145 br_eval_detection(parv[0], parv[1], parc == 3 ? parv[2] : "");
openbr/core/cluster.cpp
@@ -100,7 +100,9 @@ Neighborhood getNeighborhood(const QStringList &amp;simmats) @@ -100,7 +100,9 @@ Neighborhood getNeighborhood(const QStringList &amp;simmats)
100 int currentRows = -1; 100 int currentRows = -1;
101 int columnOffset = 0; 101 int columnOffset = 0;
102 for (int j=0; j<numGalleries; j++) { 102 for (int j=0; j<numGalleries; j++) {
103 - cv::Mat m = BEE::readMat(simmats[i*numGalleries+j]); 103 + QScopedPointer<br::Format> format(br::Factory<br::Format>::make(simmats[i*numGalleries+j]));
  104 + br::Template t = format->read();
  105 + cv::Mat m = t.m();
104 if (j==0) { 106 if (j==0) {
105 currentRows = m.rows; 107 currentRows = m.rows;
106 allNeighbors.resize(currentRows); 108 allNeighbors.resize(currentRows);
@@ -275,13 +277,14 @@ float jaccardIndex(const QVector&lt;int&gt; &amp;indicesA, const QVector&lt;int&gt; &amp;indicesB) @@ -275,13 +277,14 @@ float jaccardIndex(const QVector&lt;int&gt; &amp;indicesA, const QVector&lt;int&gt; &amp;indicesB)
275 277
276 // Evaluates clustering algorithms based on metrics described in 278 // Evaluates clustering algorithms based on metrics described in
277 // Santo Fortunato "Community detection in graphs", Physics Reports 486 (2010) 279 // Santo Fortunato "Community detection in graphs", Physics Reports 486 (2010)
278 -void br::EvalClustering(const QString &csv, const QString &input) 280 +void br::EvalClustering(const QString &csv, const QString &input, QString truth_property)
279 { 281 {
  282 + if (truth_property.isEmpty())
  283 + truth_property = "Label";
280 qDebug("Evaluating %s against %s", qPrintable(csv), qPrintable(input)); 284 qDebug("Evaluating %s against %s", qPrintable(csv), qPrintable(input));
281 285
282 - // We assume clustering algorithms store assigned cluster labels as integers (since the clusters are  
283 - // not named). Direct use of ClusterID is not general -cao  
284 - QList<int> labels = File::get<int>(TemplateList::fromGallery(input), "ClusterID"); 286 + TemplateList tList = TemplateList::fromGallery(input);
  287 + QList<int> labels = tList.indexProperty(truth_property);
285 288
286 QHash<int, int> labelToIndex; 289 QHash<int, int> labelToIndex;
287 int nClusters = 0; 290 int nClusters = 0;
openbr/core/cluster.h
@@ -28,7 +28,7 @@ namespace br @@ -28,7 +28,7 @@ namespace br
28 typedef QVector<Cluster> Clusters; 28 typedef QVector<Cluster> Clusters;
29 29
30 Clusters ClusterGallery(const QStringList &simmats, float aggressiveness, const QString &csv); 30 Clusters ClusterGallery(const QStringList &simmats, float aggressiveness, const QString &csv);
31 - void EvalClustering(const QString &csv, const QString &input); 31 + void EvalClustering(const QString &csv, const QString &input, QString truth_property);
32 32
33 Clusters ReadClusters(const QString &csv); 33 Clusters ReadClusters(const QString &csv);
34 void WriteClusters(const Clusters &clusters, const QString &csv); 34 void WriteClusters(const Clusters &clusters, const QString &csv);
openbr/openbr.cpp
@@ -109,9 +109,9 @@ void br_eval_classification(const char *predicted_gallery, const char *truth_gal @@ -109,9 +109,9 @@ void br_eval_classification(const char *predicted_gallery, const char *truth_gal
109 EvalClassification(predicted_gallery, truth_gallery, predicted_property, truth_property); 109 EvalClassification(predicted_gallery, truth_gallery, predicted_property, truth_property);
110 } 110 }
111 111
112 -void br_eval_clustering(const char *csv, const char *gallery) 112 +void br_eval_clustering(const char *csv, const char *gallery, const char * truth_property)
113 { 113 {
114 - EvalClustering(csv, gallery); 114 + EvalClustering(csv, gallery, truth_property);
115 } 115 }
116 116
117 float br_eval_detection(const char *predicted_gallery, const char *truth_gallery, const char *csv) 117 float br_eval_detection(const char *predicted_gallery, const char *truth_gallery, const char *csv)
openbr/openbr.h
@@ -167,9 +167,10 @@ BR_EXPORT void br_eval_classification(const char *predicted_gallery, const char @@ -167,9 +167,10 @@ BR_EXPORT void br_eval_classification(const char *predicted_gallery, const char
167 * \brief Evaluates and prints clustering accuracy to the terminal. 167 * \brief Evaluates and prints clustering accuracy to the terminal.
168 * \param csv The cluster results file. 168 * \param csv The cluster results file.
169 * \param gallery The br::Gallery used to generate the \ref simmat that was clustered. 169 * \param gallery The br::Gallery used to generate the \ref simmat that was clustered.
  170 + * \param truth_property (Optional) which metadata key to use from <i>gallery</i/>, defaults to Label
170 * \see br_cluster 171 * \see br_cluster
171 */ 172 */
172 -BR_EXPORT void br_eval_clustering(const char *csv, const char *gallery); 173 +BR_EXPORT void br_eval_clustering(const char *csv, const char *gallery, const char * truth_property);
173 174
174 /*! 175 /*!
175 * \brief Evaluates and prints detection accuracy to terminal. 176 * \brief Evaluates and prints detection accuracy to terminal.