From e868900cd7b308b20dfb759eaaf78ba1276001f5 Mon Sep 17 00:00:00 2001 From: Scott Klum Date: Sat, 29 Mar 2014 13:31:01 -0400 Subject: [PATCH] Added the ability to remove subjects to Downsample --- openbr/plugins/independent.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/openbr/plugins/independent.cpp b/openbr/plugins/independent.cpp index 7781b74..59c7fb5 100644 --- a/openbr/plugins/independent.cpp +++ b/openbr/plugins/independent.cpp @@ -9,13 +9,14 @@ using namespace cv; namespace br { -static TemplateList Downsample(const TemplateList &templates, int classes, int instances, float fraction, const QString & inputVariable, const QStringList &gallery) +static TemplateList Downsample(const TemplateList &templates, int classes, int instances, float fraction, const QString & inputVariable, const QStringList &gallery, const QStringList &subjects) { // Return early when no downsampling is required if ((classes == std::numeric_limits::max()) && (instances == std::numeric_limits::max()) && (fraction >= 1) && - (gallery.isEmpty())) + (gallery.isEmpty()) && + (subjects.isEmpty())) return templates; const bool atLeast = instances < 0; @@ -66,6 +67,11 @@ static TemplateList Downsample(const TemplateList &templates, int classes, int i if (!gallery.contains(downsample[i].file.get("Gallery"))) downsample.removeAt(i); + if (!subjects.isEmpty()) + for (int i=downsample.size()-1; i>=0; i--) + if (subjects.contains(downsample[i].file.get(inputVariable))) + downsample.removeAt(i); + return downsample; } @@ -78,12 +84,15 @@ class DownsampleTrainingTransform : public Transform Q_PROPERTY(float fraction READ get_fraction WRITE set_fraction RESET reset_fraction STORED false) Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false) Q_PROPERTY(QStringList gallery READ get_gallery WRITE set_gallery RESET reset_gallery STORED false) + Q_PROPERTY(QStringList subjects READ get_subjects WRITE set_subjects RESET reset_subjects STORED false) BR_PROPERTY(br::Transform*, transform, NULL) BR_PROPERTY(int, classes, std::numeric_limits::max()) BR_PROPERTY(int, instances, std::numeric_limits::max()) BR_PROPERTY(float, fraction, 1) BR_PROPERTY(QString, inputVariable, "Label") BR_PROPERTY(QStringList, gallery, QStringList()) + BR_PROPERTY(QStringList, subjects, QStringList()) + void project(const Template & src, Template & dst) const { @@ -96,7 +105,7 @@ class DownsampleTrainingTransform : public Transform if (!transform || !transform->trainable) return; - TemplateList downsampled = Downsample(data, classes, instances, fraction, inputVariable, gallery); + TemplateList downsampled = Downsample(data, classes, instances, fraction, inputVariable, gallery, subjects); transform->train(downsampled); } -- libgit2 0.21.4