Skip to content

trainf_ocr_class_mlpTrainfOcrClassMlpTrainfOcrClassMlptrainf_ocr_class_mlpT_trainf_ocr_class_mlp🔗

Short description🔗

trainf_ocr_class_mlpTrainfOcrClassMlpTrainfOcrClassMlptrainf_ocr_class_mlpT_trainf_ocr_class_mlp — Train an OCR classifier.

Signature🔗

trainf_ocr_class_mlp( ocr_mlp OCRHandle, filename.read TrainingFile, integer MaxIterations, real WeightTolerance, real ErrorTolerance, out real Error, out real ErrorLog )void TrainfOcrClassMlp( const HTuple& OCRHandle, const HTuple& TrainingFile, const HTuple& MaxIterations, const HTuple& WeightTolerance, const HTuple& ErrorTolerance, HTuple* Error, HTuple* ErrorLog )static void HOperatorSet.TrainfOcrClassMlp( HTuple OCRHandle, HTuple trainingFile, HTuple maxIterations, HTuple weightTolerance, HTuple errorTolerance, out HTuple error, out HTuple errorLog )def trainf_ocr_class_mlp( ocrhandle: HHandle, training_file: MaybeSequence[str], max_iterations: int, weight_tolerance: float, error_tolerance: float ) -> Tuple[float, Sequence[float]]

Herror T_trainf_ocr_class_mlp( const Htuple OCRHandle, const Htuple TrainingFile, const Htuple MaxIterations, const Htuple WeightTolerance, const Htuple ErrorTolerance, Htuple* Error, Htuple* ErrorLog )

double HOCRMlp::TrainfOcrClassMlp( const HTuple& TrainingFile, Hlong MaxIterations, double WeightTolerance, double ErrorTolerance, HTuple* ErrorLog ) const

double HOCRMlp::TrainfOcrClassMlp( const HString& TrainingFile, Hlong MaxIterations, double WeightTolerance, double ErrorTolerance, HTuple* ErrorLog ) const

double HOCRMlp::TrainfOcrClassMlp( const char* TrainingFile, Hlong MaxIterations, double WeightTolerance, double ErrorTolerance, HTuple* ErrorLog ) const

double HOCRMlp::TrainfOcrClassMlp( const wchar_t* TrainingFile, Hlong MaxIterations, double WeightTolerance, double ErrorTolerance, HTuple* ErrorLog ) const (Windows only)

double HOCRMlp.TrainfOcrClassMlp( HTuple trainingFile, int maxIterations, double weightTolerance, double errorTolerance, out HTuple errorLog )

double HOCRMlp.TrainfOcrClassMlp( string trainingFile, int maxIterations, double weightTolerance, double errorTolerance, out HTuple errorLog )

Description🔗

trainf_ocr_class_mlpTrainfOcrClassMlp trains the OCR classifier OCRHandleOCRHandleocrhandle with the training characters stored in the OCR training files given by TrainingFiletrainingFiletraining_file. The training files must have been created, e.g., using write_ocr_trainfWriteOcrTrainf, before calling trainf_ocr_class_mlpTrainfOcrClassMlp.

The remaining parameters have the same meaning as in train_class_mlpTrainClassMlp and are described in detail with train_class_mlpTrainClassMlp. A regularization of the OCR classifier and an automatic determination of the regularization parameters (see set_regularization_params_ocr_class_mlpSetRegularizationParamsOcrClassMlp) is taken into account during the training. Furthermore, if a rejection class has been specified using set_rejection_params_ocr_class_mlpSetRejectionParamsOcrClassMlp, before the actual training the samples for the rejection class are generated.

Please note that training characters that have no corresponding class in the classifier OCRHandleOCRHandleocrhandle are discarded.

Execution information🔗

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Automatically parallelized on internal data level.

This operator modifies the state of the following input parameter:

During execution of this operator, access to the value of this parameter must be synchronized if it is used across multiple threads.

