Commit c9a0e83fc9ad652d650ca66cfcaf91920461d041
1 parent
95911ac6
Fixed conflicts
Showing
3 changed files
with
49 additions
and
5 deletions
openbr/plugins/independent.cpp
| ... | ... | @@ -11,17 +11,21 @@ namespace br |
| 11 | 11 | |
| 12 | 12 | static TemplateList Downsample(const TemplateList &templates, int classes, int instances, float fraction, const QString & inputVariable, const QStringList &gallery) |
| 13 | 13 | { |
| 14 | + QString keepKey = "baggy"; | |
| 15 | + | |
| 14 | 16 | // Return early when no downsampling is required |
| 15 | 17 | if ((classes == std::numeric_limits<int>::max()) && |
| 16 | 18 | (instances == std::numeric_limits<int>::max()) && |
| 17 | 19 | (fraction >= 1) && |
| 18 | - (gallery.isEmpty())) | |
| 20 | + (gallery.isEmpty()) && | |
| 21 | + (keepKey.isEmpty())) | |
| 19 | 22 | return templates; |
| 20 | 23 | |
| 21 | 24 | const bool atLeast = instances < 0; |
| 22 | 25 | instances = abs(instances); |
| 23 | 26 | |
| 24 | 27 | QList<QString> allLabels = File::get<QString>(templates, inputVariable); |
| 28 | + | |
| 25 | 29 | QList<QString> uniqueLabels = allLabels.toSet().toList(); |
| 26 | 30 | qSort(uniqueLabels); |
| 27 | 31 | ... | ... |
openbr/plugins/template.cpp
| ... | ... | @@ -103,9 +103,13 @@ class MTurkTransform : public UntrainableTransform |
| 103 | 103 | Q_OBJECT |
| 104 | 104 | Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false) |
| 105 | 105 | Q_PROPERTY(float maxVotes READ get_maxVotes WRITE set_maxVotes RESET reset_maxVotes STORED false) |
| 106 | + Q_PROPERTY(bool classify READ get_classify WRITE set_classify RESET reset_classify STORED false) | |
| 107 | + Q_PROPERTY(bool consensusOnly READ get_consensusOnly WRITE set_consensusOnly RESET reset_consensusOnly STORED false) | |
| 106 | 108 | BR_PROPERTY(QString, inputVariable, QString()) |
| 107 | 109 | BR_PROPERTY(float, maxVotes, 1.) |
| 108 | -; | |
| 110 | + BR_PROPERTY(bool, classify, false) | |
| 111 | + BR_PROPERTY(bool, consensusOnly, false) | |
| 112 | + | |
| 109 | 113 | void project(const Template &src, Template &dst) const |
| 110 | 114 | { |
| 111 | 115 | dst = src; |
| ... | ... | @@ -117,8 +121,11 @@ class MTurkTransform : public UntrainableTransform |
| 117 | 121 | QMapIterator<QString, QVariant> i(map); |
| 118 | 122 | while (i.hasNext()) { |
| 119 | 123 | i.next(); |
| 120 | - float value = i.value().toFloat(&ok)/maxVotes; | |
| 121 | - dst.file.set(i.key(), value); | |
| 124 | + // Normalize to [-1,1] | |
| 125 | + float value = i.value().toFloat(&ok)/maxVotes;//* 2./maxVotes - 1; | |
| 126 | + if (classify) (value > 0) ? value = 1 : value = -1; | |
| 127 | + else if (consensusOnly && (value != 1 && value != -1)) continue; | |
| 128 | + dst.file.set(i.key(),value); | |
| 122 | 129 | } |
| 123 | 130 | } |
| 124 | 131 | }; | ... | ... |
openbr/plugins/validate.cpp
| ... | ... | @@ -142,9 +142,42 @@ BR_REGISTER(Transform, CrossValidateTransform) |
| 142 | 142 | class CrossValidateDistance : public Distance |
| 143 | 143 | { |
| 144 | 144 | Q_OBJECT |
| 145 | - | |
| 145 | +; | |
| 146 | 146 | float compare(const Template &a, const Template &b) const |
| 147 | 147 | { |
| 148 | + QStringList filters; | |
| 149 | + //filters << "Age" << "GENDER" << "RACE"; | |
| 150 | + foreach (const QString &key, filters) { | |
| 151 | + QString aValue = a.file.get<QString>(key, QString()); | |
| 152 | + QString bValue = b.file.get<QString>(key, QString()); | |
| 153 | + | |
| 154 | + // The query value may be a range. Let's check. | |
| 155 | + if (bValue.isEmpty()) bValue = QtUtils::toString(b.file.get<QPointF>(key, QPointF())); | |
| 156 | + | |
| 157 | + if (aValue.isEmpty() || bValue.isEmpty()) continue; | |
| 158 | + | |
| 159 | + bool keep = false; | |
| 160 | + bool ok; | |
| 161 | + | |
| 162 | + QPointF range = QtUtils::toPoint(bValue,&ok); | |
| 163 | + | |
| 164 | + if (ok) /* Range */ { | |
| 165 | + int value = range.x(); | |
| 166 | + int upperBound = range.y(); | |
| 167 | + | |
| 168 | + while (value <= upperBound) { | |
| 169 | + if (aValue == QString::number(value)) { | |
| 170 | + keep = true; | |
| 171 | + break; | |
| 172 | + } | |
| 173 | + value++; | |
| 174 | + } | |
| 175 | + } | |
| 176 | + else if (aValue == bValue) keep = true; | |
| 177 | + | |
| 178 | + if (!keep) return -std::numeric_limits<float>::max(); | |
| 179 | + } | |
| 180 | + | |
| 148 | 181 | static const QString key("Partition"); // More efficient to preallocate this |
| 149 | 182 | const int partitionA = a.file.get<int>(key, 0); |
| 150 | 183 | const int partitionB = b.file.get<int>(key, 0); | ... | ... |