Commit 0529fdedfd04b114668b8c057bea6406e3c31ad7

Authored by Charles Otto
1 parent 6e844a9c

Refactor FTE template exclusion

introduce a separate function to split FTE templates to a different list
Better handling of FTE exclusion during training (no reason to every include
fte templates in calls to train).
Remove File::failed, instead use direct access to fte.
openbr/frvt2012.cpp
... ... @@ -133,7 +133,7 @@ int32_t SdkEstimator::estimate_age(const ONEFACE &input_face, int32_t &age)
133 133 templates.append(templateFromONEFACE(input_face));
134 134 templates >> *frvt2012_age_transform.data();
135 135 age = templates.first().file.get<float>("Age");
136   - return templates.first().file.failed() ? 4 : 0;
  136 + return templates.first().file.fte ? 4 : 0;
137 137 }
138 138  
139 139 int32_t SdkEstimator::estimate_gender(const ONEFACE &input_face, int8_t &gender, double &mf)
... ... @@ -142,5 +142,5 @@ int32_t SdkEstimator::estimate_gender(const ONEFACE &amp;input_face, int8_t &amp;gender,
142 142 templates.append(templateFromONEFACE(input_face));
143 143 templates >> *frvt2012_gender_transform.data();
144 144 mf = gender = templates.first().file.get<QString>("Gender") == "Male" ? 0 : 1;
145   - return templates.first().file.failed() ? 4 : 0;
  145 + return templates.first().file.fte ? 4 : 0;
146 146 }
... ...
openbr/openbr_plugin.h
... ... @@ -308,8 +308,6 @@ struct BR_EXPORT File
308 308 return result;
309 309 }
310 310  
311   - inline bool failed() const { return fte; } /*!< \brief Returns \c true if the file failed to open or enroll, \c false otherwise. */
312   -
313 311 QList<QPointF> namedPoints() const; /*!< \brief Returns points convertible from metadata keys. */
314 312 QList<QPointF> points() const; /*!< \brief Returns the file's points list. */
315 313 void appendPoint(const QPointF &point); /*!< \brief Adds a point to the file's point list. */
... ... @@ -545,7 +543,7 @@ struct TemplateList : public QList&lt;Template&gt;
545 543 {
546 544 QMap<T, int> labelCounts;
547 545 foreach (const File &file, files())
548   - if (!excludeFailures || !file.failed())
  546 + if (!excludeFailures || !file.fte)
549 547 labelCounts[file.get<T>(propName)]++;
550 548 return labelCounts;
551 549 }
... ...
openbr/plugins/meta.cpp
... ... @@ -76,21 +76,14 @@ class PipeTransform : public CompositeTransform
76 76  
77 77 void _projectPartial(TemplateList *srcdst, int startIndex, int stopIndex)
78 78 {
79   - TemplateList dst = *srcdst;
80   - TemplateList temp;
  79 + TemplateList ftes;
81 80 for (int i=startIndex; i<stopIndex; i++) {
82   - TemplateList temp;
83   - transforms[i]->project(dst, temp);
84   -
85   - dst.clear();
86   - foreach (const Template &t, *srcdst) {
87   - if (!t.file.fte)
88   - dst.append(t);
89   - else
90   - srcdst->append(t);
91   - }
  81 + TemplateList res;
  82 + transforms[i]->project(*srcdst, res);
  83 +
  84 + splitFTEs(res, ftes);
  85 + *srcdst = res;
92 86 }
93   - srcdst->append(dst);
94 87 }
95 88  
96 89 void train(const QList<TemplateList> &data)
... ... @@ -112,8 +105,12 @@ class PipeTransform : public CompositeTransform
112 105 // if the transform is time varying, we can't project it in parallel
113 106 if (transforms[i]->timeVarying()) {
114 107 fprintf(stderr, "\n%s projecting...", qPrintable(transforms[i]->objectName()));
115   - for (int j=0; j < dataLines.size();j++)
  108 + for (int j=0; j < dataLines.size();j++) {
  109 + TemplateList junk;
  110 + splitFTEs(dataLines[j], junk);
  111 +
116 112 transforms[i]->projectUpdate(dataLines[j], dataLines[j]);
  113 + }
117 114  
118 115 // advance i since we already projected for this stage.
119 116 i++;
... ... @@ -215,20 +212,15 @@ protected:
215 212 // or if parallelism is disabled, handle them sequentially
216 213 void _project(const TemplateList &src, TemplateList &dst) const
217 214 {
218   - TemplateList temp, output;
219   - temp = src;
  215 + TemplateList ftes;
  216 + dst = src;
220 217 foreach (const Transform *f, transforms) {
221   - dst.clear();
222   - f->project(temp, dst);
223   - temp.clear();
224   - foreach(const Template &t, dst) {
225   - if (!t.file.fte)
226   - temp.append(t);
227   - else output.append(t);
228   - }
  218 + TemplateList res;
  219 + f->project(dst, res);
  220 + splitFTEs(res, ftes);
  221 + dst = res;
229 222 }
230   - output.append(temp);
231   - dst = output;
  223 + dst.append(ftes);
232 224 }
233 225  
234 226 // Single template const project, pass the template through each sub-transform, one after the other
... ...
openbr/plugins/openbr_internal.h
... ... @@ -481,6 +481,19 @@ Transform *wrapTransform(Transform *base, const QString &amp;target);
481 481  
482 482 Transform *pipeTransforms(QList<Transform *> &transforms);
483 483  
  484 +inline void splitFTEs(TemplateList &src, TemplateList &ftes)
  485 +{
  486 + TemplateList active = src;
  487 + src.clear();
  488 +
  489 + foreach (const Template &t, active) {
  490 + if (t.file.fte && !Globals->enrollAll)
  491 + ftes.append(t);
  492 + else
  493 + src.append(t);
  494 + }
  495 +}
  496 +
484 497 }
485 498  
486 499 #endif // OPENBR_INTERNAL_H
... ...
openbr/plugins/stream.cpp
... ... @@ -907,17 +907,12 @@ public:
907 907 qFatal("null input to multi-thread stage");
908 908 }
909 909  
910   - TemplateList project;
911   - TemplateList completed;
912   - for (int i=0; i < input->data.size(); i++) {
913   - if (input->data[i].file.fte)
914   - completed.append(input->data[i]);
915   - else
916   - project.append(input->data[i]);
917   - }
918   - input->data.clear();
919   - transform->project(project, input->data);
920   - input->data.append(completed);
  910 + TemplateList ftes;
  911 + splitFTEs(input->data, ftes);
  912 + TemplateList res;
  913 + transform->project(input->data, res);
  914 + input->data = res;
  915 + input->data.append(ftes);
921 916  
922 917 should_continue = nextStage->tryAcquireNextStage(input, final);
923 918  
... ... @@ -994,18 +989,12 @@ public:
994 989  
995 990 next_target = input->sequenceNumber + 1;
996 991  
997   - TemplateList project;
998   - TemplateList completed;
999   - foreach (const Template &t, input->data) {
1000   - if (t.file.fte)
1001   - completed.append(t);
1002   - else
1003   - project.append(t);
1004   - }
1005   - input->data.clear();
1006   - // Project the input we got
1007   - transform->projectUpdate(project, input->data);
1008   - input->data.append(completed);
  992 + TemplateList ftes;
  993 + splitFTEs(input->data, ftes);
  994 + TemplateList res;
  995 + transform->projectUpdate(input->data, res);
  996 + input->data = res;
  997 + input->data.append(ftes);
1009 998  
1010 999 should_continue = nextStage->tryAcquireNextStage(input,final);
1011 1000  
... ... @@ -1305,7 +1294,11 @@ public:
1305 1294  
1306 1295 QList<TemplateList> output;
1307 1296 for (int i=0; i < data.size(); i++) {
1308   - projectUpdate(data[i], data[i]);
  1297 + TemplateList res;
  1298 + TemplateList ftes;
  1299 + projectUpdate(data[i], res);
  1300 + data[i] = res;
  1301 + splitFTEs(data[i], ftes);
1309 1302 output.append(collector.sets);
1310 1303 collector.sets.clear();
1311 1304 }
... ...