Commit e4df71435b705282a7dc8e8d4b11cd3afc6b6c1c
1 parent
fa9cbd42
Preliminary version of an alternate enroll implementation based on stream
Instead of processing things in blocks, this version wraps the transform in a stream, with the input transform as 1 stage, and the other stage having transforms that estimate time to completion, nad output templates to a gallery
Showing
1 changed file
with
18 additions
and
59 deletions
openbr/core/core.cpp
| @@ -19,6 +19,7 @@ | @@ -19,6 +19,7 @@ | ||
| 19 | #include "bee.h" | 19 | #include "bee.h" |
| 20 | #include "common.h" | 20 | #include "common.h" |
| 21 | #include "qtutils.h" | 21 | #include "qtutils.h" |
| 22 | +#include "../plugins/openbr_internal.h" | ||
| 22 | 23 | ||
| 23 | using namespace br; | 24 | using namespace br; |
| 24 | 25 | ||
| @@ -46,6 +47,7 @@ struct AlgorithmCore | @@ -46,6 +47,7 @@ struct AlgorithmCore | ||
| 46 | 47 | ||
| 47 | TemplateList data(TemplateList::fromGallery(input)); | 48 | TemplateList data(TemplateList::fromGallery(input)); |
| 48 | 49 | ||
| 50 | + | ||
| 49 | // set the Train bool metadata, in case a Transform's project | 51 | // set the Train bool metadata, in case a Transform's project |
| 50 | // needs to know if it's called during train or enroll | 52 | // needs to know if it's called during train or enroll |
| 51 | for (int i=0; i<data.size(); i++) | 53 | for (int i=0; i<data.size(); i++) |
| @@ -123,65 +125,24 @@ struct AlgorithmCore | @@ -123,65 +125,24 @@ struct AlgorithmCore | ||
| 123 | else gallery = getMemoryGallery(input); | 125 | else gallery = getMemoryGallery(input); |
| 124 | } | 126 | } |
| 125 | 127 | ||
| 126 | - QScopedPointer<Gallery> g(Gallery::make(gallery)); | ||
| 127 | - if (g.isNull()) qFatal("Null gallery!"); | ||
| 128 | - | ||
| 129 | - do { | ||
| 130 | - fileList.clear(); | ||
| 131 | - | ||
| 132 | - if (gallery.contains("read") || gallery.contains("cache")) | ||
| 133 | - fileList = g->files(); | ||
| 134 | - | ||
| 135 | - if (!fileList.isEmpty() && gallery.contains("cache")) | ||
| 136 | - return fileList; | ||
| 137 | - | ||
| 138 | - const TemplateList i(TemplateList::fromGallery(input)); | ||
| 139 | - if (i.isEmpty()) return fileList; // Nothing to enroll | ||
| 140 | - | ||
| 141 | - if (transform.isNull()) qFatal("Null transform."); | ||
| 142 | - const int blocks = Globals->blocks(i.size()); | ||
| 143 | - Globals->currentStep = 0; | ||
| 144 | - Globals->totalSteps = i.size(); | ||
| 145 | - Globals->startTime.start(); | ||
| 146 | - | ||
| 147 | - const bool noDuplicates = gallery.contains("noDuplicates"); | ||
| 148 | - QStringList fileNames = noDuplicates ? fileList.names() : QStringList(); | ||
| 149 | - const int subBlockSize = 4*std::max(1, Globals->parallelism); | ||
| 150 | - const int numSubBlocks = ceil(1.0*Globals->blockSize/subBlockSize); | ||
| 151 | - int totalCount = 0, failureCount = 0; | ||
| 152 | - double totalBytes = 0; | ||
| 153 | - for (int block=0; block<blocks; block++) { | ||
| 154 | - for (int subBlock = 0; subBlock<numSubBlocks; subBlock++) { | ||
| 155 | - TemplateList data = i.mid(block*Globals->blockSize + subBlock*subBlockSize, subBlockSize); | ||
| 156 | - if (data.isEmpty()) break; | ||
| 157 | - if (noDuplicates) | ||
| 158 | - for (int i=data.size()-1; i>=0; i--) | ||
| 159 | - if (fileNames.contains(data[i].file.name)) | ||
| 160 | - data.removeAt(i); | ||
| 161 | - const int numFiles = data.size(); | ||
| 162 | - | ||
| 163 | - data >> *transform; | ||
| 164 | - | ||
| 165 | - g->writeBlock(data); | ||
| 166 | - const FileList newFiles = data.files(); | ||
| 167 | - fileList.append(newFiles); | ||
| 168 | - | ||
| 169 | - totalCount += newFiles.size(); | ||
| 170 | - failureCount += newFiles.failures(); | ||
| 171 | - totalBytes += data.bytes<double>(); | ||
| 172 | - Globals->currentStep += numFiles; | ||
| 173 | - Globals->printStatus(); | ||
| 174 | - } | ||
| 175 | - } | 128 | + TemplateList i(TemplateList::fromGallery(input)); |
| 129 | + | ||
| 130 | + QString shellDescription = "DirectStream([Identity,ProgressCounter("+QString::number(i.length())+")+GalleryOutput("+gallery.flat()+")+Discard],readMode=DistributeFrames)"; | ||
| 131 | + qDebug("built shell string %s", qPrintable(shellDescription)); | ||
| 132 | + // Make a stream with a placeholder first transform, and our progress counter/gallery output. | ||
| 133 | + QScopedPointer<Transform> enrollJob(Transform::make(shellDescription, NULL)); | ||
| 134 | + | ||
| 135 | + CompositeTransform * downcast = dynamic_cast<CompositeTransform *>(enrollJob.data()); | ||
| 136 | + if (downcast == NULL) | ||
| 137 | + qFatal("downcast failed?"); | ||
| 138 | + | ||
| 139 | + downcast->transforms[0] = this->transform.data(); | ||
| 140 | + downcast->init(); | ||
| 141 | + | ||
| 176 | 142 | ||
| 177 | - const float speed = 1000 * Globals->totalSteps / Globals->startTime.elapsed() / std::max(1, abs(Globals->parallelism)); | ||
| 178 | - if (!Globals->quiet && (Globals->totalSteps > 1)) | ||
| 179 | - fprintf(stderr, "\rSPEED=%.1e SIZE=%.4g FAILURES=%d/%d \n", | ||
| 180 | - speed, totalBytes/totalCount, failureCount, totalCount); | ||
| 181 | - Globals->totalSteps = 0; | ||
| 182 | - } while (input.getBool("infinite")); | 143 | + downcast->projectUpdate(i,i); |
| 183 | 144 | ||
| 184 | - return fileList; | 145 | + return i.files(); |
| 185 | } | 146 | } |
| 186 | 147 | ||
| 187 | void retrieveOrEnroll(const File &file, QScopedPointer<Gallery> &gallery, FileList &galleryFiles) | 148 | void retrieveOrEnroll(const File &file, QScopedPointer<Gallery> &gallery, FileList &galleryFiles) |
| @@ -306,8 +267,6 @@ private: | @@ -306,8 +267,6 @@ private: | ||
| 306 | if ((words.size() < 1) || (words.size() > 2)) qFatal("Invalid algorithm format."); | 267 | if ((words.size() < 1) || (words.size() > 2)) qFatal("Invalid algorithm format."); |
| 307 | //! [Parsing the algorithm description] | 268 | //! [Parsing the algorithm description] |
| 308 | 269 | ||
| 309 | - if (description.getBool("distribute", true)) | ||
| 310 | - words[0] = "DistributeTemplate(" + words[0] + ")"; | ||
| 311 | 270 | ||
| 312 | //! [Creating the template generation and comparison methods] | 271 | //! [Creating the template generation and comparison methods] |
| 313 | transform = QSharedPointer<Transform>(Transform::make(words[0], NULL)); | 272 | transform = QSharedPointer<Transform>(Transform::make(words[0], NULL)); |