mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-12-13 16:09:04 +08:00
023e1b340e
* api: Replace Tesseract data types by POSIX data types Signed-off-by: Stefan Weil <sw@weilnetz.de> * ccmain: Replace Tesseract data types by POSIX data types Signed-off-by: Stefan Weil <sw@weilnetz.de> * ccstruct: Replace Tesseract data types by POSIX data types Signed-off-by: Stefan Weil <sw@weilnetz.de> * classify: Replace Tesseract data types by POSIX data types Signed-off-by: Stefan Weil <sw@weilnetz.de> * cutil: Replace Tesseract data types by POSIX data types Signed-off-by: Stefan Weil <sw@weilnetz.de> * dict: Replace Tesseract data types by POSIX data types Signed-off-by: Stefan Weil <sw@weilnetz.de> * textord: Replace Tesseract data types by POSIX data types Signed-off-by: Stefan Weil <sw@weilnetz.de> * training: Replace Tesseract data types by POSIX data types Signed-off-by: Stefan Weil <sw@weilnetz.de> * wordrec: Replace Tesseract data types by POSIX data types Signed-off-by: Stefan Weil <sw@weilnetz.de> * ccutil: Replace Tesseract data types by POSIX data types Now all Tesseract data types which are no longer needed can be removed from ccutil/host.h. Signed-off-by: Stefan Weil <sw@weilnetz.de> * ccmain: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX Signed-off-by: Stefan Weil <sw@weilnetz.de> * ccstruct: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX Signed-off-by: Stefan Weil <sw@weilnetz.de> * classify: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX Signed-off-by: Stefan Weil <sw@weilnetz.de> * dict: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX Signed-off-by: Stefan Weil <sw@weilnetz.de> * lstm: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX Signed-off-by: Stefan Weil <sw@weilnetz.de> * textord: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX Signed-off-by: Stefan Weil <sw@weilnetz.de> * wordrec: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX Signed-off-by: Stefan Weil <sw@weilnetz.de> * ccutil: Replace Tesseract's MIN_*INT, MAX_*INT* by POSIX *INT*_MIN, *INT*_MAX Remove the macros which are now unused from ccutil/host.h. Remove also the obsolete history comments. Signed-off-by: Stefan Weil <sw@weilnetz.de> * Fix build error caused by ambiguous ClipToRange Error message vom Appveyor CI: C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2672: 'ClipToRange': no matching overloaded function found [C:\projects\tesseract\build\libtesseract.vcxproj] C:\projects\tesseract\ccstruct\coutln.cpp(818): error C2782: 'T ClipToRange(const T &,const T &,const T &)': template parameter 'T' is ambiguous [C:\projects\tesseract\build\libtesseract.vcxproj] c:\projects\tesseract\ccutil\helpers.h(122): note: see declaration of 'ClipToRange' C:\projects\tesseract\ccstruct\coutln.cpp(818): note: could be 'char' C:\projects\tesseract\ccstruct\coutln.cpp(818): note: or 'int' Signed-off-by: Stefan Weil <sw@weilnetz.de> * unittest: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX Signed-off-by: Stefan Weil <sw@weilnetz.de> * arch: Replace Tesseract's MAX_INT8 by POSIX INT8_MAX Signed-off-by: Stefan Weil <sw@weilnetz.de>
96 lines
4.2 KiB
C++
96 lines
4.2 KiB
C++
///////////////////////////////////////////////////////////////////////
|
|
// File: lstmtester.h
|
|
// Description: Top-level line evaluation class for LSTM-based networks.
|
|
// Author: Ray Smith
|
|
// Created: Wed Nov 23 11:05:06 PST 2016
|
|
//
|
|
// (C) Copyright 2016, Google Inc.
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef TESSERACT_TRAINING_LSTMTESTER_H_
|
|
#define TESSERACT_TRAINING_LSTMTESTER_H_
|
|
|
|
#include "genericvector.h"
|
|
#include "lstmtrainer.h"
|
|
#include "strngs.h"
|
|
#include "svutil.h"
|
|
|
|
namespace tesseract {
|
|
|
|
class LSTMTester {
|
|
public:
|
|
LSTMTester(int64_t max_memory);
|
|
|
|
// Loads a set of lstmf files that were created using the lstm.train config to
|
|
// tesseract into memory ready for testing. Returns false if nothing was
|
|
// loaded. The arg is a filename of a file that lists the filenames, with one
|
|
// name per line. Conveniently, tesstrain.sh generates such a file, along
|
|
// with the files themselves.
|
|
bool LoadAllEvalData(const STRING& filenames_file);
|
|
// Loads a set of lstmf files that were created using the lstm.train config to
|
|
// tesseract into memory ready for testing. Returns false if nothing was
|
|
// loaded.
|
|
bool LoadAllEvalData(const GenericVector<STRING>& filenames);
|
|
|
|
// Runs an evaluation asynchronously on the stored eval data and returns a
|
|
// string describing the results of the previous test. Args match TestCallback
|
|
// declared in lstmtrainer.h:
|
|
// iteration: Current learning iteration number.
|
|
// training_errors: If not null, is an array of size ET_COUNT, indexed by
|
|
// the ErrorTypes enum and indicates the current errors measured by the
|
|
// trainer, and this is a serious request to run an evaluation. If null,
|
|
// then the caller is just polling for the results of the previous eval.
|
|
// model_data: is the model to evaluate, which should be a serialized
|
|
// LSTMTrainer.
|
|
// training_stage: an arbitrary number on the progress of training.
|
|
STRING RunEvalAsync(int iteration, const double* training_errors,
|
|
const TessdataManager& model_mgr, int training_stage);
|
|
// Runs an evaluation synchronously on the stored eval data and returns a
|
|
// string describing the results. Args as RunEvalAsync, except verbosity,
|
|
// which outputs errors, if 1, or all results if 2.
|
|
STRING RunEvalSync(int iteration, const double* training_errors,
|
|
const TessdataManager& model_mgr, int training_stage,
|
|
int verbosity);
|
|
|
|
private:
|
|
// Static helper thread function for RunEvalAsync, with a specific signature
|
|
// required by SVSync::StartThread. Actually a member function pretending to
|
|
// be static, its arg is a this pointer that it will cast back to LSTMTester*
|
|
// to call RunEvalSync using the stored args that RunEvalAsync saves in *this.
|
|
// LockIfNotRunning must have returned true before calling ThreadFunc, and
|
|
// it will call UnlockRunning to release the lock after RunEvalSync completes.
|
|
static void* ThreadFunc(void* lstmtester_void);
|
|
// Returns true if there is currently nothing running, and takes the lock
|
|
// if there is nothing running.
|
|
bool LockIfNotRunning();
|
|
// Releases the running lock.
|
|
void UnlockRunning();
|
|
|
|
// The data to test with.
|
|
DocumentCache test_data_;
|
|
int total_pages_;
|
|
// Flag that indicates an asynchronous test is currently running.
|
|
// Protected by running_mutex_.
|
|
bool async_running_;
|
|
SVMutex running_mutex_;
|
|
// Stored copies of the args for use while running asynchronously.
|
|
int test_iteration_;
|
|
const double* test_training_errors_;
|
|
TessdataManager test_model_mgr_;
|
|
int test_training_stage_;
|
|
STRING test_result_;
|
|
};
|
|
|
|
} // namespace tesseract
|
|
|
|
#endif // TESSERACT_TRAINING_LSTMTESTER_H_
|