diff --git a/openbr/plugins/independent.cpp b/openbr/plugins/independent.cpp index 7781b74..4399214 100644 --- a/openbr/plugins/independent.cpp +++ b/openbr/plugins/independent.cpp @@ -11,17 +11,21 @@ namespace br static TemplateList Downsample(const TemplateList &templates, int classes, int instances, float fraction, const QString & inputVariable, const QStringList &gallery) { + QString keepKey = "baggy"; + // Return early when no downsampling is required if ((classes == std::numeric_limits::max()) && (instances == std::numeric_limits::max()) && (fraction >= 1) && - (gallery.isEmpty())) + (gallery.isEmpty()) && + (keepKey.isEmpty())) return templates; const bool atLeast = instances < 0; instances = abs(instances); QList allLabels = File::get(templates, inputVariable); + QList uniqueLabels = allLabels.toSet().toList(); qSort(uniqueLabels); diff --git a/openbr/plugins/template.cpp b/openbr/plugins/template.cpp index a7d11c8..e8f750f 100644 --- a/openbr/plugins/template.cpp +++ b/openbr/plugins/template.cpp @@ -103,9 +103,13 @@ class MTurkTransform : public UntrainableTransform Q_OBJECT Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false) Q_PROPERTY(float maxVotes READ get_maxVotes WRITE set_maxVotes RESET reset_maxVotes STORED false) + Q_PROPERTY(bool classify READ get_classify WRITE set_classify RESET reset_classify STORED false) + Q_PROPERTY(bool consensusOnly READ get_consensusOnly WRITE set_consensusOnly RESET reset_consensusOnly STORED false) BR_PROPERTY(QString, inputVariable, QString()) BR_PROPERTY(float, maxVotes, 1.) -; + BR_PROPERTY(bool, classify, false) + BR_PROPERTY(bool, consensusOnly, false) + void project(const Template &src, Template &dst) const { dst = src; @@ -117,8 +121,11 @@ class MTurkTransform : public UntrainableTransform QMapIterator i(map); while (i.hasNext()) { i.next(); - float value = i.value().toFloat(&ok)/maxVotes; - dst.file.set(i.key(), value); + // Normalize to [-1,1] + float value = i.value().toFloat(&ok)/maxVotes;//* 2./maxVotes - 1; + if (classify) (value > 0) ? value = 1 : value = -1; + else if (consensusOnly && (value != 1 && value != -1)) continue; + dst.file.set(i.key(),value); } } }; diff --git a/openbr/plugins/validate.cpp b/openbr/plugins/validate.cpp index 75bca83..e535e57 100644 --- a/openbr/plugins/validate.cpp +++ b/openbr/plugins/validate.cpp @@ -142,9 +142,42 @@ BR_REGISTER(Transform, CrossValidateTransform) class CrossValidateDistance : public Distance { Q_OBJECT - +; float compare(const Template &a, const Template &b) const { + QStringList filters; + //filters << "Age" << "GENDER" << "RACE"; + foreach (const QString &key, filters) { + QString aValue = a.file.get(key, QString()); + QString bValue = b.file.get(key, QString()); + + // The query value may be a range. Let's check. + if (bValue.isEmpty()) bValue = QtUtils::toString(b.file.get(key, QPointF())); + + if (aValue.isEmpty() || bValue.isEmpty()) continue; + + bool keep = false; + bool ok; + + QPointF range = QtUtils::toPoint(bValue,&ok); + + if (ok) /* Range */ { + int value = range.x(); + int upperBound = range.y(); + + while (value <= upperBound) { + if (aValue == QString::number(value)) { + keep = true; + break; + } + value++; + } + } + else if (aValue == bValue) keep = true; + + if (!keep) return -std::numeric_limits::max(); + } + static const QString key("Partition"); // More efficient to preallocate this const int partitionA = a.file.get(key, 0); const int partitionB = b.file.get(key, 0);