#include <params_model.h>
Definition at line 31 of file params_model.h.
◆ PassEnum
Enumerator |
---|
PTRAIN_PASS1 | |
PTRAIN_PASS2 | |
PTRAIN_NUM_PASSES | |
Definition at line 34 of file params_model.h.
◆ ParamsModel() [1/2]
tesseract::ParamsModel::ParamsModel |
( |
| ) |
|
|
inline |
◆ ParamsModel() [2/2]
tesseract::ParamsModel::ParamsModel |
( |
const char * |
lang, |
|
|
const GenericVector< float > & |
weights |
|
) |
| |
|
inline |
Definition at line 42 of file params_model.h.
42 :
const GenericVector< float > & weights() const
◆ Clear()
void tesseract::ParamsModel::Clear |
( |
| ) |
|
|
inline |
Definition at line 50 of file params_model.h.
50 {
51 for (auto & p : weights_vec_) p.clear();
52 }
◆ ComputeCost()
float tesseract::ParamsModel::ComputeCost |
( |
const float |
features[] | ) |
const |
Definition at line 80 of file params_model.cpp.
80 {
81 float unnorm_score = 0.0;
83 unnorm_score += weights_vec_[pass_][f] * features[f];
84 }
85 return ClipToRange(-unnorm_score / kScoreScaleFactor,
86 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 | ) |
|
Definition at line 47 of file params_model.cpp.
47 {
49 weights_vec_[p] = other_model.weights_for_pass(
51 }
52}
◆ Equivalent()
bool tesseract::ParamsModel::Equivalent |
( |
const ParamsModel & |
that | ) |
const |
Definition at line 89 of file params_model.cpp.
89 {
90 float epsilon = 0.0001;
92 if (weights_vec_[p].size() != that.weights_vec_[p].size()) return false;
93 for (
int i = 0; i < weights_vec_[p].
size(); i++) {
94 if (weights_vec_[p][i] != that.weights_vec_[p][i] &&
95 fabs(weights_vec_[p][i] - that.weights_vec_[p][i]) > epsilon)
96 return false;
97 }
98 }
99 return true;
100}
◆ Initialized()
bool tesseract::ParamsModel::Initialized |
( |
| ) |
|
|
inline |
◆ LoadFromFp()
bool tesseract::ParamsModel::LoadFromFp |
( |
const char * |
lang, |
|
|
TFile * |
fp |
|
) |
| |
Definition at line 102 of file params_model.cpp.
102 {
103 const int kMaxLineSize = 100;
104 char line[kMaxLineSize];
105 BitVector present;
107 lang_ = lang;
108
111
112 while (fp->FGets(line, kMaxLineSize) != nullptr) {
113 char *key = nullptr;
114 float value;
115 if (!ParseLine(line, &key, &value))
116 continue;
118 if (idx < 0) {
119 tprintf(
"ParamsModel::Unknown parameter %s\n", key);
120 continue;
121 }
122 if (!present[idx]) {
123 present.SetValue(idx, true);
124 }
126 }
128 if (!complete) {
130 if (!present[i]) {
131 tprintf(
"Missing field %s.\n", kParamsTrainingFeatureTypeName[i]);
132 }
133 }
134 lang_ = "";
136 }
137 return complete;
138}
DLLSYM void tprintf(const char *format,...)
int ParamsTrainingFeatureByName(const char *name)
void init_to_size(int size, const T &t)
◆ Print()
void tesseract::ParamsModel::Print |
( |
| ) |
|
Definition at line 37 of file params_model.cpp.
37 {
39 tprintf(
"ParamsModel for pass %d lang %s\n", p, lang_.
string());
40 for (
int i = 0; i < weights_vec_[p].
size(); ++i) {
41 tprintf(
"%s = %g\n", kParamsTrainingFeatureTypeName[i],
42 weights_vec_[p][i]);
43 }
44 }
45}
const char * string() const
◆ SaveToFile()
bool tesseract::ParamsModel::SaveToFile |
( |
const char * |
full_path | ) |
const |
Definition at line 140 of file params_model.cpp.
140 {
143 tprintf(
"Refusing to save ParamsModel that has not been initialized.\n");
144 return false;
145 }
146 FILE *fp = fopen(full_path, "wb");
147 if (!fp) {
148 tprintf(
"Could not open %s for writing.\n", full_path);
149 return false;
150 }
151 bool all_good = true;
153 if (fprintf(fp,
"%s %f\n", kParamsTrainingFeatureTypeName[i],
weights[i])
154 < 0) {
155 all_good = false;
156 }
157 }
158 fclose(fp);
159 return all_good;
160}
◆ SetPass()
void tesseract::ParamsModel::SetPass |
( |
PassEnum |
pass | ) |
|
|
inline |
◆ weights()
const GenericVector< float > & tesseract::ParamsModel::weights |
( |
| ) |
const |
|
inline |
Definition at line 66 of file params_model.h.
66 {
67 return weights_vec_[pass_];
68 }
◆ weights_for_pass()
Definition at line 69 of file params_model.h.
69 {
70 return weights_vec_[pass];
71 }
The documentation for this class was generated from the following files: