From fd2c2ed7b1238d2135f141c3a5516210f7362106 Mon Sep 17 00:00:00 2001 From: Tunde Date: Thu, 22 May 2014 16:20:46 -0400 Subject: [PATCH] Added Top Predictions Gallery. Very basic at the moment --- openbr/plugins/gallery.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+), 0 deletions(-) diff --git a/openbr/plugins/gallery.cpp b/openbr/plugins/gallery.cpp index e1e2144..ae1ce51 100644 --- a/openbr/plugins/gallery.cpp +++ b/openbr/plugins/gallery.cpp @@ -1019,6 +1019,85 @@ class landmarksGallery : public Gallery BR_REGISTER(Gallery, landmarksGallery) +/*! + * \ingroup galleries + * \brief Prints top attributes. + * \author Babatunde Ogunfemi \cite baba1472 + * + * Prints to std out the top predictions. An optional threshold may be specified using a space ' ' separator: + * + */ +class topPredictionsGallery : public Gallery +{ + Q_OBJECT + Q_PROPERTY(float out_count READ get_out_count WRITE set_out_count RESET reset_out_count STORED false) + BR_PROPERTY(float, out_count, 3) + + QMap attributes; + + ~topPredictionsGallery() + { + QString result = QString("# of attributes: %1").arg(QString::number(attributes.count())); + QtUtils::writeFile(file.name, result); + if (!attributes.isEmpty()) + { + QMapIterator it(attributes); + it.toBack(); + if (out_count > 1) + { + if (attributes.count() < out_count) + out_count = attributes.count(); + + for (int i = 0; i < out_count; i++) + { + it.previous(); + result = QString("%1) %2 : %3").arg(QString::number(i + 1), it.value(), QString::number((float)it.key())); + QtUtils::writeFile(file.name, result); + } + } + else + { + int count = 0; + it.toBack(); + while (it.hasPrevious()) + { + it.previous(); + if (it.key() >= out_count) + { + result = QString("%1) %2 : %3").arg(QString::number(count + 1), it.value(), QString::number((float)it.key())); + QtUtils::writeFile(file.name, result); + count++; + } + } + } + } + } + + //Pure virtial function so needs an implementation + TemplateList readBlock(bool *done) + { + *done = true; + return TemplateList() << file; + } + + void write(const Template &t) + { + QList keys = t.file.localKeys(); + for (int i = 0; i < keys.count(); i++) + { + QString key = keys.at(i); + if (key.startsWith("predicted_")) + { + float val = t.file.get(key); + attributes.insert(val, key); //use float as key to keep in order + } + + } + } +}; + +BR_REGISTER(Gallery, topPredictionsGallery) + #ifdef CVMATIO using namespace cv; -- libgit2 0.21.4