Commit 242292801ef703267d59ca8a96ed7b81af1c8feb
1 parent
74762655
Remove FileList return from br::Enroll
With this, we will not have to accumulate the file metadata during enroll which will help with memory use on large jobs. Functions actually using the return type (gui/classifier.cpp, and gallerytoolbar.cpp) updated to avoid using it directly. In gallerytoolbar.cpp, drop support for implicit enrollment to a .gal file.
Showing
4 changed files
with
16 additions
and
15 deletions
openbr/core/core.cpp
| ... | ... | @@ -161,15 +161,13 @@ struct AlgorithmCore |
| 161 | 161 | return name + file.baseName() + file.hash() + ".mem"; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - FileList enroll(File input, File gallery = File()) | |
| 164 | + void enroll(File input, File gallery = File()) | |
| 165 | 165 | { |
| 166 | - FileList files; | |
| 167 | - | |
| 168 | 166 | qDebug("Enrolling %s%s", qPrintable(input.flat()), |
| 169 | 167 | gallery.isNull() ? "" : qPrintable(" to " + gallery.flat())); |
| 170 | 168 | |
| 171 | 169 | if (gallery.name.isEmpty()) { |
| 172 | - if (input.name.isEmpty()) return FileList(); | |
| 170 | + if (input.name.isEmpty()) return; | |
| 173 | 171 | else gallery = getMemoryGallery(input); |
| 174 | 172 | } |
| 175 | 173 | |
| ... | ... | @@ -212,12 +210,8 @@ struct AlgorithmCore |
| 212 | 210 | progressCounter->setPropertyRecursive("totalProgress", QString::number(total)); |
| 213 | 211 | stream->projectUpdate(data, output); |
| 214 | 212 | |
| 215 | - files.append(output.files()); | |
| 216 | - | |
| 217 | 213 | if (multiProcess) |
| 218 | 214 | delete enroll; |
| 219 | - | |
| 220 | - return files; | |
| 221 | 215 | } |
| 222 | 216 | |
| 223 | 217 | void project(File input, File output) |
| ... | ... | @@ -632,9 +626,9 @@ void br::Train(const File &input, const File &model) |
| 632 | 626 | AlgorithmManager::getAlgorithm(model.get<QString>("algorithm"))->train(input, model); |
| 633 | 627 | } |
| 634 | 628 | |
| 635 | -FileList br::Enroll(const File &input, const File &gallery) | |
| 629 | +void br::Enroll(const File &input, const File &gallery) | |
| 636 | 630 | { |
| 637 | - return AlgorithmManager::getAlgorithm(gallery.get<QString>("algorithm"))->enroll(input, gallery); | |
| 631 | + AlgorithmManager::getAlgorithm(gallery.get<QString>("algorithm"))->enroll(input, gallery); | |
| 638 | 632 | } |
| 639 | 633 | |
| 640 | 634 | void br::Project(const File &input, const File &output) | ... | ... |
openbr/gui/classifier.cpp
| ... | ... | @@ -37,7 +37,13 @@ void Classifier::setClassification(const QString &key, const QString &value) |
| 37 | 37 | void Classifier::_classify(File file) |
| 38 | 38 | { |
| 39 | 39 | QString key, value; |
| 40 | - foreach (const File &f, Enroll(file.flat(), File("[algorithm=" + algorithm + "]"))) { | |
| 40 | + QSharedPointer<Transform> transform = Transform::fromAlgorithm(algorithm); | |
| 41 | + | |
| 42 | + TemplateList input, output; | |
| 43 | + input.append(file); | |
| 44 | + transform->projectUpdate(input, output); | |
| 45 | + | |
| 46 | + foreach (const File &f, output.files() ) { | |
| 41 | 47 | if (algorithm == "GenderClassification") key = "Gender"; |
| 42 | 48 | else if (algorithm == "AgeRegression") key = "Age"; |
| 43 | 49 | else key = algorithm; | ... | ... |
openbr/gui/gallerytoolbar.cpp
| ... | ... | @@ -83,9 +83,10 @@ void br::GalleryToolBar::_enroll(const br::File &input) |
| 83 | 83 | { |
| 84 | 84 | galleryLock.lock(); |
| 85 | 85 | this->input = input; |
| 86 | - if (input.suffix() == "gal") gallery = input.name + ".mem"; | |
| 87 | - else gallery = QString("%1/galleries/%2.gal[cache]").arg(br::Globals->scratchPath(), qPrintable(input.baseName()+input.hash())); | |
| 88 | - files = br::Enroll(input.flat(), gallery.flat()); | |
| 86 | + gallery = input.name + ".mem"; | |
| 87 | + br::Enroll(input.flat(), gallery.flat()); | |
| 88 | + files = FileList::fromGallery(gallery); | |
| 89 | + | |
| 89 | 90 | galleryLock.unlock(); |
| 90 | 91 | } |
| 91 | 92 | ... | ... |
openbr/openbr_plugin.h
| ... | ... | @@ -1393,7 +1393,7 @@ BR_EXPORT void Train(const File &input, const File &model); |
| 1393 | 1393 | * \brief High-level function for creating galleries. |
| 1394 | 1394 | * \see br_enroll |
| 1395 | 1395 | */ |
| 1396 | -BR_EXPORT FileList Enroll(const File &input, const File &gallery = File()); | |
| 1396 | +BR_EXPORT void Enroll(const File &input, const File &gallery = File()); | |
| 1397 | 1397 | |
| 1398 | 1398 | /*! |
| 1399 | 1399 | * \brief High-level function for enrolling templates. | ... | ... |