Skip to content

Commit

Permalink
Add ability to use EvalClustering with gal and cluster property inste…
Browse files Browse the repository at this point in the history
…ad of a cluster csv
  • Loading branch information
imaus10 committed Jun 19, 2015
1 parent 992fb54 commit 5a33ca8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/br/br.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ class FakeMain : public QRunnable
check(parc >= 2 && parc <= 4, "Incorrect parameter count for 'evalClassification'.");
br_eval_classification(parv[0], parv[1], parc >= 3 ? parv[2] : "", parc >= 4 ? parv[3] : "");
} else if (!strcmp(fun, "evalClustering")) {
check((parc >= 2) && (parc <= 3), "Incorrect parameter count for 'evalClustering'.");
br_eval_clustering(parv[0], parv[1], parc == 3 ? parv[2] : "");
check((parc >= 2) && (parc <= 5), "Incorrect parameter count for 'evalClustering'.");
br_eval_clustering(parv[0], parv[1], parc > 2 ? parv[2] : "", parc > 3 ? atoi(parv[3]) : 1, parc > 4 ? parv[4] : "");
} else if (!strcmp(fun, "evalDetection")) {
check((parc >= 2) && (parc <= 6), "Incorrect parameter count for 'evalDetection'.");
br_eval_detection(parv[0], parv[1], parc >= 3 ? parv[2] : "", parc >= 4 ? atoi(parv[3]) : 0, parc >= 5 ? atoi(parv[4]) : 0, parc == 6 ? atoi(parv[5]) : 0);
Expand Down
27 changes: 23 additions & 4 deletions openbr/core/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,16 @@ float jaccardIndex(const QVector<int> &indicesA, const QVector<int> &indicesB)

// Evaluates clustering algorithms based on metrics described in
// Santo Fortunato "Community detection in graphs", Physics Reports 486 (2010)
void br::EvalClustering(const QString &csv, const QString &input, QString truth_property)
void br::EvalClustering(const QString &clusters, const QString &truth_gallery, QString truth_property, bool cluster_csv, QString cluster_property)
{
if (truth_property.isEmpty())
truth_property = "Label";
qDebug("Evaluating %s against %s", qPrintable(csv), qPrintable(input));
if (!cluster_csv && cluster_property.isEmpty()) {
cluster_property = "ClusterID";
}
qDebug("Evaluating %s against %s", qPrintable(clusters), qPrintable(truth_gallery));

TemplateList tList = TemplateList::fromGallery(input);
TemplateList tList = TemplateList::fromGallery(truth_gallery);
QList<int> labels = tList.indexProperty(truth_property);

QHash<int, int> labelToIndex;
Expand All @@ -459,7 +462,23 @@ void br::EvalClustering(const QString &csv, const QString &input, QString truth_
truthClusters[labelToIndex[labels[i]]].append(i);
}

Clusters testClusters = ReadClusters(csv);
Clusters testClusters;
if (cluster_csv) {
testClusters = ReadClusters(clusters);
} else {
// get Clusters from gallery
const TemplateList tl(TemplateList::fromGallery(clusters));
QHash<int,Cluster > clust_id_map;
for (int i=0; i<tl.size(); i++) {
const Template &t = tl.at(i);
int c = t.file.get<int>(cluster_property);
if (!clust_id_map.contains(c)) {
clust_id_map.insert(c, Cluster());
}
clust_id_map[c].append(i);
}
testClusters = Clusters::fromList(clust_id_map.values());
}

QVector<int> testIndices(labels.size());
for (int i=0; i<testClusters.size(); i++)
Expand Down
2 changes: 1 addition & 1 deletion openbr/core/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace br

// evaluate clustering results in csv, reading ground truth data from gallery input, using truth_property
// as the key for ground truth labels.
void EvalClustering(const QString &csv, const QString &input, QString truth_property);
void EvalClustering(const QString &clusters, const QString &truth_gallery, QString truth_property, bool cluster_csv, QString cluster_property);

// Read/write clusters from a text format, 1 line = 1 cluster, each line contains comma separated list
// of assigned indices.
Expand Down
4 changes: 2 additions & 2 deletions openbr/openbr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ void br_eval_classification(const char *predicted_gallery, const char *truth_gal
EvalClassification(predicted_gallery, truth_gallery, predicted_property, truth_property);
}

void br_eval_clustering(const char *csv, const char *gallery, const char *truth_property)
void br_eval_clustering(const char *clusters, const char *truth_gallery, const char *truth_property, bool cluster_csv, const char *cluster_property)
{
EvalClustering(csv, gallery, truth_property);
EvalClustering(clusters, truth_gallery, truth_property, cluster_csv, cluster_property);
}

float br_eval_detection(const char *predicted_gallery, const char *truth_gallery, const char *csv, bool normalize, int minSize, int maxSize)
Expand Down
2 changes: 1 addition & 1 deletion openbr/openbr.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ BR_EXPORT float br_inplace_eval(const char * simmat, const char *target, const c

BR_EXPORT void br_eval_classification(const char *predicted_gallery, const char *truth_gallery, const char *predicted_property = "", const char *truth_property = "");

BR_EXPORT void br_eval_clustering(const char *csv, const char *gallery, const char * truth_property);
BR_EXPORT void br_eval_clustering(const char *clusters, const char *truth_gallery, const char *truth_property = "", bool cluster_csv = true, const char *cluster_property = "");

BR_EXPORT float br_eval_detection(const char *predicted_gallery, const char *truth_gallery, const char *csv = "", bool normalize = false, int minSize = 0, int maxSize = 0);

Expand Down

0 comments on commit 5a33ca8

Please sign in to comment.