Tests a classifier, computing its error rate. See errorcounter.h for description of arguments. Iterates over the samples, calling the classifier in normal/silent mode. If the classifier makes a CT_UNICHAR_TOPN_ERR error, and the appropriate report_level is set (4 or greater), it will then call the classifier again with a debug flag and a keep_this argument to find out what is going on.
| 37 | // report_level is set (4 or greater), it will then call the classifier again |
| 38 | // with a debug flag and a keep_this argument to find out what is going on. |
| 39 | double ErrorCounter::ComputeErrorRate(ShapeClassifier* classifier, |
| 40 | int report_level, CountTypes boosting_mode, |
| 41 | const FontInfoTable& fontinfo_table, |
| 42 | const GenericVector<Pix*>& page_images, SampleIterator* it, |
| 43 | double* unichar_error, double* scaled_error, STRING* fonts_report) { |
| 44 | int fontsize = it->sample_set()->NumFonts(); |
| 45 | ErrorCounter counter(classifier->GetUnicharset(), fontsize); |
| 46 | GenericVector<UnicharRating> results; |
| 47 | |
| 48 | clock_t start = clock(); |
| 49 | int total_samples = 0; |
| 50 | double unscaled_error = 0.0; |
| 51 | // Set a number of samples on which to run the classify debug mode. |
| 52 | int error_samples = report_level > 3 ? report_level * report_level : 0; |
| 53 | // Iterate over all the samples, accumulating errors. |
| 54 | for (it->Begin(); !it->AtEnd(); it->Next()) { |
| 55 | TrainingSample* mutable_sample = it->MutableSample(); |
| 56 | int page_index = mutable_sample->page_num(); |
| 57 | Pix* page_pix = 0 <= page_index && page_index < page_images.size() |
| 58 | ? page_images[page_index] : NULL; |
| 59 | // No debug, no keep this. |
| 60 | classifier->UnicharClassifySample(*mutable_sample, page_pix, 0, |
| 61 | INVALID_UNICHAR_ID, &results); |
| 62 | bool debug_it = false; |
| 63 | int correct_id = mutable_sample->class_id(); |
| 64 | if (counter.unicharset_.has_special_codes() && |
| 65 | (correct_id == UNICHAR_SPACE || correct_id == UNICHAR_JOINED || |
| 66 | correct_id == UNICHAR_BROKEN)) { |
| 67 | // This is junk so use the special counter. |
| 68 | debug_it = counter.AccumulateJunk(report_level > 3, |
| 69 | results, |
| 70 | mutable_sample); |
| 71 | } else { |
| 72 | debug_it = counter.AccumulateErrors(report_level > 3, boosting_mode, |
| 73 | fontinfo_table, |
| 74 | results, mutable_sample); |
| 75 | } |
| 76 | if (debug_it && error_samples > 0) { |
| 77 | // Running debug, keep the correct answer, and debug the classifier. |
| 78 | tprintf("Error on sample %d: %s Classifier debug output:\n", |
| 79 | it->GlobalSampleIndex(), |
| 80 | it->sample_set()->SampleToString(*mutable_sample).string()); |
| 81 | classifier->DebugDisplay(*mutable_sample, page_pix, correct_id); |
| 82 | --error_samples; |
| 83 | } |
| 84 | ++total_samples; |
| 85 | } |
| 86 | double total_time = 1.0 * (clock() - start) / CLOCKS_PER_SEC; |
| 87 | // Create the appropriate error report. |
| 88 | unscaled_error = counter.ReportErrors(report_level, boosting_mode, |
| 89 | fontinfo_table, |
| 90 | *it, unichar_error, fonts_report); |
| 91 | if (scaled_error != NULL) *scaled_error = counter.scaled_error_; |
| 92 | if (report_level > 1) { |
| 93 | // It is useful to know the time in microseconds/char. |
| 94 | tprintf("Errors computed in %.2fs at %.1f μs/char\n", |
| 95 | total_time, 1000000.0 * total_time / total_samples); |
| 96 | } |
nothing calls this directly
no test coverage detected