Commit 2d868e20ec73d385020602d6c4cad65f0153e543

Authored by jklontz
2 parents 8b3c745f 5f870098

Merge pull request #81 from biometrics/pipe_changes

Changes to Pipe::train
openbr/plugins/meta.cpp
@@ -104,6 +104,25 @@ class PipeTransform : public CompositeTransform @@ -104,6 +104,25 @@ class PipeTransform : public CompositeTransform
104 fprintf(stderr, " training..."); 104 fprintf(stderr, " training...");
105 transforms[i]->train(copy); 105 transforms[i]->train(copy);
106 } 106 }
  107 + // if the transform is time varying, we batch project it.
  108 + if (transforms[i]->timeVarying()) {
  109 + fprintf(stderr, "\n%s projecting...", qPrintable(transforms[i]->objectName()));
  110 + transforms[i]->projectUpdate(copy, copy);
  111 +
  112 + // advance i since we already projected for this stage.
  113 + i++;
  114 +
  115 + // set up the single item lists since they are inconsistent again.
  116 + singleItemLists.clear();
  117 + for (int j=0; j < copy.size(); j++)
  118 + {
  119 + TemplateList temp;
  120 + temp.append(copy[j]);
  121 + singleItemLists.append(temp);
  122 + }
  123 + // the next stage might be trainable, so continue to evaluate it.
  124 + continue;
  125 + }
107 126
108 // We project through any subsequent untrainable transforms at once 127 // We project through any subsequent untrainable transforms at once
109 // as a memory optimization in case any of these intermediate 128 // as a memory optimization in case any of these intermediate
@@ -112,7 +131,8 @@ class PipeTransform : public CompositeTransform @@ -112,7 +131,8 @@ class PipeTransform : public CompositeTransform
112 // by that transform at once if we can avoid it. 131 // by that transform at once if we can avoid it.
113 int nextTrainableTransform = i+1; 132 int nextTrainableTransform = i+1;
114 while ((nextTrainableTransform < transforms.size()) && 133 while ((nextTrainableTransform < transforms.size()) &&
115 - !transforms[nextTrainableTransform]->trainable) 134 + !transforms[nextTrainableTransform]->trainable &&
  135 + !transforms[nextTrainableTransform]->timeVarying())
116 nextTrainableTransform++; 136 nextTrainableTransform++;
117 137
118 fprintf(stderr, " projecting..."); 138 fprintf(stderr, " projecting...");
openbr/plugins/openbr_internal.h
@@ -170,14 +170,8 @@ public: @@ -170,14 +170,8 @@ public:
170 virtual void project(const TemplateList &src, TemplateList &dst) const 170 virtual void project(const TemplateList &src, TemplateList &dst) const
171 { 171 {
172 if (timeVarying()) { 172 if (timeVarying()) {
173 - if (!this->timeInvariantAlias) {  
174 - QMutexLocker lock(&aliasLock);  
175 - CompositeTransform * non_const = const_cast<CompositeTransform *>(this);  
176 - non_const->timeInvariantAlias = non_const->smartCopy();  
177 - non_const->timeInvariantAlias->setParent(non_const);  
178 - lock.unlock();  
179 - }  
180 - timeInvariantAlias->projectUpdate(src,dst); 173 + CompositeTransform * non_const = const_cast<CompositeTransform *>(this);
  174 + non_const->projectUpdate(src,dst);
181 return; 175 return;
182 } 176 }
183 _project(src, dst); 177 _project(src, dst);
@@ -237,13 +231,10 @@ public: @@ -237,13 +231,10 @@ public:
237 protected: 231 protected:
238 bool isTimeVarying; 232 bool isTimeVarying;
239 233
240 - mutable QMutex aliasLock;  
241 - Transform * timeInvariantAlias;  
242 -  
243 virtual void _project(const Template & src, Template & dst) const = 0; 234 virtual void _project(const Template & src, Template & dst) const = 0;
244 virtual void _project(const TemplateList & src, TemplateList & dst) const = 0; 235 virtual void _project(const TemplateList & src, TemplateList & dst) const = 0;
245 236
246 - CompositeTransform() : TimeVaryingTransform(false) { timeInvariantAlias = NULL; } 237 + CompositeTransform() : TimeVaryingTransform(false) {}
247 }; 238 };
248 239
249 } 240 }
openbr/plugins/stream.cpp
@@ -958,6 +958,8 @@ public: @@ -958,6 +958,8 @@ public:
958 { 958 {
959 if (transforms.isEmpty()) return; 959 if (transforms.isEmpty()) return;
960 960
  961 + CompositeTransform::init();
  962 +
961 // We share a thread pool across streams attached to the same 963 // We share a thread pool across streams attached to the same
962 // parent tranform, retrieve or create a thread pool based 964 // parent tranform, retrieve or create a thread pool based
963 // on our parent transform. 965 // on our parent transform.