Package: ocr4all-pixel-classifier
OCR4All Pixel ClassifierRequirementsPython dependencies are specified inrequirements.txt/setup.py.The package is tested with Tensorflow 2.0 up to 2.5. If you want to use a GPU,
you'll have to set up your system with the CUDA and CuDNN versionsmatching
your used Tensorflow version.
If using Tensorflow older than 2.1 for some reason, you'll additionaly have to
replace thetensorflowpackage withtensorflow-gpumanually.UsageFor training and direct usage, installocr4all-pixel-classifier-frontend. This package only contains the library code.Pixel classifierClassificationTo run a model on some input images, useocr4all-pixel-classifier predict:ocr4all-pixel-classifierpredict--loadPATH_TO_MODEL\--outputOUTPUT_PATH\--binaryPATH_TO_BINARY_IMAGES\--imagesPATH_TO_SOURCE_IMAGES\--normPATH_TO_NORMALIZATIONS(ocr4all-pixel-classifieris an alias forocr4all-pixel-classifier predict)This will create three folders at the output path:color: the classification as color image, with pixel color corresponding to
the class for that pixelinverted: inverted binary image with classification of foreground pixels
only (i.e. background is black, foreground is white or class color)overlay: classification image layered transparently over the original imageTrainingFor training, you first have to create dataset files. A dataset file is a JSON
file containing three arrays, for train, test and evaluation data (also
called train/validation/test in other publications). The JSON file uses the
following format:{"train":[//datasets here],"test":[//datasets here],"eval":[//datasets here]}A dataset describes a single input image and consists of several paths: the
original image, a binarized version and the mask (pixel color corresponds to
class). Furthermore, the line height of the page in pixels must be specified:{"binary_path":"/path/to/image/binary/filename.bin.png","image_path":"/path/to/image/color/filename.jpg","mask_path":"/path/to/image/mask/filename_MASK.png","line_height_px":18}The generation of dataset files can be automated usingocr4all-pixel-classifier create-dataset-file. Refer to the command's--helpoutput for further
information.To start the training:ocr4all-pixel-classifiertrain\--trainDATASET_FILE.json--testDATASET_FILE.json--evalDATASET_FILE.json\--outputMODEL_TARGET_PATH\--n_iter5000The parameters--train,--testand--evalmay be followed by any number of
dataset files or patterns (shell globbing).Refer toocr4all-pixel-classifier train --helpfor further parameters provided to
affect the training procedure.You can combine several dataset files into asplit file. The format of the
split file is:{"label":"name of split","train":["/path/to/dataset1.json","/path/to/dataset2.json",...],"test":[//dataset paths here],"eval":[//dataset paths here]}To use a split file, add the--split_fileparameter.ExamplesSee the examples fordataset generationandtrainingocr4all-pixel-classifier compute-image-normalizations/ocrd_compute_normalizationsCalculate image normalizations, i.e. scaling factors based on average line
height.Required arguments:--input_dir: location of images--output_dir: target location of norm filesOptional arguments:--average_all: Average height over all images--inverse