MCPcopy Create free account
hub / github.com/creatale/node-dv / LoadFromFp

Method LoadFromFp

deps/tesseract/wordrec/params_model.cpp:113–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111}
112
113bool ParamsModel::LoadFromFp(const char *lang, FILE *fp, inT64 end_offset) {
114 const int kMaxLineSize = 100;
115 char line[kMaxLineSize];
116 BitVector present;
117 present.Init(PTRAIN_NUM_FEATURE_TYPES);
118 lang_ = lang;
119 // Load weights for passes with adaption on.
120 GenericVector<float> &weights = weights_vec_[pass_];
121 weights.init_to_size(PTRAIN_NUM_FEATURE_TYPES, 0.0);
122
123 while ((end_offset < 0 || ftell(fp) < end_offset) &&
124 fgets(line, kMaxLineSize, fp)) {
125 char *key = NULL;
126 float value;
127 if (!ParseLine(line, &key, &value))
128 continue;
129 int idx = ParamsTrainingFeatureByName(key);
130 if (idx < 0) {
131 tprintf("ParamsModel::Unknown parameter %s\n", key);
132 continue;
133 }
134 if (!present[idx]) {
135 present.SetValue(idx, true);
136 }
137 weights[idx] = value;
138 }
139 bool complete = (present.NumSetBits() == PTRAIN_NUM_FEATURE_TYPES);
140 if (!complete) {
141 for (int i = 0; i < PTRAIN_NUM_FEATURE_TYPES; i++) {
142 if (!present[i]) {
143 tprintf("Missing field %s.\n", kParamsTrainingFeatureTypeName[i]);
144 }
145 }
146 lang_ = "";
147 weights.truncate(0);
148 }
149 return complete;
150}
151
152bool ParamsModel::SaveToFile(const char *full_path) const {
153 const GenericVector<float> &weights = weights_vec_[pass_];

Callers 1

Calls 6

init_to_sizeMethod · 0.80
NumSetBitsMethod · 0.80
InitMethod · 0.45
SetValueMethod · 0.45
truncateMethod · 0.45

Tested by

no test coverage detected