Skip to content

Commit

Permalink
Replace STRING by std::string for LSTMRecognizer::network_str_
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Jan 15, 2021
1 parent 97cfd95 commit 970eba7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/ccutil/serialis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,24 @@ template TESS_API bool TFile::DeSerialize(std::vector<int32_t>& data);
template TESS_API bool TFile::Serialize(const std::vector<double>& data);
template TESS_API bool TFile::Serialize(const std::vector<int32_t>& data);

bool TFile::DeSerialize(std::string& data) {
uint32_t size;
if (!DeSerialize(&size)) {
return false;
} else if (size > 0) {
// TODO: optimize.
data.resize(size);
return DeSerialize(&data[0], size);
}
data.clear();
return true;
}

bool TFile::Serialize(const std::string& data) {
uint32_t size = data.size();
return Serialize(&size) && Serialize(data.c_str(), size);
}

bool TFile::DeSerialize(std::vector<char>& data) {
uint32_t size;
if (!DeSerialize(&size)) {
Expand Down
2 changes: 2 additions & 0 deletions src/ccutil/serialis.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class TESS_API TFile {
}

// Deserialize data.
bool DeSerialize(std::string& data);
bool DeSerialize(std::vector<char>& data);
template <typename T> bool DeSerialize(std::vector<T>& data);
template <typename T>
Expand All @@ -93,6 +94,7 @@ class TESS_API TFile {
}

// Serialize data.
bool Serialize(const std::string& data);
bool Serialize(const std::vector<char>& data);
template <typename T> bool Serialize(const std::vector<T>& data);
template <typename T>
Expand Down
4 changes: 2 additions & 2 deletions src/lstm/lstmrecognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ bool LSTMRecognizer::Serialize(const TessdataManager* mgr, TFile* fp) const {
!mgr->IsComponentAvailable(TESSDATA_LSTM_UNICHARSET);
if (!network_->Serialize(fp)) return false;
if (include_charsets && !GetUnicharset().save_to_file(fp)) return false;
if (!network_str_.Serialize(fp)) return false;
if (!fp->Serialize(network_str_)) return false;
if (!fp->Serialize(&training_flags_)) return false;
if (!fp->Serialize(&training_iteration_)) return false;
if (!fp->Serialize(&sample_iteration_)) return false;
Expand All @@ -112,7 +112,7 @@ bool LSTMRecognizer::DeSerialize(const TessdataManager* mgr, TFile* fp) {
!mgr->IsComponentAvailable(TESSDATA_LSTM_UNICHARSET);
if (include_charsets && !ccutil_.unicharset.load_from_file(fp, false))
return false;
if (!network_str_.DeSerialize(fp)) return false;
if (!fp->DeSerialize(network_str_)) return false;
if (!fp->DeSerialize(&training_flags_)) return false;
if (!fp->DeSerialize(&training_iteration_)) return false;
if (!fp->DeSerialize(&sample_iteration_)) return false;
Expand Down
2 changes: 1 addition & 1 deletion src/lstm/lstmrecognizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class TESS_API LSTMRecognizer {
UnicharCompress recoder_;

// ==Training parameters that are serialized to provide a record of them.==
STRING network_str_;
std::string network_str_;
// Flags used to determine the training method of the network.
// See enum TrainingFlags above.
int32_t training_flags_;
Expand Down

0 comments on commit 970eba7

Please sign in to comment.