Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
conv_net_classifier.h
Go to the documentation of this file.
1 /**********************************************************************
2 * File: conv_net_classifier.h
3 * Description: Declaration of Convolutional-NeuralNet Character Classifier
4 * Author: Ahmad Abdulkader
5 * Created: 2007
6 *
7 * (C) Copyright 2008, Google Inc.
8 ** Licensed under the Apache License, Version 2.0 (the "License");
9 ** you may not use this file except in compliance with the License.
10 ** You may obtain a copy of the License at
11 ** http://www.apache.org/licenses/LICENSE-2.0
12 ** Unless required by applicable law or agreed to in writing, software
13 ** distributed under the License is distributed on an "AS IS" BASIS,
14 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ** See the License for the specific language governing permissions and
16 ** limitations under the License.
17 *
18 **********************************************************************/
19
20 // The ConvNetCharClassifier inherits from the base classifier class:
21 // "CharClassifierBase". It implements a Convolutional Neural Net classifier
22 // instance of the base classifier. It uses the Tesseract Neural Net library
23 // The Neural Net takes a scaled version of a bitmap and feeds it to a
24 // Convolutional Neural Net as input and performs a FeedForward. Each output
25 // of the net corresponds to class_id in the CharSet passed at construction
26 // time.
27 // Afterwards, the outputs of the Net are "folded" using the folding set
28 // (if any)
29 #ifndef CONV_NET_CLASSIFIER_H
30 #define CONV_NET_CLASSIFIER_H
31
32 #include <string>
33 #include "char_samp.h"
34 #include "char_altlist.h"
35 #include "char_set.h"
36 #include "feature_base.h"
37 #include "classifier_base.h"
38 #include "neural_net.h"
39 #include "lang_model.h"
40 #include "tuning_params.h"
41
42 namespace tesseract {
43
44 // Folding Ratio is the ratio of the max-activation of members of a folding
45 // set that is used to compute the min-activation of the rest of the set
46 static const float kFoldingRatio = 0.75;
47
48 class ConvNetCharClassifier : public CharClassifier {
49 public:
50 ConvNetCharClassifier(CharSet *char_set, TuningParams *params,
51 FeatureBase *feat_extract);
52 virtual ~ConvNetCharClassifier();
53 // The main training function. Given a sample and a class ID the classifier
54 // updates its parameters according to its learning algorithm. This function
55 // is currently not implemented. TODO(ahmadab): implement end-2-end training
56 virtual bool Train(CharSamp *char_samp, int ClassID);
57 // A secondary function needed for training. Allows the trainer to set the
58 // value of any train-time paramter. This function is currently not
59 // implemented. TODO(ahmadab): implement end-2-end training
60 virtual bool SetLearnParam(char *var_name, float val);
61 // Externally sets the Neural Net used by the classifier. Used for training
62 void SetNet(tesseract::NeuralNet *net);
63
64 // Classifies an input charsamp and return a CharAltList object containing
65 // the possible candidates and corresponding scores
66 virtual CharAltList * Classify(CharSamp *char_samp);
67 // Computes the cost of a specific charsamp being a character (versus a
68 // non-character: part-of-a-character OR more-than-one-character)
69 virtual int CharCost(CharSamp *char_samp);
70
71
72 private:
73 // Neural Net object used for classification
74 tesseract::NeuralNet *char_net_;
75 // data buffers used to hold Neural Net inputs and outputs
76 float *net_input_;
77 float *net_output_;
78
79 // Init the classifier provided a data-path and a language string
80 virtual bool Init(const string &data_file_path, const string &lang,
81 LangModel *lang_mod);
82 // Loads the NeuralNets needed for the classifier
83 bool LoadNets(const string &data_file_path, const string &lang);
84 // Loads the folding sets provided a data-path and a language string
85 virtual bool LoadFoldingSets(const string &data_file_path,
86 const string &lang,
87 LangModel *lang_mod);
88 // Folds the output of the NeuralNet using the loaded folding sets
89 virtual void Fold();
90 // Scales the input char_samp and feeds it to the NeuralNet as input
91 bool RunNets(CharSamp *char_samp);
92 };
93 }
94 #endif // CONV_NET_CLASSIFIER_H