#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.
const std::vector< float > & weights() const
◆ Clear()
void tesseract::ParamsModel::Clear |
( |
| ) |
|
|
inline |
◆ ComputeCost()
float tesseract::ParamsModel::ComputeCost |
( |
const float |
features[] | ) |
const |
Definition at line 81 of file params_model.cpp.
82 float unnorm_score = 0.0;
84 unnorm_score += weights_vec_[pass_][f] * features[f];
86 return ClipToRange(-unnorm_score / kScoreScaleFactor, kMinFinalCost, kMaxFinalCost);
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.
90 float epsilon = 0.0001f;
92 if (weights_vec_[p].size() != that.weights_vec_[p].size()) {
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) {
◆ 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.
106 const int kMaxLineSize = 100;
107 char line[kMaxLineSize];
112 std::vector<float> &
weights = weights_vec_[pass_];
116 while (fp->FGets(line, kMaxLineSize) !=
nullptr) {
119 if (!ParseLine(line, &key, &value)) {
124 tprintf(
"ParamsModel::Unknown parameter %s\n", key);
128 present.SetValue(idx,
true);
136 tprintf(
"Missing field %s.\n", kParamsTrainingFeatureTypeName[i]);
int ParamsTrainingFeatureByName(const char *name)
void tprintf(const char *format,...)
◆ Print()
void tesseract::ParamsModel::Print |
( |
| ) |
|
Definition at line 39 of file params_model.cpp.
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]);
◆ SaveToFile()
bool tesseract::ParamsModel::SaveToFile |
( |
const char * |
full_path | ) |
const |
Definition at line 145 of file params_model.cpp.
146 const std::vector<float> &
weights = weights_vec_[pass_];
148 tprintf(
"Refusing to save ParamsModel that has not been initialized.\n");
151 FILE *fp = fopen(full_path,
"wb");
153 tprintf(
"Could not open %s for writing.\n", full_path);
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) {
◆ SetPass()
void tesseract::ParamsModel::SetPass |
( |
PassEnum |
pass | ) |
|
|
inline |
◆ weights()
const std::vector<float>& tesseract::ParamsModel::weights |
( |
| ) |
const |
|
inline |
◆ weights_for_pass()
const std::vector<float>& tesseract::ParamsModel::weights_for_pass |
( |
PassEnum |
pass | ) |
const |
|
inline |
The documentation for this class was generated from the following files: