From b52a58b69dcf13583f9482a32e41feb30eaa9a7a Mon Sep 17 00:00:00 2001 From: Josh Klontz Date: Tue, 19 Mar 2013 13:14:02 -0400 Subject: [PATCH] optimized pipe training --- openbr/openbr_plugin.cpp | 6 +++--- openbr/plugins/meta.cpp | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/openbr/openbr_plugin.cpp b/openbr/openbr_plugin.cpp index 3fb8798..0c19c22 100644 --- a/openbr/openbr_plugin.cpp +++ b/openbr/openbr_plugin.cpp @@ -1162,6 +1162,7 @@ public: transform->setParent(this); transforms.append(transform); file = transform->file; + trainable = transform->trainable; setObjectName(transforms.first()->objectName()); } @@ -1178,9 +1179,8 @@ private: void train(const TemplateList &data) { - // Don't bother constructing datasets if the transform is untrainable - if (dynamic_cast(transforms.first())) - return; + // Don't bother if the transform is untrainable + if (!trainable) return; QList templatesList; foreach (const Template &t, data) { diff --git a/openbr/plugins/meta.cpp b/openbr/plugins/meta.cpp index 907bcad..26771a4 100644 --- a/openbr/plugins/meta.cpp +++ b/openbr/plugins/meta.cpp @@ -75,14 +75,42 @@ class PipeTransform : public CompositeTransform { Q_OBJECT + void _projectPartial(Template *srcdst, int startIndex, int stopIndex) + { + for (int i=startIndex; i> *transforms[i]; + } + void train(const TemplateList &data) { TemplateList copy(data); - for (int i=0; iobjectName())); - transforms[i]->train(copy); - fprintf(stderr, "projecting...\n"); - copy >> *transforms[i]; + int i = 0; + while (i < transforms.size()) { + fprintf(stderr, "%s", qPrintable(transforms[i]->objectName())); + + // Conditional statement covers likely case that first transform is untrainable + if (transforms[i]->trainable) { + fprintf(stderr, " training..."); + transforms[i]->train(copy); + } + + // We project through any subsequent untrainable transforms at once + // as a memory optimization in case any of these intermediate + // transforms allocate a lot of memory (like OpenTransform) + // then we don't want all the training templates to be processed + // by that transform at once if we can avoid it. + int nextTrainableTransform = i+1; + while ((nextTrainableTransform < transforms.size()) && + !transforms[nextTrainableTransform]->trainable) + nextTrainableTransform++; + + fprintf(stderr, " projecting...\n"); + QFutureSynchronizer futures; + for (int j=0; jparallelism) futures.addFuture(QtConcurrent::run(this, &PipeTransform::_projectPartial, ©[j], i, nextTrainableTransform)); + else _projectPartial( ©[j], i, nextTrainableTransform); + futures.waitForFinished(); + i = nextTrainableTransform; } } -- libgit2 0.21.4