Commit 4b34805ad82c6d5a9fbdd19015f8bde7e14c1401

Authored by Josh Klontz
1 parent e3b09a68

added IUM bins

Showing 1 changed file with 32 additions and 9 deletions
sdk/plugins/quality.cpp
@@ -15,37 +15,60 @@ namespace br @@ -15,37 +15,60 @@ namespace br
15 class IUMTransform : public Transform 15 class IUMTransform : public Transform
16 { 16 {
17 Q_OBJECT 17 Q_OBJECT
18 - Q_PROPERTY(br::Distance* distance READ get_distance WRITE set_distance RESET reset_distance) 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)
  20 + Q_PROPERTY(double stddev READ get_stddev WRITE set_stddev RESET reset_stddev)
19 BR_PROPERTY(br::Distance*, distance, Factory<Distance>::make(".Dist(L2)")) 21 BR_PROPERTY(br::Distance*, distance, Factory<Distance>::make(".Dist(L2)"))
  22 + BR_PROPERTY(double, mean, 0)
  23 + BR_PROPERTY(double, stddev, 1)
20 br::TemplateList impostors; 24 br::TemplateList impostors;
21 25
  26 + float calculateIUM(const Template &probe, const TemplateList &gallery) const
  27 + {
  28 + QList<float> scores = distance->compare(gallery, probe);
  29 + float min, max;
  30 + Common::MinMax(scores, &min, &max);
  31 + double mean;
  32 + Common::Mean(scores, &mean);
  33 + return (max-mean)/(max-min);
  34 + }
  35 +
22 void train(const TemplateList &data) 36 void train(const TemplateList &data)
23 { 37 {
24 distance->train(data); 38 distance->train(data);
25 impostors = data; 39 impostors = data;
  40 +
  41 + 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 + }
  50 +
  51 + Common::MeanStdDev(iums, &mean, &stddev);
26 } 52 }
27 53
28 void project(const Template &src, Template &dst) const 54 void project(const Template &src, Template &dst) const
29 { 55 {
30 - QList<float> scores = distance->compare(impostors, src);  
31 - float min, max;  
32 - Common::MinMax(scores, &min, &max);  
33 - double mean;  
34 - Common::Mean(scores, &mean);  
35 dst = src; 56 dst = src;
36 - dst.file.insert("IUM", float((max-mean)/(max-min))); 57 + float ium = calculateIUM(src, impostors);
  58 + dst.file.insert("IUM", ium);
  59 + dst.file.insert("IUM_Bin", ium < mean-stddev ? 0 : (ium < mean+stddev ? 1 : 2));
37 } 60 }
38 61
39 void store(QDataStream &stream) const 62 void store(QDataStream &stream) const
40 { 63 {
41 distance->store(stream); 64 distance->store(stream);
42 - stream << impostors; 65 + stream << mean << stddev << impostors;
43 } 66 }
44 67
45 void load(QDataStream &stream) 68 void load(QDataStream &stream)
46 { 69 {
47 distance->load(stream); 70 distance->load(stream);
48 - stream >> impostors; 71 + stream >> mean >> stddev >> impostors;
49 } 72 }
50 }; 73 };
51 74