#include <params_model.h>
Definition at line 30 of file params_model.h.
◆ PassEnum
Enumerator |
---|
PTRAIN_PASS1 | |
PTRAIN_PASS2 | |
PTRAIN_NUM_PASSES | |
Definition at line 33 of file params_model.h.
◆ ParamsModel() [1/2]
tesseract::ParamsModel::ParamsModel |
( |
| ) |
|
|
inline |
◆ ParamsModel() [2/2]
tesseract::ParamsModel::ParamsModel |
( |
const char * |
lang, |
|
|
const std::vector< float > & |
weights |
|
) |
| |
|
inline |
Definition at line 41 of file params_model.h.
44 }
const std::vector< float > & weights() const
◆ Clear()
void tesseract::ParamsModel::Clear |
( |
| ) |
|
|
inline |
Definition at line 51 of file params_model.h.
51 {
52 for (
auto &
p : weights_vec_) {
54 }
55 }
◆ ComputeCost()
float tesseract::ParamsModel::ComputeCost |
( |
const float |
features[] | ) |
const |
Definition at line 81 of file params_model.cpp.
81 {
82 float unnorm_score = 0.0;
84 unnorm_score += weights_vec_[pass_][f] * features[f];
85 }
86 return ClipToRange(-unnorm_score / kScoreScaleFactor, kMinFinalCost, kMaxFinalCost);
87}
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
@ PTRAIN_NUM_FEATURE_TYPES
◆ Copy()
void tesseract::ParamsModel::Copy |
( |
const ParamsModel & |
other_model | ) |
|
◆ Equivalent()
bool tesseract::ParamsModel::Equivalent |
( |
const ParamsModel & |
that | ) |
const |
Definition at line 89 of file params_model.cpp.
89 {
90 float epsilon = 0.0001f;
92 if (weights_vec_[
p].size() != that.weights_vec_[
p].size()) {
93 return false;
94 }
95 for (
unsigned i = 0;
i < weights_vec_[
p].size();
i++) {
96 if (weights_vec_[
p][
i] != that.weights_vec_[
p][
i] &&
97 std::fabs(weights_vec_[
p][
i] - that.weights_vec_[
p][
i]) > epsilon) {
98 return false;
99 }
100 }
101 }
102 return true;
103}
◆ Initialized()
bool tesseract::ParamsModel::Initialized |
( |
| ) |
|
|
inline |
◆ LoadFromFp()
bool tesseract::ParamsModel::LoadFromFp |
( |
const char * |
lang, |
|
|
TFile * |
fp |
|
) |
| |
Definition at line 105 of file params_model.cpp.
105 {
106 const int kMaxLineSize = 100;
107 char line[kMaxLineSize];
108 BitVector present;
110 lang_ = lang;
111
112 std::vector<float> &
weights = weights_vec_[pass_];
115
116 while (fp->FGets(line, kMaxLineSize) != nullptr) {
117 char *key = nullptr;
119 if (!ParseLine(line, &key, &
value)) {
120 continue;
121 }
123 if (idx < 0) {
124 tprintf(
"ParamsModel::Unknown parameter %s\n", key);
125 continue;
126 }
127 if (!present[idx]) {
128 present.SetValue(idx, true);
129 }
131 }
133 if (!complete) {
136 tprintf(
"Missing field %s.\n", kParamsTrainingFeatureTypeName[
i]);
137 }
138 }
139 lang_ = "";
141 }
142 return complete;
143}
int ParamsTrainingFeatureByName(const char *name)
void tprintf(const char *format,...)
◆ Print()
void tesseract::ParamsModel::Print |
( |
| ) |
|
Definition at line 39 of file params_model.cpp.
39 {
41 tprintf(
"ParamsModel for pass %d lang %s\n",
p, lang_.c_str());
42 for (
unsigned i = 0;
i < weights_vec_[
p].size(); ++
i) {
43 tprintf(
"%s = %g\n", kParamsTrainingFeatureTypeName[
i], weights_vec_[
p][
i]);
44 }
45 }
46}
◆ SaveToFile()
bool tesseract::ParamsModel::SaveToFile |
( |
const char * |
full_path | ) |
const |
Definition at line 145 of file params_model.cpp.
145 {
146 const std::vector<float> &
weights = weights_vec_[pass_];
148 tprintf(
"Refusing to save ParamsModel that has not been initialized.\n");
149 return false;
150 }
151 FILE *fp = fopen(full_path, "wb");
152 if (!fp) {
153 tprintf(
"Could not open %s for writing.\n", full_path);
154 return false;
155 }
156 bool all_good = true;
157 for (
unsigned i = 0;
i <
weights.size();
i++) {
158 if (fprintf(fp,
"%s %f\n", kParamsTrainingFeatureTypeName[
i],
weights[
i]) < 0) {
159 all_good = false;
160 }
161 }
162 fclose(fp);
163 return all_good;
164}
◆ SetPass()
void tesseract::ParamsModel::SetPass |
( |
PassEnum |
pass | ) |
|
|
inline |
◆ weights()
const std::vector< float > & tesseract::ParamsModel::weights |
( |
| ) |
const |
|
inline |
Definition at line 69 of file params_model.h.
69 {
70 return weights_vec_[pass_];
71 }
◆ weights_for_pass()
const std::vector< float > & tesseract::ParamsModel::weights_for_pass |
( |
PassEnum |
pass | ) |
const |
|
inline |
Definition at line 72 of file params_model.h.
72 {
73 return weights_vec_[pass];
74 }
The documentation for this class was generated from the following files:
- /media/home/debian/src/github/tesseract-ocr/tesseract/src/wordrec/params_model.h
- /media/home/debian/src/github/tesseract-ocr/tesseract/src/wordrec/params_model.cpp