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 | 971 | protected: |
| 972 | 972 | Transform(bool independent = true); /*!< \brief Construct a transform. */ |
| 973 | 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 | 1074 | float compare(const Template &target, const Template &query) const; /*!< \brief Compute the normalized distance between two templates. */ |
| 1076 | 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 | 1080 | private: |
| 1079 | 1081 | virtual void compareBlock(const TemplateList &target, const TemplateList &query, Output *output, int targetOffset, int queryOffset) const; |
| 1080 | 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 | 18 | Q_PROPERTY(br::Distance* distance READ get_distance WRITE set_distance RESET reset_distance STORED false) |
| 19 | 19 | Q_PROPERTY(double mean READ get_mean WRITE set_mean RESET reset_mean) |
| 20 | 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 | 22 | BR_PROPERTY(double, mean, 0) |
| 23 | 23 | BR_PROPERTY(double, stddev, 1) |
| 24 | 24 | br::TemplateList impostors; |
| 25 | 25 | |
| 26 | 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 | 35 | float min, max; |
| 30 | 36 | Common::MinMax(scores, &min, &max); |
| 31 | 37 | double mean; |
| ... | ... | @@ -39,14 +45,8 @@ class IUMTransform : public Transform |
| 39 | 45 | impostors = data; |
| 40 | 46 | |
| 41 | 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 | 51 | Common::MeanStdDev(iums, &mean, &stddev); |
| 52 | 52 | } |
| ... | ... | @@ -134,42 +134,43 @@ QDataStream &operator>>(QDataStream &stream, NMP &nmp) |
| 134 | 134 | |
| 135 | 135 | /*! |
| 136 | 136 | * \ingroup distances |
| 137 | - * \brief Impostor Uniqueness Distance \cite klare12 | |
| 137 | + * \brief Non-match Probability Distance \cite klare12 | |
| 138 | 138 | * \author Josh Klontz \cite jklontz |
| 139 | 139 | */ |
| 140 | -class IUMDistance : public Distance | |
| 140 | +class NMPDistance : public Distance | |
| 141 | 141 | { |
| 142 | 142 | Q_OBJECT |
| 143 | 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 | 150 | void train(const TemplateList &src) |
| 149 | 151 | { |
| 150 | 152 | distance->train(src); |
| 151 | 153 | |
| 152 | - const QList<float> labels = src.labels<float>(); | |
| 154 | + const QList<int> labels = src.labels<int>(); | |
| 153 | 155 | QScopedPointer<MatrixOutput> memoryOutput(dynamic_cast<MatrixOutput*>(Output::make(".Matrix", FileList(src.size()), FileList(src.size())))); |
| 154 | 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 | 159 | for (int i=0; i<src.size(); i++) |
| 159 | 160 | for (int j=0; j<i; j++) { |
| 160 | 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 | 163 | if (labels[i] == labels[j]) genuineScores[bin].append(score); |
| 163 | 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 | 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 | 176 | void store(QDataStream &stream) const |
| ... | ... | @@ -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 | 191 | } // namespace br |
| 191 | 192 | ... | ... |