Commit 6e96c4e040676d007cfc3fbea5f2cf3160054107
1 parent
d29e2df1
CrossValidation with same training across all splits
Showing
8 changed files
with
33 additions
and
11 deletions
openbr/core/core.cpp
| ... | ... | @@ -248,9 +248,8 @@ struct AlgorithmCore |
| 248 | 248 | if (!partitionSizes.empty()) targetPartitions = targets.partition(partitionSizes); |
| 249 | 249 | else targetPartitions.append(targets); |
| 250 | 250 | |
| 251 | - if (queryPartitions[i].first().size() != targetPartitions[i].first().size()) qFatal("Query and target templates have different number of matrices."); | |
| 252 | - | |
| 253 | 251 | outputs[i]->setBlock(queryBlock, targetBlock); |
| 252 | + | |
| 254 | 253 | distance->compare(targetPartitions[i], queryPartitions[i], outputs[i]); |
| 255 | 254 | |
| 256 | 255 | Globals->currentStep += double(targets.size()) * double(queries.size()); | ... | ... |
openbr/core/plot.cpp
| ... | ... | @@ -268,7 +268,7 @@ float Evaluate(const Mat &simmat, const Mat &mask, const QString &csv) |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | // Write Cumulative Match Characteristic (CMC) curve |
| 271 | - const int Max_Retrieval = 100; | |
| 271 | + const int Max_Retrieval = 200; | |
| 272 | 272 | const int Report_Retrieval = 5; |
| 273 | 273 | |
| 274 | 274 | float reportRetrievalRate = -1; |
| ... | ... | @@ -472,6 +472,8 @@ struct RPlot |
| 472 | 472 | } |
| 473 | 473 | }; |
| 474 | 474 | |
| 475 | +// Does not work if dataset folder starts with a number | |
| 476 | + | |
| 475 | 477 | bool Plot(const QStringList &files, const br::File &destination, bool show) |
| 476 | 478 | { |
| 477 | 479 | qDebug("Plotting %d file(s) to %s", files.size(), qPrintable(destination)); | ... | ... |
openbr/openbr_plugin.cpp
| ... | ... | @@ -137,7 +137,7 @@ QVariant File::value(const QString &key) const |
| 137 | 137 | |
| 138 | 138 | QVariant File::parse(const QString &value) |
| 139 | 139 | { |
| 140 | - bool ok; | |
| 140 | + bool ok = false; | |
| 141 | 141 | const QPointF point = QtUtils::toPoint(value, &ok); |
| 142 | 142 | if (ok) return point; |
| 143 | 143 | const QRectF rect = QtUtils::toRect(value, &ok); |
| ... | ... | @@ -1003,7 +1003,7 @@ void Output::reformat(const FileList &targetFiles, const FileList &queryFiles, c |
| 1003 | 1003 | const int columns = targetFiles.size(); |
| 1004 | 1004 | for (int i=0; i<rows; i++) |
| 1005 | 1005 | for (int j=0; j<columns; j++) |
| 1006 | - o->setRelative(m.at<float>(i,i), i, j); | |
| 1006 | + o->setRelative(m.at<float>(i,j), i, j); | |
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | 1009 | /* Output - protected methods */ | ... | ... |
openbr/openbr_plugin.h
| ... | ... | @@ -410,7 +410,7 @@ struct TemplateList : public QList<Template> |
| 410 | 410 | sum+=partitionSizes[i]; |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | - if (sum != first().size()) qFatal("Partition sizes do not span template matrices properly"); | |
| 413 | + if (sum != first().size()) qFatal("Partition sizes %i do not span template matrices %i properly", sum, first().size()); | |
| 414 | 414 | |
| 415 | 415 | foreach (const Template &t, *this) { |
| 416 | 416 | int index = 0; | ... | ... |
openbr/plugins/eigen3.cpp
| ... | ... | @@ -330,6 +330,7 @@ class LDATransform : public Transform |
| 330 | 330 | void train(const TemplateList &_trainingSet) |
| 331 | 331 | { |
| 332 | 332 | TemplateList trainingSet = TemplateList::relabel(_trainingSet); |
| 333 | + | |
| 333 | 334 | int instances = trainingSet.size(); |
| 334 | 335 | |
| 335 | 336 | // Perform PCA dimensionality reduction | ... | ... |
openbr/plugins/format.cpp
| ... | ... | @@ -317,6 +317,7 @@ BR_REGISTER(Format, maskFormat) |
| 317 | 317 | * \brief MATLAB <tt>.mat</tt> format. |
| 318 | 318 | * \author Josh Klontz \cite jklontz |
| 319 | 319 | * http://www.mathworks.com/help/pdf_doc/matlab/matfile_format.pdf |
| 320 | + * \note matFormat is known not to work with compressed matrices | |
| 320 | 321 | */ |
| 321 | 322 | class matFormat : public Format |
| 322 | 323 | { |
| ... | ... | @@ -324,12 +325,18 @@ class matFormat : public Format |
| 324 | 325 | |
| 325 | 326 | struct Element |
| 326 | 327 | { |
| 328 | + // It is always best to cast integers to a Qt integer type, such as qint16 or quint32, when reading and writing. | |
| 329 | + // This ensures that you always know exactly what size integers you are reading and writing, no matter what the | |
| 330 | + // underlying platform and architecture the application happens to be running on. | |
| 331 | + // http://qt-project.org/doc/qt-4.8/datastreamformat.html | |
| 327 | 332 | quint32 type, bytes; |
| 328 | 333 | QByteArray data; |
| 329 | 334 | Element() : type(0), bytes(0) {} |
| 330 | 335 | Element(QDataStream &stream) |
| 331 | 336 | : type(0), bytes(0) |
| 332 | 337 | { |
| 338 | + // Read first 4 bytes into type (32 bit integer), | |
| 339 | + // specifying the type of data used | |
| 333 | 340 | if (stream.readRawData((char*)&type, 4) != 4) |
| 334 | 341 | qFatal("Unexpected end of file."); |
| 335 | 342 | |
| ... | ... | @@ -340,11 +347,16 @@ class matFormat : public Format |
| 340 | 347 | bytes = bytes >> 16; |
| 341 | 348 | } else { |
| 342 | 349 | // Regular format |
| 350 | + // Read 4 bytes into bytes (32 bit integer), | |
| 351 | + // specifying the size of the element | |
| 343 | 352 | if (stream.readRawData((char*)&bytes, 4) != 4) |
| 344 | 353 | qFatal("Unexpected end of file."); |
| 345 | 354 | } |
| 346 | 355 | |
| 356 | + // Set the size of data to bytes | |
| 347 | 357 | data.resize(bytes); |
| 358 | + | |
| 359 | + // Read bytes amount of data from the file into data | |
| 348 | 360 | if (int(bytes) != stream.readRawData(data.data(), bytes)) |
| 349 | 361 | qFatal("Unexpected end of file."); |
| 350 | 362 | |
| ... | ... | @@ -372,8 +384,9 @@ class matFormat : public Format |
| 372 | 384 | while (!f.atEnd()) { |
| 373 | 385 | Element element(f); |
| 374 | 386 | |
| 375 | - // miCOMPRESS | |
| 387 | + // miCOMPRESSED | |
| 376 | 388 | if (element.type == 15) { |
| 389 | + // Prepend the number of bytes to element.data | |
| 377 | 390 | element.data.prepend((char*)&element.bytes, 4); // Qt zlib wrapper requires this to preallocate the buffer |
| 378 | 391 | QDataStream uncompressed(qUncompress(element.data)); |
| 379 | 392 | element = Element(uncompressed); | ... | ... |
openbr/plugins/stasm.cpp
| ... | ... | @@ -34,7 +34,7 @@ BR_REGISTER(Initializer, StasmInitializer) |
| 34 | 34 | * \author Scott Klum \cite sklum |
| 35 | 35 | */ |
| 36 | 36 | // TODO: Use a global mutex to prevent concurrent calls to AsmSearchDll |
| 37 | -#if 0 | |
| 37 | + | |
| 38 | 38 | class StasmTransform : public UntrainableTransform |
| 39 | 39 | { |
| 40 | 40 | Q_OBJECT |
| ... | ... | @@ -46,6 +46,9 @@ class StasmTransform : public UntrainableTransform |
| 46 | 46 | |
| 47 | 47 | void project(const Template &src, Template &dst) const |
| 48 | 48 | { |
| 49 | + static QMutex mutex; | |
| 50 | + QMutexLocker locker(&mutex); | |
| 51 | + | |
| 49 | 52 | int nlandmarks; |
| 50 | 53 | int landmarks[500]; |
| 51 | 54 | |
| ... | ... | @@ -68,7 +71,6 @@ class StasmTransform : public UntrainableTransform |
| 68 | 71 | }; |
| 69 | 72 | |
| 70 | 73 | BR_REGISTER(Transform, StasmTransform) |
| 71 | -#endif | |
| 72 | 74 | |
| 73 | 75 | } // namespace br |
| 74 | 76 | ... | ... |
openbr/plugins/validate.cpp
| ... | ... | @@ -52,8 +52,13 @@ class CrossValidateTransform : public MetaTransform |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | void project(const Template &src, Template &dst) const |
| 55 | - { | |
| 56 | - transforms[src.file.get<int>("Partition", 0)]->project(src, dst); | |
| 55 | + { | |
| 56 | + // If the src partition is greater than the number of training partitions, | |
| 57 | + // assume that projection should be done using the same training data for all partitions. | |
| 58 | + int partition = src.file.get<int>("Partition", 0); | |
| 59 | + if (partition >= transforms.size()-1) partition = 0; | |
| 60 | + | |
| 61 | + transforms[partition]->project(src, dst); | |
| 57 | 62 | } |
| 58 | 63 | |
| 59 | 64 | void store(QDataStream &stream) const | ... | ... |