Commit bdf1112049f52c84ba55bf671cca8a609f67856a
1 parent
4fb48f36
Added the option in DownsampleTraining to only train from a specific gallery
Showing
2 changed files
with
13 additions
and
5 deletions
openbr/openbr_plugin.cpp
| ... | ... | @@ -408,7 +408,7 @@ TemplateList TemplateList::fromGallery(const br::File &gallery) |
| 408 | 408 | QStringList labels; |
| 409 | 409 | for (int i=newTemplates.size()-1; i>=0; i--) { |
| 410 | 410 | newTemplates[i].file.set("Index", i+templates.size()); |
| 411 | - newTemplates[i].file.set("Gallery", gallery.name); | |
| 411 | + newTemplates[i].file.set("Gallery", file.name); | |
| 412 | 412 | |
| 413 | 413 | QString label = newTemplates.at(i).file.get<QString>("Label"); |
| 414 | 414 | // Have we seen this subject before? |
| ... | ... | @@ -436,7 +436,7 @@ TemplateList TemplateList::fromGallery(const br::File &gallery) |
| 436 | 436 | } else { |
| 437 | 437 | for (int i=newTemplates.size()-1; i>=0; i--) { |
| 438 | 438 | newTemplates[i].file.set("Index", i+templates.size()); |
| 439 | - newTemplates[i].file.set("Gallery", gallery.name); | |
| 439 | + newTemplates[i].file.set("Gallery", file.name); | |
| 440 | 440 | |
| 441 | 441 | if (crossValidate > 0) { |
| 442 | 442 | if (newTemplates[i].file.getBool("duplicatePartitions")) { | ... | ... |
openbr/plugins/independent.cpp
| ... | ... | @@ -9,12 +9,13 @@ using namespace cv; |
| 9 | 9 | namespace br |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | -static TemplateList Downsample(const TemplateList &templates, int classes, int instances, float fraction, const QString & inputVariable) | |
| 12 | +static TemplateList Downsample(const TemplateList &templates, int classes, int instances, float fraction, const QString & inputVariable, const QString &gallery) | |
| 13 | 13 | { |
| 14 | 14 | // Return early when no downsampling is required |
| 15 | 15 | if ((classes == std::numeric_limits<int>::max()) && |
| 16 | 16 | (instances == std::numeric_limits<int>::max()) && |
| 17 | - (fraction >= 1)) | |
| 17 | + (fraction >= 1) && | |
| 18 | + (gallery.isEmpty())) | |
| 18 | 19 | return templates; |
| 19 | 20 | |
| 20 | 21 | const bool atLeast = instances < 0; |
| ... | ... | @@ -60,6 +61,11 @@ static TemplateList Downsample(const TemplateList &templates, int classes, int i |
| 60 | 61 | downsample = downsample.mid(0, downsample.size()*fraction); |
| 61 | 62 | } |
| 62 | 63 | |
| 64 | + if (!gallery.isEmpty()) | |
| 65 | + foreach(const Template &t, templates) | |
| 66 | + if (t.file.get<QString>("Gallery") == gallery) | |
| 67 | + downsample.append(t); | |
| 68 | + | |
| 63 | 69 | return downsample; |
| 64 | 70 | } |
| 65 | 71 | |
| ... | ... | @@ -71,11 +77,13 @@ class DownsampleTrainingTransform : public Transform |
| 71 | 77 | Q_PROPERTY(int instances READ get_instances WRITE set_instances RESET reset_instances STORED false) |
| 72 | 78 | Q_PROPERTY(float fraction READ get_fraction WRITE set_fraction RESET reset_fraction STORED false) |
| 73 | 79 | Q_PROPERTY(QString inputVariable READ get_inputVariable WRITE set_inputVariable RESET reset_inputVariable STORED false) |
| 80 | + Q_PROPERTY(QString gallery READ get_gallery WRITE set_gallery RESET reset_gallery STORED false) | |
| 74 | 81 | BR_PROPERTY(br::Transform*, transform, NULL) |
| 75 | 82 | BR_PROPERTY(int, classes, std::numeric_limits<int>::max()) |
| 76 | 83 | BR_PROPERTY(int, instances, std::numeric_limits<int>::max()) |
| 77 | 84 | BR_PROPERTY(float, fraction, 1) |
| 78 | 85 | BR_PROPERTY(QString, inputVariable, "Label") |
| 86 | + BR_PROPERTY(QString, gallery, QString()) | |
| 79 | 87 | |
| 80 | 88 | void project(const Template & src, Template & dst) const |
| 81 | 89 | { |
| ... | ... | @@ -88,7 +96,7 @@ class DownsampleTrainingTransform : public Transform |
| 88 | 96 | if (!transform || !transform->trainable) |
| 89 | 97 | return; |
| 90 | 98 | |
| 91 | - TemplateList downsampled = Downsample(data, classes, instances, fraction, inputVariable); | |
| 99 | + TemplateList downsampled = Downsample(data, classes, instances, fraction, inputVariable, gallery); | |
| 92 | 100 | transform->train(downsampled); |
| 93 | 101 | } |
| 94 | 102 | }; | ... | ... |