Parameters🔗

OCRHandleOCRHandleocrhandle (input_control, state is modified) ocr_mlp → (handle)HTuple (HHandle)HOCRMlp, HTuple (IntPtr)HHandleHtuple (handle)

Handle of the OCR classifier.

TrainingFiletrainingFiletraining_file (input_control) filename.read(-array) → (string)HTuple (HString)HTuple (string)MaybeSequence[str]Htuple (char*)

Names of the training files.

Default: 'ocr.trf'"ocr.trf"
File extension: .trf, .otr

MaxIterationsmaxIterationsmax_iterations (input_control) integer → (integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

Maximum number of iterations of the optimization algorithm.

Default: 200200
Suggested values: 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 30020, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300

WeightToleranceweightToleranceweight_tolerance (input_control) real → (real)HTuple (double)HTuple (double)floatHtuple (double)

Threshold for the difference of the weights of the MLP between two iterations of the optimization algorithm.

Default: 1.01.0
Suggested values: 1.0, 0.1, 0.01, 0.001, 0.0001, 0.000011.0, 0.1, 0.01, 0.001, 0.0001, 0.00001
Restriction: WeightTolerance >= 1.0e-8

ErrorToleranceerrorToleranceerror_tolerance (input_control) real → (real)HTuple (double)HTuple (double)floatHtuple (double)

Threshold for the difference of the mean error of the MLP on the training data between two iterations of the optimization algorithm.

Default: 0.010.01
Suggested values: 1.0, 0.1, 0.01, 0.001, 0.0001, 0.000011.0, 0.1, 0.01, 0.001, 0.0001, 0.00001
Restriction: ErrorTolerance >= 1.0e-8

Errorerrorerror (output_control) real → (real)HTuple (double)HTuple (double)floatHtuple (double)

Mean error of the MLP on the training data.

ErrorLogerrorLogerror_log (output_control) real-array → (real)HTuple (double)HTuple (double)Sequence[float]Htuple (double)

Mean error of the MLP on the training data as a function of the number of iterations of the optimization algorithm.

Example🔗

(HDevelop)

* Train an OCR classifier
read_ocr_trainf_names ('ocr.trf', CharacterNames, CharacterCount)
create_ocr_class_mlp (8, 10, 'constant', 'default', CharacterNames, 80, \
                      'none', 81, 42, OCRHandle)
trainf_ocr_class_mlp (OCRHandle, 'ocr.trf', 100, 1, 0.01, Error, ErrorLog)
write_ocr_class_mlp (OCRHandle, 'ocr.omc')

Result🔗

If the parameters are valid, the operator trainf_ocr_class_mlpTrainfOcrClassMlp returns the value 2 (H_MSG_TRUE). If necessary, an exception is raised.

trainf_ocr_class_mlpTrainfOcrClassMlp may return the error 9211 (Matrix is not positive definite) if Preprocessingpreprocessingpreprocessing \(=\) 'canonical_variates'"canonical_variates" is used. This typically indicates that not enough training samples have been stored for each class. In this case we recommend to change Preprocessingpreprocessingpreprocessing to 'normalization'"normalization". Another solution can be to add more training samples.

Combinations with other operators🔗

Combinations

Possible predecessors

create_ocr_class_mlpCreateOcrClassMlp, write_ocr_trainfWriteOcrTrainf, append_ocr_trainfAppendOcrTrainf, write_ocr_trainf_imageWriteOcrTrainfImage, set_regularization_params_ocr_class_mlpSetRegularizationParamsOcrClassMlp

Possible successors

do_ocr_single_class_mlpDoOcrSingleClassMlp, do_ocr_multi_class_mlpDoOcrMultiClassMlp, write_ocr_class_mlpWriteOcrClassMlp

Alternatives

read_ocr_class_mlpReadOcrClassMlp

See also

train_class_mlpTrainClassMlp

Module🔗

OCR/OCV