diff --git a/openbr/plugins/meta.cpp b/openbr/plugins/meta.cpp index b5e14cb..c8df4c5 100644 --- a/openbr/plugins/meta.cpp +++ b/openbr/plugins/meta.cpp @@ -104,6 +104,25 @@ class PipeTransform : public CompositeTransform fprintf(stderr, " training..."); transforms[i]->train(copy); } + // if the transform is time varying, we batch project it. + if (transforms[i]->timeVarying()) { + fprintf(stderr, "\n%s projecting...", qPrintable(transforms[i]->objectName())); + transforms[i]->projectUpdate(copy, copy); + + // advance i since we already projected for this stage. + i++; + + // set up the single item lists since they are inconsistent again. + singleItemLists.clear(); + for (int j=0; j < copy.size(); j++) + { + TemplateList temp; + temp.append(copy[j]); + singleItemLists.append(temp); + } + // the next stage might be trainable, so continue to evaluate it. + continue; + } // We project through any subsequent untrainable transforms at once // as a memory optimization in case any of these intermediate @@ -112,7 +131,8 @@ class PipeTransform : public CompositeTransform // by that transform at once if we can avoid it. int nextTrainableTransform = i+1; while ((nextTrainableTransform < transforms.size()) && - !transforms[nextTrainableTransform]->trainable) + !transforms[nextTrainableTransform]->trainable && + !transforms[nextTrainableTransform]->timeVarying()) nextTrainableTransform++; fprintf(stderr, " projecting..."); diff --git a/openbr/plugins/openbr_internal.h b/openbr/plugins/openbr_internal.h index fb7a1b5..2f42e50 100644 --- a/openbr/plugins/openbr_internal.h +++ b/openbr/plugins/openbr_internal.h @@ -170,14 +170,8 @@ public: virtual void project(const TemplateList &src, TemplateList &dst) const { if (timeVarying()) { - if (!this->timeInvariantAlias) { - QMutexLocker lock(&aliasLock); - CompositeTransform * non_const = const_cast(this); - non_const->timeInvariantAlias = non_const->smartCopy(); - non_const->timeInvariantAlias->setParent(non_const); - lock.unlock(); - } - timeInvariantAlias->projectUpdate(src,dst); + CompositeTransform * non_const = const_cast(this); + non_const->projectUpdate(src,dst); return; } _project(src, dst); @@ -237,13 +231,10 @@ public: protected: bool isTimeVarying; - mutable QMutex aliasLock; - Transform * timeInvariantAlias; - virtual void _project(const Template & src, Template & dst) const = 0; virtual void _project(const TemplateList & src, TemplateList & dst) const = 0; - CompositeTransform() : TimeVaryingTransform(false) { timeInvariantAlias = NULL; } + CompositeTransform() : TimeVaryingTransform(false) {} }; } diff --git a/openbr/plugins/stream.cpp b/openbr/plugins/stream.cpp index e02092c..7376265 100644 --- a/openbr/plugins/stream.cpp +++ b/openbr/plugins/stream.cpp @@ -958,6 +958,8 @@ public: { if (transforms.isEmpty()) return; + CompositeTransform::init(); + // We share a thread pool across streams attached to the same // parent tranform, retrieve or create a thread pool based // on our parent transform.