Commit 9bd0b8c166bdb9993384ad565c0302c1e84f6765
1 parent
4f8a2319
Reworked some Turk-related transforms
Showing
2 changed files
with
14 additions
and
8 deletions
openbr/plugins/distance.cpp
| @@ -396,17 +396,20 @@ BR_REGISTER(Distance, OnlineDistance) | @@ -396,17 +396,20 @@ BR_REGISTER(Distance, OnlineDistance) | ||
| 396 | */ | 396 | */ |
| 397 | class AttributeDistance : public Distance | 397 | class AttributeDistance : public Distance |
| 398 | { | 398 | { |
| 399 | + | ||
| 399 | Q_OBJECT | 400 | Q_OBJECT |
| 400 | - Q_PROPERTY(QString attribute READ get_attribute WRITE set_attribute RESET reset_attribute STORED false) | ||
| 401 | - BR_PROPERTY(QString, attribute, QString()) | 401 | + Q_PROPERTY(QString targetAttribute READ get_targetAttribute WRITE set_targetAttribute RESET reset_targetAttribute STORED false) |
| 402 | + Q_PROPERTY(QString queryAttribute READ get_queryAttribute WRITE set_queryAttribute RESET reset_queryAttribute STORED false) | ||
| 403 | + BR_PROPERTY(QString, targetAttribute, QString()) | ||
| 404 | + BR_PROPERTY(QString, queryAttribute, QString()) | ||
| 402 | 405 | ||
| 403 | float compare(const Template &target, const Template &query) const | 406 | float compare(const Template &target, const Template &query) const |
| 404 | { | 407 | { |
| 405 | - float queryValue = query.file.get<float>(attribute); | ||
| 406 | - float targetValue = target.file.get<float>(attribute); | 408 | + float queryValue = query.file.get<float>(queryAttribute); |
| 409 | + float targetValue = target.file.get<float>(targetAttribute); | ||
| 407 | 410 | ||
| 408 | // TODO: Set this magic number to something meaningful | 411 | // TODO: Set this magic number to something meaningful |
| 409 | - float stddev = 1; | 412 | + float stddev = .5; |
| 410 | 413 | ||
| 411 | if (queryValue == targetValue) return 1; | 414 | if (queryValue == targetValue) return 1; |
| 412 | else return 1/(stddev*sqrt(2*CV_PI))*exp(-0.5*pow((targetValue-queryValue)/stddev, 2)); | 415 | else return 1/(stddev*sqrt(2*CV_PI))*exp(-0.5*pow((targetValue-queryValue)/stddev, 2)); |
| @@ -433,12 +436,14 @@ class SumDistance : public Distance | @@ -433,12 +436,14 @@ class SumDistance : public Distance | ||
| 433 | futures.addFuture(QtConcurrent::run(distance, &Distance::train, data)); | 436 | futures.addFuture(QtConcurrent::run(distance, &Distance::train, data)); |
| 434 | futures.waitForFinished(); | 437 | futures.waitForFinished(); |
| 435 | } | 438 | } |
| 436 | - | 439 | +; |
| 437 | float compare(const Template &target, const Template &query) const | 440 | float compare(const Template &target, const Template &query) const |
| 438 | { | 441 | { |
| 439 | float result = 0; | 442 | float result = 0; |
| 440 | 443 | ||
| 444 | + QList<float> scores; | ||
| 441 | foreach (br::Distance *distance, distances) { | 445 | foreach (br::Distance *distance, distances) { |
| 446 | + scores.append(distance->compare(target, query)); | ||
| 442 | result += distance->compare(target, query); | 447 | result += distance->compare(target, query); |
| 443 | 448 | ||
| 444 | if (result == -std::numeric_limits<float>::max()) | 449 | if (result == -std::numeric_limits<float>::max()) |
openbr/plugins/template.cpp
| @@ -105,7 +105,7 @@ class MTurkTransform : public UntrainableTransform | @@ -105,7 +105,7 @@ class MTurkTransform : public UntrainableTransform | ||
| 105 | Q_PROPERTY(float maxVotes READ get_maxVotes WRITE set_maxVotes RESET reset_maxVotes STORED false) | 105 | Q_PROPERTY(float maxVotes READ get_maxVotes WRITE set_maxVotes RESET reset_maxVotes STORED false) |
| 106 | BR_PROPERTY(QString, inputVariable, QString()) | 106 | BR_PROPERTY(QString, inputVariable, QString()) |
| 107 | BR_PROPERTY(float, maxVotes, 1.) | 107 | BR_PROPERTY(float, maxVotes, 1.) |
| 108 | - | 108 | +; |
| 109 | void project(const Template &src, Template &dst) const | 109 | void project(const Template &src, Template &dst) const |
| 110 | { | 110 | { |
| 111 | dst = src; | 111 | dst = src; |
| @@ -117,7 +117,8 @@ class MTurkTransform : public UntrainableTransform | @@ -117,7 +117,8 @@ class MTurkTransform : public UntrainableTransform | ||
| 117 | QMapIterator<QString, QVariant> i(map); | 117 | QMapIterator<QString, QVariant> i(map); |
| 118 | while (i.hasNext()) { | 118 | while (i.hasNext()) { |
| 119 | i.next(); | 119 | i.next(); |
| 120 | - dst.file.set(i.key(), i.value().toFloat(&ok)/maxVotes); | 120 | + float value = i.value().toFloat(&ok)/maxVotes; |
| 121 | + dst.file.set(i.key(), value); | ||
| 121 | } | 122 | } |
| 122 | } | 123 | } |
| 123 | }; | 124 | }; |