Commit e868900cd7b308b20dfb759eaaf78ba1276001f5

Authored by Scott Klum
1 parent 2a8e4d9c

Added the ability to remove subjects to Downsample

Showing 1 changed file with 12 additions and 3 deletions
openbr/plugins/independent.cpp
@@ -9,13 +9,14 @@ using namespace cv; @@ -9,13 +9,14 @@ using namespace cv;
9 namespace br 9 namespace br
10 { 10 {
11 11
12 -static TemplateList Downsample(const TemplateList &templates, int classes, int instances, float fraction, const QString & inputVariable, const QStringList &gallery) 12 +static TemplateList Downsample(const TemplateList &templates, int classes, int instances, float fraction, const QString & inputVariable, const QStringList &gallery, const QStringList &subjects)
13 { 13 {
14 // Return early when no downsampling is required 14 // Return early when no downsampling is required
15 if ((classes == std::numeric_limits<int>::max()) && 15 if ((classes == std::numeric_limits<int>::max()) &&
16 (instances == std::numeric_limits<int>::max()) && 16 (instances == std::numeric_limits<int>::max()) &&
17 (fraction >= 1) && 17 (fraction >= 1) &&
18 - (gallery.isEmpty())) 18 + (gallery.isEmpty()) &&
  19 + (subjects.isEmpty()))
19 return templates; 20 return templates;
20 21
21 const bool atLeast = instances < 0; 22 const bool atLeast = instances < 0;
@@ -66,6 +67,11 @@ static TemplateList Downsample(const TemplateList &amp;templates, int classes, int i @@ -66,6 +67,11 @@ static TemplateList Downsample(const TemplateList &amp;templates, int classes, int i
66 if (!gallery.contains(downsample[i].file.get<QString>("Gallery"))) 67 if (!gallery.contains(downsample[i].file.get<QString>("Gallery")))
67 downsample.removeAt(i); 68 downsample.removeAt(i);
68 69
  70 + if (!subjects.isEmpty())
  71 + for (int i=downsample.size()-1; i>=0; i--)
  72 + if (subjects.contains(downsample[i].file.get<QString>(inputVariable)))
  73 + downsample.removeAt(i);
  74 +
69 return downsample; 75 return downsample;
70 } 76 }
71 77
@@ -78,12 +84,15 @@ class DownsampleTrainingTransform : public Transform @@ -78,12 +84,15 @@ class DownsampleTrainingTransform : public Transform
78 Q_PROPERTY(float fraction READ get_fraction WRITE set_fraction RESET reset_fraction STORED false) 84 Q_PROPERTY(float fraction READ get_fraction WRITE set_fraction RESET reset_fraction STORED false)
79 Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false) 85 Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false)
80 Q_PROPERTY(QStringList gallery READ get_gallery WRITE set_gallery RESET reset_gallery STORED false) 86 Q_PROPERTY(QStringList gallery READ get_gallery WRITE set_gallery RESET reset_gallery STORED false)
  87 + Q_PROPERTY(QStringList subjects READ get_subjects WRITE set_subjects RESET reset_subjects STORED false)
81 BR_PROPERTY(br::Transform*, transform, NULL) 88 BR_PROPERTY(br::Transform*, transform, NULL)
82 BR_PROPERTY(int, classes, std::numeric_limits<int>::max()) 89 BR_PROPERTY(int, classes, std::numeric_limits<int>::max())
83 BR_PROPERTY(int, instances, std::numeric_limits<int>::max()) 90 BR_PROPERTY(int, instances, std::numeric_limits<int>::max())
84 BR_PROPERTY(float, fraction, 1) 91 BR_PROPERTY(float, fraction, 1)
85 BR_PROPERTY(QString, inputVariable, "Label") 92 BR_PROPERTY(QString, inputVariable, "Label")
86 BR_PROPERTY(QStringList, gallery, QStringList()) 93 BR_PROPERTY(QStringList, gallery, QStringList())
  94 + BR_PROPERTY(QStringList, subjects, QStringList())
  95 +
87 96
88 void project(const Template & src, Template & dst) const 97 void project(const Template & src, Template & dst) const
89 { 98 {
@@ -96,7 +105,7 @@ class DownsampleTrainingTransform : public Transform @@ -96,7 +105,7 @@ class DownsampleTrainingTransform : public Transform
96 if (!transform || !transform->trainable) 105 if (!transform || !transform->trainable)
97 return; 106 return;
98 107
99 - TemplateList downsampled = Downsample(data, classes, instances, fraction, inputVariable, gallery); 108 + TemplateList downsampled = Downsample(data, classes, instances, fraction, inputVariable, gallery, subjects);
100 109
101 transform->train(downsampled); 110 transform->train(downsampled);
102 } 111 }