---------------------------------------------------------------------------*/ * This routine reads in the training * information needed by the adaptive classifier * and saves it into global variables. * Parameters: * load_pre_trained_templates Indicates whether the pre-trained * templates (inttemp, normproto and pffmtable components) * should be
| 525 | * @note History: Mon Mar 11 12:49:34 1991, DSJ, Created. |
| 526 | */ |
| 527 | void Classify::InitAdaptiveClassifier(bool load_pre_trained_templates) { |
| 528 | if (!classify_enable_adaptive_matcher) |
| 529 | return; |
| 530 | if (AllProtosOn != NULL) |
| 531 | EndAdaptiveClassifier(); // Don't leak with multiple inits. |
| 532 | |
| 533 | // If there is no language_data_path_prefix, the classifier will be |
| 534 | // adaptive only. |
| 535 | if (language_data_path_prefix.length() > 0 && |
| 536 | load_pre_trained_templates) { |
| 537 | ASSERT_HOST(tessdata_manager.SeekToStart(TESSDATA_INTTEMP)); |
| 538 | PreTrainedTemplates = |
| 539 | ReadIntTemplates(tessdata_manager.GetDataFilePtr()); |
| 540 | if (tessdata_manager.DebugLevel() > 0) tprintf("Loaded inttemp\n"); |
| 541 | |
| 542 | if (tessdata_manager.SeekToStart(TESSDATA_SHAPE_TABLE)) { |
| 543 | shape_table_ = new ShapeTable(unicharset); |
| 544 | if (!shape_table_->DeSerialize(tessdata_manager.swap(), |
| 545 | tessdata_manager.GetDataFilePtr())) { |
| 546 | tprintf("Error loading shape table!\n"); |
| 547 | delete shape_table_; |
| 548 | shape_table_ = NULL; |
| 549 | } else if (tessdata_manager.DebugLevel() > 0) { |
| 550 | tprintf("Successfully loaded shape table!\n"); |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | ASSERT_HOST(tessdata_manager.SeekToStart(TESSDATA_PFFMTABLE)); |
| 555 | ReadNewCutoffs(tessdata_manager.GetDataFilePtr(), |
| 556 | tessdata_manager.swap(), |
| 557 | tessdata_manager.GetEndOffset(TESSDATA_PFFMTABLE), |
| 558 | CharNormCutoffs); |
| 559 | if (tessdata_manager.DebugLevel() > 0) tprintf("Loaded pffmtable\n"); |
| 560 | |
| 561 | ASSERT_HOST(tessdata_manager.SeekToStart(TESSDATA_NORMPROTO)); |
| 562 | NormProtos = |
| 563 | ReadNormProtos(tessdata_manager.GetDataFilePtr(), |
| 564 | tessdata_manager.GetEndOffset(TESSDATA_NORMPROTO)); |
| 565 | if (tessdata_manager.DebugLevel() > 0) tprintf("Loaded normproto\n"); |
| 566 | static_classifier_ = new TessClassifier(false, this); |
| 567 | } |
| 568 | |
| 569 | im_.Init(&classify_debug_level); |
| 570 | InitIntegerFX(); |
| 571 | |
| 572 | AllProtosOn = NewBitVector(MAX_NUM_PROTOS); |
| 573 | AllConfigsOn = NewBitVector(MAX_NUM_CONFIGS); |
| 574 | AllConfigsOff = NewBitVector(MAX_NUM_CONFIGS); |
| 575 | TempProtoMask = NewBitVector(MAX_NUM_PROTOS); |
| 576 | set_all_bits(AllProtosOn, WordsInVectorOfSize(MAX_NUM_PROTOS)); |
| 577 | set_all_bits(AllConfigsOn, WordsInVectorOfSize(MAX_NUM_CONFIGS)); |
| 578 | zero_all_bits(AllConfigsOff, WordsInVectorOfSize(MAX_NUM_CONFIGS)); |
| 579 | |
| 580 | for (int i = 0; i < MAX_NUM_CLASSES; i++) { |
| 581 | BaselineCutoffs[i] = 0; |
| 582 | } |
| 583 | |
| 584 | if (classify_use_pre_adapted_templates) { |
no test coverage detected