Commit 91eff7dd38b595f097b07e7d35b698005218ce8a
1 parent
e6ad9c22
Refactored from gallery a bit
Showing
1 changed file
with
30 additions
and
32 deletions
openbr/openbr_plugin.cpp
| @@ -392,42 +392,41 @@ TemplateList TemplateList::fromGallery(const br::File &gallery) | @@ -392,42 +392,41 @@ TemplateList TemplateList::fromGallery(const br::File &gallery) | ||
| 392 | 392 | ||
| 393 | const int crossValidate = gallery.get<int>("crossValidate"); | 393 | const int crossValidate = gallery.get<int>("crossValidate"); |
| 394 | 394 | ||
| 395 | - if (gallery.getBool("leaveOneImageOut")) { | ||
| 396 | - QStringList labels; | ||
| 397 | - for (int i=newTemplates.size()-1; i>=0; i--) { | 395 | + for (int i=newTemplates.size()-1; i>=0; i--) { |
| 398 | newTemplates[i].file.set("Index", i+templates.size()); | 396 | newTemplates[i].file.set("Index", i+templates.size()); |
| 399 | newTemplates[i].file.set("Gallery", gallery.name); | 397 | newTemplates[i].file.set("Gallery", gallery.name); |
| 400 | 398 | ||
| 401 | - QString label = newTemplates.at(i).file.get<QString>("Label"); | ||
| 402 | - // Have we seen this subject before? | ||
| 403 | - if (!labels.contains(label)) { | ||
| 404 | - labels.append(label); | ||
| 405 | - // Get indices belonging to this subject | ||
| 406 | - QList<int> labelIndices = newTemplates.find("Label",label); | ||
| 407 | - for (int j = 0; j < labelIndices.size(); j++) { | ||
| 408 | - // Set subject partitions | ||
| 409 | - newTemplates[labelIndices[j]].file.set("Partition",j%crossValidate); | ||
| 410 | - } | ||
| 411 | - // Extend the gallery for each partition | ||
| 412 | - for (int j=0; j<labelIndices.size(); j++) { | ||
| 413 | - for (int k=0; k<crossValidate; k++) { | ||
| 414 | - Template leaveOneImageOutTemplate = newTemplates[labelIndices[j]]; | ||
| 415 | - if (k!=leaveOneImageOutTemplate.file.get<int>("Partition")) { | ||
| 416 | - leaveOneImageOutTemplate.file.set("Partition", k); | ||
| 417 | - leaveOneImageOutTemplate.file.set("testOnly", true); | ||
| 418 | - newTemplates.insert(i+1,leaveOneImageOutTemplate); | 399 | + if (crossValidate > 0) { |
| 400 | + if (gallery.getBool("leaveOneImageOut")) { | ||
| 401 | + QStringList labels; | ||
| 402 | + for (int i=newTemplates.size()-1; i>=0; i--) { | ||
| 403 | + newTemplates[i].file.set("Index", i+templates.size()); | ||
| 404 | + newTemplates[i].file.set("Gallery", gallery.name); | ||
| 405 | + | ||
| 406 | + QString label = newTemplates.at(i).file.get<QString>("Label"); | ||
| 407 | + // Have we seen this subject before? | ||
| 408 | + if (!labels.contains(label)) { | ||
| 409 | + labels.append(label); | ||
| 410 | + // Get indices belonging to this subject | ||
| 411 | + QList<int> labelIndices = newTemplates.find("Label",label); | ||
| 412 | + for (int j = 0; j < labelIndices.size(); j++) { | ||
| 413 | + // Set subject partitions | ||
| 414 | + newTemplates[labelIndices[j]].file.set("Partition",j%crossValidate); | ||
| 415 | + } | ||
| 416 | + // Extend the gallery for each partition | ||
| 417 | + for (int j=0; j<labelIndices.size(); j++) { | ||
| 418 | + for (int k=0; k<crossValidate; k++) { | ||
| 419 | + Template leaveOneImageOutTemplate = newTemplates[labelIndices[j]]; | ||
| 420 | + if (k!=leaveOneImageOutTemplate.file.get<int>("Partition")) { | ||
| 421 | + leaveOneImageOutTemplate.file.set("Partition", k); | ||
| 422 | + leaveOneImageOutTemplate.file.set("testOnly", true); | ||
| 423 | + newTemplates.insert(i+1,leaveOneImageOutTemplate); | ||
| 424 | + } | ||
| 425 | + } | ||
| 426 | + } | ||
| 419 | } | 427 | } |
| 420 | } | 428 | } |
| 421 | - } | ||
| 422 | - } | ||
| 423 | - } | ||
| 424 | - } else { | ||
| 425 | - for (int i=newTemplates.size()-1; i>=0; i--) { | ||
| 426 | - newTemplates[i].file.set("Index", i+templates.size()); | ||
| 427 | - newTemplates[i].file.set("Gallery", gallery.name); | ||
| 428 | - | ||
| 429 | - if (crossValidate > 0) { | ||
| 430 | - if (newTemplates[i].file.getBool("duplicatePartitions")) { | 429 | + } else if (newTemplates[i].file.getBool("duplicatePartitions")) { |
| 431 | // The duplicatePartitions flag is used to add target images | 430 | // The duplicatePartitions flag is used to add target images |
| 432 | // crossValidate times to the simmat/mask | 431 | // crossValidate times to the simmat/mask |
| 433 | // when multiple training sets are being used | 432 | // when multiple training sets are being used |
| @@ -454,7 +453,6 @@ TemplateList TemplateList::fromGallery(const br::File &gallery) | @@ -454,7 +453,6 @@ TemplateList TemplateList::fromGallery(const br::File &gallery) | ||
| 454 | } | 453 | } |
| 455 | } | 454 | } |
| 456 | } | 455 | } |
| 457 | - } | ||
| 458 | } | 456 | } |
| 459 | 457 | ||
| 460 | if (!templates.isEmpty() && gallery.get<bool>("merge", false)) { | 458 | if (!templates.isEmpty() && gallery.get<bool>("merge", false)) { |