Commit 57118ef4956cd0b645492d95a99bf40537a46d97

Authored by Ben Klein
2 parents f6272818 0658fb41

Merge pull request #247 from biometrics/eval

Eval matches fix
openbr/core/eval.cpp
... ... @@ -100,10 +100,10 @@ static cv::Mat constructMatchingMask(const cv::Mat &scores, const FileList &targ
100 100  
101 101 float Evaluate(const cv::Mat &scores, const FileList &target, const FileList &query, const QString &csv, int partition)
102 102 {
103   - return Evaluate(scores, constructMatchingMask(scores, target, query, partition), target, query, csv, 10);
  103 + return Evaluate(scores, constructMatchingMask(scores, target, query, partition), csv, QString(), QString(), 0);
104 104 }
105 105  
106   -float Evaluate(const QString &simmat, const QString &mask, const QString &csv, int matches)
  106 +float Evaluate(const QString &simmat, const QString &mask, const QString &csv, unsigned int matches)
107 107 {
108 108 qDebug("Evaluating %s%s%s",
109 109 qPrintable(simmat),
... ... @@ -137,11 +137,12 @@ float Evaluate(const QString &simmat, const QString &mask, const QString &csv, i
137 137 truth = format->read();
138 138 }
139 139  
140   - return Evaluate(scores, truth, TemplateList::fromGallery(target).files(), TemplateList::fromGallery(query).files(), csv, matches);
  140 + return Evaluate(scores, truth, csv, target, query, matches);
141 141 }
142 142  
143   -float Evaluate(const Mat &simmat, const Mat &mask, const FileList &target, const FileList &query, const QString &csv, int matches)
  143 +float Evaluate(const Mat &simmat, const Mat &mask, const QString &csv, const QString &target, const QString &query, unsigned int matches)
144 144 {
  145 + if (target.isEmpty() || query.isEmpty()) matches = 0;
145 146 if (simmat.size() != mask.size())
146 147 qFatal("Similarity matrix (%ix%i) differs in size from mask matrix (%ix%i).",
147 148 simmat.rows, simmat.cols, mask.rows, mask.cols);
... ... @@ -172,7 +173,7 @@ float Evaluate(const Mat &simmat, const Mat &mask, const FileList &target, const
172 173 if (comparison.genuine) {
173 174 genuineCount++;
174 175 if (matches != 0){
175   - if (botGenuines.size() < matches) {
  176 + if (botGenuines.size() < (int)matches) {
176 177 botGenuines.append(comparison);
177 178 std::sort(botGenuines.begin(), botGenuines.end());
178 179 } else if (comparison.score < botGenuines.first().score) {
... ... @@ -184,7 +185,7 @@ float Evaluate(const Mat &amp;simmat, const Mat &amp;mask, const FileList &amp;target, const
184 185 } else {
185 186 impostorCount++;
186 187 if (matches != 0) {
187   - if (topImpostors.size() < matches) {
  188 + if (topImpostors.size() < (int)matches) {
188 189 topImpostors.append(comparison);
189 190 std::sort(topImpostors.begin(), topImpostors.end());
190 191 } else if (topImpostors.last().score < comparison.score) {
... ... @@ -265,14 +266,16 @@ float Evaluate(const Mat &amp;simmat, const Mat &amp;mask, const FileList &amp;target, const
265 266  
266 267 QString filePath = Globals->path;
267 268 if (matches != 0) {
  269 + const FileList targetFiles = TemplateList::fromGallery(target).files();
  270 + const FileList queryFiles = TemplateList::fromGallery(query).files();
268 271 for (int i=0; i<topImpostors.size(); i++) {
269   - lines.append("TI,"+QString::number(topImpostors[i].score)+","+target[topImpostors[i].target].get<QString>("Label")+":"
270   - +filePath+"/"+target[topImpostors[i].target].name+":"+query[topImpostors[i].query].get<QString>("Label")+":"+filePath+"/"+query[topImpostors[i].query].name);
  272 + lines.append("TI,"+QString::number(topImpostors[i].score)+","+targetFiles[topImpostors[i].target].get<QString>("Label")+":"
  273 + +filePath+"/"+targetFiles[topImpostors[i].target].name+":"+queryFiles[topImpostors[i].query].get<QString>("Label")+":"+filePath+"/"+queryFiles[topImpostors[i].query].name);
271 274 }
272 275 std::reverse(botGenuines.begin(), botGenuines.end());
273 276 for (int i=0; i<botGenuines.size(); i++) {
274   - lines.append("BG,"+QString::number(botGenuines[i].score)+","+target[botGenuines[i].target].get<QString>("Label")+":"
275   - +filePath+"/"+target[botGenuines[i].target].name+":"+query[botGenuines[i].query].get<QString>("Label")+":"+filePath+"/"+query[botGenuines[i].query].name);
  277 + lines.append("BG,"+QString::number(botGenuines[i].score)+","+targetFiles[botGenuines[i].target].get<QString>("Label")+":"
  278 + +filePath+"/"+targetFiles[botGenuines[i].target].name+":"+queryFiles[botGenuines[i].query].get<QString>("Label")+":"+filePath+"/"+queryFiles[botGenuines[i].query].name);
276 279 }
277 280 }
278 281  
... ...
openbr/core/eval.h
... ... @@ -23,9 +23,9 @@
23 23  
24 24 namespace br
25 25 {
26   - float Evaluate(const QString &simmat, const QString &mask = "", const QString &csv = "", int matches = 0); // Returns TAR @ FAR = 0.001
  26 + float Evaluate(const QString &simmat, const QString &mask = "", const QString &csv = "", unsigned int matches = 0); // Returns TAR @ FAR = 0.001
27 27 float Evaluate(const cv::Mat &scores, const FileList &target, const FileList &query, const QString &csv = "", int parition = 0);
28   - float Evaluate(const cv::Mat &scores, const cv::Mat &masks, const FileList &target, const FileList &query, const QString &csv = "", int matches = 0);
  28 + float Evaluate(const cv::Mat &scores, const cv::Mat &masks, const QString &csv = "", const QString &target = "", const QString &query = "", unsigned int matches = 0);
29 29 float InplaceEval(const QString & simmat, const QString & target, const QString & query, const QString & csv = "");
30 30  
31 31 void EvalClassification(const QString &predictedGallery, const QString &truthGallery, QString predictedProperty = "", QString truthProperty = "");
... ...