Commit bef0d1390b05e785b7a23a97f116609b38983ae1
1 parent
adab506f
IUM/NMP mostly working
Showing
2 changed files
with
26 additions
and
23 deletions
sdk/openbr_plugin.h
| @@ -971,7 +971,6 @@ public: | @@ -971,7 +971,6 @@ public: | ||
| 971 | protected: | 971 | protected: |
| 972 | Transform(bool independent = true); /*!< \brief Construct a transform. */ | 972 | Transform(bool independent = true); /*!< \brief Construct a transform. */ |
| 973 | inline Transform *make(const QString &description) { return make(description, this); } /*!< \brief Make a subtransform. */ | 973 | inline Transform *make(const QString &description) { return make(description, this); } /*!< \brief Make a subtransform. */ |
| 974 | - | ||
| 975 | }; | 974 | }; |
| 976 | 975 | ||
| 977 | /*! | 976 | /*! |
| @@ -1075,6 +1074,9 @@ public: | @@ -1075,6 +1074,9 @@ public: | ||
| 1075 | float compare(const Template &target, const Template &query) const; /*!< \brief Compute the normalized distance between two templates. */ | 1074 | float compare(const Template &target, const Template &query) const; /*!< \brief Compute the normalized distance between two templates. */ |
| 1076 | QList<float> compare(const TemplateList &targets, const Template &query) const; /*!< \brief Compute the normalized distance between a template and a template list. */ | 1075 | QList<float> compare(const TemplateList &targets, const Template &query) const; /*!< \brief Compute the normalized distance between a template and a template list. */ |
| 1077 | 1076 | ||
| 1077 | +protected: | ||
| 1078 | + inline Distance *make(const QString &description) { return make(description, this); } /*!< \brief Make a subdistance. */ | ||
| 1079 | + | ||
| 1078 | private: | 1080 | private: |
| 1079 | virtual void compareBlock(const TemplateList &target, const TemplateList &query, Output *output, int targetOffset, int queryOffset) const; | 1081 | virtual void compareBlock(const TemplateList &target, const TemplateList &query, Output *output, int targetOffset, int queryOffset) const; |
| 1080 | virtual float _compare(const Template &a, const Template &b) const = 0; /*!< \brief Compute the distance between two templates. */ | 1082 | virtual float _compare(const Template &a, const Template &b) const = 0; /*!< \brief Compute the distance between two templates. */ |
sdk/plugins/quality.cpp
| @@ -18,14 +18,20 @@ class IUMTransform : public Transform | @@ -18,14 +18,20 @@ class IUMTransform : public Transform | ||
| 18 | Q_PROPERTY(br::Distance* distance READ get_distance WRITE set_distance RESET reset_distance STORED false) | 18 | Q_PROPERTY(br::Distance* distance READ get_distance WRITE set_distance RESET reset_distance STORED false) |
| 19 | Q_PROPERTY(double mean READ get_mean WRITE set_mean RESET reset_mean) | 19 | Q_PROPERTY(double mean READ get_mean WRITE set_mean RESET reset_mean) |
| 20 | Q_PROPERTY(double stddev READ get_stddev WRITE set_stddev RESET reset_stddev) | 20 | Q_PROPERTY(double stddev READ get_stddev WRITE set_stddev RESET reset_stddev) |
| 21 | - BR_PROPERTY(br::Distance*, distance, Factory<Distance>::make(".Dist(L2)")) | 21 | + BR_PROPERTY(br::Distance*, distance, Distance::make("Dist(L2)", this)) |
| 22 | BR_PROPERTY(double, mean, 0) | 22 | BR_PROPERTY(double, mean, 0) |
| 23 | BR_PROPERTY(double, stddev, 1) | 23 | BR_PROPERTY(double, stddev, 1) |
| 24 | br::TemplateList impostors; | 24 | br::TemplateList impostors; |
| 25 | 25 | ||
| 26 | float calculateIUM(const Template &probe, const TemplateList &gallery) const | 26 | float calculateIUM(const Template &probe, const TemplateList &gallery) const |
| 27 | { | 27 | { |
| 28 | - QList<float> scores = distance->compare(gallery, probe); | 28 | + const int probeLabel = probe.file.label(); |
| 29 | + TemplateList subset = gallery; | ||
| 30 | + for (int j=subset.size()-1; j>=0; j--) | ||
| 31 | + if (subset[j].file.label() == probeLabel) | ||
| 32 | + subset.removeAt(j); | ||
| 33 | + | ||
| 34 | + QList<float> scores = distance->compare(subset, probe); | ||
| 29 | float min, max; | 35 | float min, max; |
| 30 | Common::MinMax(scores, &min, &max); | 36 | Common::MinMax(scores, &min, &max); |
| 31 | double mean; | 37 | double mean; |
| @@ -39,14 +45,8 @@ class IUMTransform : public Transform | @@ -39,14 +45,8 @@ class IUMTransform : public Transform | ||
| 39 | impostors = data; | 45 | impostors = data; |
| 40 | 46 | ||
| 41 | QList<float> iums; iums.reserve(impostors.size()); | 47 | QList<float> iums; iums.reserve(impostors.size()); |
| 42 | - QList<int> labels = impostors.labels<int>(); | ||
| 43 | - for (int i=0; i<data.size(); i++) { | ||
| 44 | - TemplateList subset = impostors; | ||
| 45 | - for (int j=subset.size()-1; j>=0; j--) | ||
| 46 | - if (labels[j] == labels[i]) | ||
| 47 | - subset.removeAt(j); | ||
| 48 | - iums.append(calculateIUM(impostors[i], subset)); | ||
| 49 | - } | 48 | + for (int i=0; i<data.size(); i++) |
| 49 | + iums.append(calculateIUM(impostors[i], impostors)); | ||
| 50 | 50 | ||
| 51 | Common::MeanStdDev(iums, &mean, &stddev); | 51 | Common::MeanStdDev(iums, &mean, &stddev); |
| 52 | } | 52 | } |
| @@ -134,42 +134,43 @@ QDataStream &operator>>(QDataStream &stream, NMP &nmp) | @@ -134,42 +134,43 @@ QDataStream &operator>>(QDataStream &stream, NMP &nmp) | ||
| 134 | 134 | ||
| 135 | /*! | 135 | /*! |
| 136 | * \ingroup distances | 136 | * \ingroup distances |
| 137 | - * \brief Impostor Uniqueness Distance \cite klare12 | 137 | + * \brief Non-match Probability Distance \cite klare12 |
| 138 | * \author Josh Klontz \cite jklontz | 138 | * \author Josh Klontz \cite jklontz |
| 139 | */ | 139 | */ |
| 140 | -class IUMDistance : public Distance | 140 | +class NMPDistance : public Distance |
| 141 | { | 141 | { |
| 142 | Q_OBJECT | 142 | Q_OBJECT |
| 143 | Q_PROPERTY(br::Distance* distance READ get_distance WRITE set_distance RESET reset_distance STORED false) | 143 | Q_PROPERTY(br::Distance* distance READ get_distance WRITE set_distance RESET reset_distance STORED false) |
| 144 | - BR_PROPERTY(br::Distance*, distance, Factory<Distance>::make(".Dist(L2)")) | 144 | + Q_PROPERTY(QString binKey READ get_binKey WRITE set_binKey RESET reset_binKey STORED false) |
| 145 | + BR_PROPERTY(br::Distance*, distance, make("Dist(L2)")) | ||
| 146 | + BR_PROPERTY(QString, binKey, "") | ||
| 145 | 147 | ||
| 146 | - QList<NMP> nmps; | 148 | + QHash<QString, NMP> nmps; |
| 147 | 149 | ||
| 148 | void train(const TemplateList &src) | 150 | void train(const TemplateList &src) |
| 149 | { | 151 | { |
| 150 | distance->train(src); | 152 | distance->train(src); |
| 151 | 153 | ||
| 152 | - const QList<float> labels = src.labels<float>(); | 154 | + const QList<int> labels = src.labels<int>(); |
| 153 | QScopedPointer<MatrixOutput> memoryOutput(dynamic_cast<MatrixOutput*>(Output::make(".Matrix", FileList(src.size()), FileList(src.size())))); | 155 | QScopedPointer<MatrixOutput> memoryOutput(dynamic_cast<MatrixOutput*>(Output::make(".Matrix", FileList(src.size()), FileList(src.size())))); |
| 154 | distance->compare(src, src, memoryOutput.data()); | 156 | distance->compare(src, src, memoryOutput.data()); |
| 155 | 157 | ||
| 156 | - const int IUM_Bins = 3; | ||
| 157 | - QVector< QList<float> > genuineScores(IUM_Bins), impostorScores(IUM_Bins); | 158 | + QHash< QString, QList<float> > genuineScores, impostorScores; |
| 158 | for (int i=0; i<src.size(); i++) | 159 | for (int i=0; i<src.size(); i++) |
| 159 | for (int j=0; j<i; j++) { | 160 | for (int j=0; j<i; j++) { |
| 160 | const float score = memoryOutput.data()->data.at<float>(i, j); | 161 | const float score = memoryOutput.data()->data.at<float>(i, j); |
| 161 | - const int bin = src[i].file.getInt("IUM_Bin"); | 162 | + const QString bin = src[i].file.getString(binKey, ""); |
| 162 | if (labels[i] == labels[j]) genuineScores[bin].append(score); | 163 | if (labels[i] == labels[j]) genuineScores[bin].append(score); |
| 163 | else impostorScores[bin].append(score); | 164 | else impostorScores[bin].append(score); |
| 164 | } | 165 | } |
| 165 | 166 | ||
| 166 | - for (int i=0; i<IUM_Bins; i++) | ||
| 167 | - nmps.append(NMP(genuineScores[i], impostorScores[i])); | 167 | + foreach (const QString &key, genuineScores.keys()) |
| 168 | + nmps.insert(key, NMP(genuineScores[key], impostorScores[key])); | ||
| 168 | } | 169 | } |
| 169 | 170 | ||
| 170 | float _compare(const Template &target, const Template &query) const | 171 | float _compare(const Template &target, const Template &query) const |
| 171 | { | 172 | { |
| 172 | - return nmps[query.file.getInt("IUM_Bin")](distance->compare(target, query)); | 173 | + return nmps[query.file.getString(binKey, "")](distance->compare(target, query)); |
| 173 | } | 174 | } |
| 174 | 175 | ||
| 175 | void store(QDataStream &stream) const | 176 | void store(QDataStream &stream) const |
| @@ -185,7 +186,7 @@ class IUMDistance : public Distance | @@ -185,7 +186,7 @@ class IUMDistance : public Distance | ||
| 185 | } | 186 | } |
| 186 | }; | 187 | }; |
| 187 | 188 | ||
| 188 | -BR_REGISTER(Distance, IUMDistance) | 189 | +BR_REGISTER(Distance, NMPDistance) |
| 189 | 190 | ||
| 190 | } // namespace br | 191 | } // namespace br |
| 191 | 192 |