Patent ID: 12205370

DETAILED DESCRIPTION

The accuracy of Optical Character Recognition (OCR) is dependent on the OCR engine used, the quality of the input image, and the content of the text to be extracted. When an OCR engine is a black-box, image recapture is infeasible, and the text to be extracted is not of a natural language, few options exist to improve OCR performance. In view of this, Applicant has developed a novel solution: employing machine-learning of image transformations that minimize edit distance between the OCR extracted text and the known true text within the training image, by training the model on edit distance improvement between original and model-transformed image. Using Levenshtein distance between true text and OCR extracted text as the raw edit distance metric, a comparative normalization scheme was developed to normalize for differences in input image distortion—to measure edit distance improvement. Improvement and raw edit distance were used in conjunction to interpret transformation outcomes. Transformation outcomes were mapped to consequences by a pseudo-policy; outcomes were mapped to values that could be used in a standard loss function and update scheme to simulate the reward/penalty structure of reinforcement learning. Corrective transformations were categorized as warping or filtering. Specialized sub-models were developed to learn each category of transformation: Inspectors—to predict corrective warp parameters, and filters—to learn corrective filter kernels.

One tested working embodiment was trained and tested on distorted text images generated from a corpus of true text strings, where the parameter of each applied distortion was chosen uniformly at random. The transformations produced a significant (p≈0.003) improvement in edit distance. The mean edit distance improvement was 9.3 characters, for true text strings of mean length 10.6 characters. 27.3% of transformed images produced an OCR output that exactly matched the true text, 47.1% produced an output within 1 character edit, and 79.0% of transformed images were within 3 character edits; compared to 0.1%, 0.1%, and 0.6% respectively, for the original images.

FIG.1schematically illustrates a process for training an image-transformation model that, once trained, is useful for preoptimizing text images prior to input thereof to an OCR engine. In order to evaluate the performance of OCR on a given input, comparison is made of the output of the OCR engine against known text within an image.

Let

ocr(o; xi) symbolize a call to OCR engine o with input image xi;yisymbolize the known text within xi; andd(ŷi, yi) symbolize the typographic distance between input string ŷiand target string yi.
The performance of OCR engine o on input image xiis evaluated as through d(ocr(o; xi), yi). There are many choices for what typographic distance, d, should be used, and different metrics produce different behaviors in the measurement of typographic distance. Edit distance is a subset of typographic and sequence distance that measures the sum of costs of edit operations required to transform an input string/sequence into a target string/sequence. The costs of operations can be uniform: an unweighted edit distance, specified by edit type: different costs for insertion, deletion, and substitution, or specified by edit content: different costs based on the source and target characters. Unweighted Levenshtein distance is calculated as the sum of single character insertions and deletions necessary to align one sequence to another. Unweighted Levenshtein distance was chosen for the tested working embodiment because it does not include substitutions, thereby reducing the edit distance to a simple count of single character edit operations. Functionality was built into the model of the test working embodiment for weighted Levenshtein distance, but was not put to you in the non-limiting example disclosed herein.

Image warping is any transformation that adjusts the location of existing pixels. Warping may be applied directly to a captured image, or approximated by altering the location/orientation of the camera and target—e.g. rotating the camera to approximate rotating an image. In the context of the tested working embodiment, corrective warping is any transformation that adjusts the location of pixels for the purpose of improving OCR performance. Common corrections via warping include (but are not limited to):Rotation: Rotate image so that lines of text are horizontal.Perspective: 4-Point perspective transform to restore parallelism of lines of text, and size uniformity among charactersTranslation: Translate image to ensure text has padding (characters on the edge of an image are often harder to extract), and is near the center of the image frame.Reflection: Restore text that has been mirrored by mirrors or lenses.Shear: Improve recognition of italic text, and correct for text printed on elastic surfaces.Scale: Alter the size of text for uniform sizing across a document.

Non-uniformity of pixel movement is one of the greatest challenges in corrective warping process; e.g. when rotating an image, the pixels farthest from the center of rotation move substantially, while the pixels near the center of rotation move much less. As such, training a model to perform a warping process through convolution is both difficult, and requires a very deep network. However, all of the above listed warping transformations can be performed using well defined closed-form algorithms. Accordingly, the learning task can be simplified to learning the transformation parameters rather than learning the transformative process itself—e.g. corrective rotation can be simplified to learning the angle and center of rotation needed to correct the image rather than learn the set of kernels necessary to approximate a rotation transformation.

Image filtering is any transformation that adjusts the color/intensity of pixels. Filtering may be applied to a captured image, or approximated by altering the lens of a camera or the lighting of the capture environment—e.g. adding a blue light filter to optics to make the colors warmer. In the context of the tested working embodiment, corrective filtering is any transformation that adjusts the color/intensity of pixels for the purpose of improving OCR performance. Common corrections via filtering include (but not limited to):Smoothing: Reduce high-frequency noise obscuring text.Color Balancing: Adjust brightness, contrast, saturation, and hue to intensify and highlight text.Gradient Mapping: Using Sobel, Prewit, Laplacian of Gaussian, etc. . . . kernels to highlight potential edges and corners in text.
Filtering processes ultimately reduce to the application of a convolution kernel across an image. As such, the learning task for a filtering operation directly maps to learning the weights of a convolution kernel.

Unlike reinforcement learning, where the aim is achievement of an end goal in a definable environment (e.g. the game of chess, in which the game board and game pieces denote an environment that can be queried for its current state and compared against known rules of game play to conclude when an definitive end-state has been reached), image transformation learned through OCR performance is not easily defined as an environment because confirmed achievement of the end goal of the correction process is only possible by comparing the OCR output against true text; i.e. progress is measured by reductions in the edit distance between OCR output and true text. As such, it is not possible for the model to query an environment for the current state outside of training. Instead, a different approach was developed that enacts a reward and penalty system through traditional loss functions, as schematically illustrated inFIG.1. More particularly, transformation outcomes were mapped to consequences by a pseudo-policy; outcomes were mapped to values that could be used in a standard loss function and update scheme to simulate the reward/penalty structure of reinforcement learning.

With reference toFIG.1, let:{circumflex over (x)}isymbolize the output of the image transformer given input image□̌isymbolize ocr(o; xi); the output of OCR engine o on the original (pre-transformation) input image xiŷisymbolize ocr(o; {circumflex over (x)}i); the output of OCR engine o on the transformed image {circumflex over (x)}iyisymbolize the known text within xi.d(□̌i; y) symbolize the edit distance between input string □̌iand target string yi; i.e. the edit distance between the known text within xiand the text extracted by OCR engine o from xid(ŷi; yi) symbolize the edit distance between input string ŷiand target string yi; i.e. the edit distance between the known text within xiand the text extracted by OCR engine o from {circumflex over (x)}i
Not all input images, xi, have the same degree and type of distortion, nor the same length of true text, |yi|. Thereby, in a training set of n images, ¬(∀i∈{1, . . . , n} ∀j∈{1, . . . , n} (d(y̌i, yi)=d(y̌j, yj))); not all input images have the same edit distance between OCR output and true text. Using edit distance alone does not fairly evaluate model performance; a fairer metric evaluates the degree of improvement in OCR performance due to the model's transformations; i.e. normalize d(ŷi; yi) by calculating the difference between d(ŷi; yi) and d(□̌i; yi), thereby determining a change in resulting edit distance that is attributable to the performed transformations. Let d(□̌i; yi)−d(ŷi; yi) be called an ‘improvement score’; where a negative score means the transformation let to an OCR output that was farther from the true text, and a positive score means the transformation led to an OCR output that was closer to the true text.

Using the forgoing comparative normalization scheme, there are five possible outcomes with respect to improvement and edit distance between true text and the OCR output of the transformed image.Improvement==0, Edit Distance==0: (I0E0)Transformation did not improve OCR performance, but perfect OCR performance was still achieved. Thus, the input image was already perfect, and transformation did not harm performance.Improvement==0, Edit Distance>0: (I0E+)Transformation did not improve OCR performance, and perfect OCR performance was not achieved. Thus, the input image was distorted, and transformation neither corrected nor worsened the distortions.Improvement>0, Edit Distance==0: (I+E0)Transformation improved OCR performance, and perfect OCR performance was achieved. Thus, the input image was distorted, and transformation completely corrected the distortion.Improvement>0, Edit Distance>0: (I+E+)Transformation improved OCR performance, but perfect OCR performance was not achieved. Thus, the input image was distorted, and transformation corrected some, but not all, distortion.Improvement<0, Edit Distance==0: (I−E0)Not a possible outcome. Since edit distance will always be positive, and a negative improvement score means transformation increased the edit distance, edit distance==0 and improvement<0 means that the edit distance was increase to 0, which is not possible since edit distance cannot be less than 0.Improvement<0, Edit Distance>0: (I−E+)Transformation worsened OCR performance. Thus, the input image may or may not have been distorted, and transformation worsened/added distortion.
A structure of consequences for the five possible outcomes was designed to map the five outcomes to a score that can be used in a classic loss and update scheme to mimic some qualities of penalties and rewards from reinforcement learning. In abstract, consequences must consider improvement, deterioration, and stasis.

Improvement is transformation that increases d(y̌i; yi)−d(ŷi; yi). Not all improvement receives the same consequence. The ideal improvement of a distorted input image is that which leads to d(ŷi; yi)=0; let this result be called ‘perfect improvement’, and other improvements be ‘partial improvement’. When training a model, perfect improvement of a distorted image is ideal behavior, and should have a loss of 0. Partial improvement is still correct behavior, especially given some images may not be perfectly correctable. Therein, partial improvement should have a small but non-zero loss.

Deterioration is transformation that decreases d(y̌i; yi)−d(ŷi; yi). Similar to improvement, not all deterioration is created equal; different distortions added by the model have different degrees of effect on edit distance. All deterioration should receive a large loss, but an additional term should be added and scaled my the magnitude of d(y̌i; yi)−d(ŷi; yi); i.e. all deterioration is punished, but additional punishment is given based on the magnitude of the effect on edit distance.

Stasis is transformation where d(y̌i; yi)=d(ŷi; yi). In the case of an original image that produces a perfect OCR output, i.e xi/d(y̌i; yi)=0, stasis is ideal behavior, let this result be called ‘perfect stasis’, and other stasis be ‘imperfect stasis’. Perfect stasis should receive a loss of 0. When d(ŷi; yi) is high, and d(y̌i; yi)=d(ŷi; yi)=0, both xiand {circumflex over (x)}iare heavily distorted, and imperfect stasis provides little to no information about model performance. It may be the case that OCR fails to extract any text from both xiand {circumflex over (x)}i; one image may be better, but the difference is not significant enough to result in successful character extraction. Conversely, it may be the case that OCR extracts an excess of characters from both xiand {circumflex over (x)}i; one image may have more correct characters, but both have enough additional characters that improvement/distortion is masked. Lastly, it may be the case that OCR extracts the correct number of characters from xiand {circumflex over (x)}i, but transformation either fails to improve xi, or leads to an equal degree of distortion of other aspects of character recognition. Imperfect stasis is common behavior early in training, on heavily distorted input images; in both cases, the transformation of the model is insufficient to effect the edit distance. Imperfect stasis should receive a loss less than deterioration, but greater than imperfect improvement.

In view of this, the particular pseudo policy employed in the tested working is described as follows, purely as a non-limiting example. In this example, the minimum consequence assigned is 0.001 if improvements are made, and 0 if no improvements were made. If the improvement is positive, but the edit distance is non-zero, the penalty assigned was a factor of 0.001. If the improvement between inspector and filter is negative, the improvement score is multiplied by 3 and added to the base consequence. In other words, negative improvement was penalized by a factor of 3. If no improvement occurs, the improvement score is multiplied by 0.25 and added to the base consequence. In other words, zero improvement is penalized by a factor of 0.25. Implementation of this non-limiting example is demonstrated as follows:

def policy(improvements, edit_dists):

#Positive Improvement#The edit distance between the true text and the OCR output of the#filter-transformed image is less than the edit distance between true#text and OCR output of the inspector-transformed image.base_consequences=(improvements>0)*0.001#Negative Improvement:#The edit distance between the true text and the OCR output of the#filter-transformed image is greater than the edit distance between true#text and OCR output of the inspector-transformed image.base_consequences=(improvements<0)*3+base_consequences#No Improvement.base_consequences=(improvements==0)*0.25+base_consequences#If the edit distance between the text extracted from the#filter-transformed image and the true text==0, then one of 2 cases#occurred:##1. The inspector completely corrected the image on its own (leading#to perfect OCR), and the filter did not perform a transformation#that harmed OCR performance.#2. The filter improved the inspector-transformed image, leading to#perfect OCR performance.#In case 1, the filter did not harm a good image. In case 2, the filter#helped a bad image. In either case, the filter should not be penalized.#Thus, the consequence vector will be adjusted to have a penalty of 0#when the edit distance is 0.zero_edit=edit_dists.apply_(lambda d: 0 if d==0 else 1)adj_consequences=base_consequences*zero_edit#Weight consequences for negative improvement (when the filter-transformed#image has a greater edit distance than the inspector-transformed image),#using the difference between the edit distances of the filter/inspector#transformed images.weights=((improvements/−10)*(improvements<0))+torch.ones(improvements.size( ))weighted_consequences=adj_consequences*weightsreturn(weighted_consequences)

Warping transformations are the most computationally expensive to learn through convolution. Although it is possible to approximate common warping transformations through convolution, reasonable approximations require very deep networks, and excessive computational power. Many warping transformations have well defined solutions, and their learning task can be simplified to learning a warp parameter for a closed-form transformation; e.g. learning the center and angle of rotation to inverse map rotated pixel coordinates. Furthermore, the separability of different warping operations suggests that models learning warp parameters can be trained asynchronously and independently; a rotation model could be trained independent of translation, scale, shear, perspective, etc. . . . and not be limited to the same dataset.

Filtering transformations are analogous to the process of convolution; learning a filter kernel maps directly to the process of learning a convolution kernel. Therein, the process of learning a set of filter kernel translates well to the task of learning a set of convolution kernel in a convolutional neural network (CNN). Unlike warping, learning filters through convolution is relatively efficient.

Warping and filtering benefit from different learning tasks, and combining both into a single CNN is neither computationally nor data efficient. To improve the computation and data efficiency of the image transformer, and better structure the learning task, the image transformer employed in the tested working embodiment contains separate classes of sub-models for warping and filtering: inspectors, and filters. The inspector sub-models and filter sub-models are cooperatively integrated together to form what is referred to herein as a cooperative model.

Referring toFIG.2, in the context of the tested working embodiment, the inspectors are sub-models devoted to learning one or more parameters of a particular warping transformation. In this particular example, the inspector was devoted to a rotation transformation, and trained to learn a singular parameter thereof, specifically the angle of rotation, while the other rotation parameter (center of rotation) was a treated as predefined constant, particularly the center point of the image. Inspectors are supervised learning models that receive an image, zi, as an input to predict the value of the warp transformation parameter, {circumflex over (θ)}i, needed to correct zi. The predicted parameter, {circumflex over (θ)}i, is compared against the true parameter, θi, to update the inspector. The inspector learns to correct a single warp transformation, and the inspector object has a built-in closed-form transformation for the particular warp it learns, displayed as the method ‘Warp Image’.

There is no requirement that any training data be shared between different sub-models. As such, each inspector can receive a different dataset, and be trained independently before use in conjunction with other sub-models. The ability to asynchronously pre-train is a beneficial component to inspector architecture since inspectors require an additional θiparameter that is neither utilized by, nor provided in the training data of, the filter sub-models. Therein, the training data for the inspector does not need to be labeled with true text, and the training data provided to the filter sub-models does not need to be labeled with θi.

Referring toFIG.3, in the context of the tested working embodiment, the filters are sub-models devoted to learning a set of kernels to filter an input image using convolution. Filter training in isolation is identical to the comparative normalization scheme discussed previously in relation toFIG.1; the filter transforms an input image, xi, to produce {circumflex over (x)}i. xiand {circumflex over (x)}iare run through OCR to produce the extracted text strings □̌iand ŷi, respectively. The edit distances d(□̌i; yi) and d(ŷi; yi) are calculated and the difference d(□̌i; yi)−d(ŷi; yi) is passed to a pseudo-policy for a consequence to update the model.

The inspectors and filters can be trained separately, but must work together to complete the image transformation task. An effective architecture thus integrates both inspectors and filters into a cooperative model, as illustrated inFIG.5. When inspectors and filters are run in series, order matters. Filtering the inputs to the inspector has little effect on training, but warping the inputs to the filter provides a substantial improvement. The filter makes very little progress on images containing warp distortions, and when run in series with an inspector, the filter does not learn effective transformations until after the inspector has reached near-convergence. Asymmetric learning highlights the importance of pre-training the inspector, then training the filter.

Since the learning task of the inspector is not tied to OCR performance, and is far more structured than the learning task of the filter, it is important to distinguish what improvements were a result of the inspector, and what improvements were a result of the filter. Comparative normalization is still necessary; the OCR performance of the filter-transformed image must be normalized against the OCR performance of the input to the filter. When the inspector and filter are run in series, the input to the filter is not the original image, it is the inspector-transformed image. Therefore, the OCR performance of the filter-transformed image should be normalized against the OCR performance of the inspector-transformed image.

So, with reference toFIG.5, the inspector sub-model is first pre-trained using an inspector-training dataset comprises a set of generated inspector-training images ziand a respective set of known warp transformation parameters θiby which known text strings extracted from a set of source images were intentionally distorted, whereby the inspector sub-model is trained to predict a corrective warp-transformation parameter {circumflex over (θ)}iintended to correct the intentionally applied distortion. In use of the finished cooperative model, once fully trained, the inspector sub-model will thus calculate a predicted corrected warp-transformation parameter {circumflex over (θ)}ito be applied to an input image of unknown text content destined for the OCR engine via the multi-transform pipeline of the cooperative model. Since the learning task of the inspector is not tied to OCR performance, the inspector-training dataset need not contain text data representative of actual known text content of the training images ziof that dataset.

On the other hand, for the purpose of training the filter sub-model, a different filter-training dataset (or primary dataset) not only includes a set of filter-training images (or primary images) xi, which optionally may be different from the inspector-training images zi, but also includes primary labels composed of true text string data yirepresentative of the actual known text content of the training images xiof the filter-training dataset. To train the filter sub-model, each filter-training image xiis first passed to and run through the inspector sub-model, which calculates and applies a predicted corrective warp-transformation parameter {circumflex over (θ)}ito the filter-training image xi, thereby deriving an inspector-transformed filter-training image Îxi. One copy of the inspector-transformed filter-training image Îxiis passed directly to the OCR engine, bypassing the filter sub-model, and thus remaining “unfiltered”. Meanwhile, another copy of this inspector-transformed filter-training image Îxiis passed to and run through the filter sub-model, which calculates and applies a convolution kernel to this copy of the inspector-transformed filter-training image Îxi, thereby deriving a filter-transformed filter-training image {circumflex over (F)}xi.

Both the filter-transformed filter-training image {circumflex over (F)}xiand the unfiltered inspector-transformed filter-training image Îxiare inputted to the OCR engine, the respective resultant outputs of which are a filter-affected OCR result ŷiand a comparative filter-unaffected OCR result □̌i. A distance metric calculator receives both of these OCR output results ŷiand □̌i, and also receives the true text string y; for the training image xiconcerned, which denotes a targeted ideal OCR result. The distance metric calculator20calculates a first distance metric d(ŷi; yi) between the filter-affected output result ŷiand the targeted ideal result yi, and also calculates a comparative second distance metric d(□̌i; yi) between the comparative filter-unaffected OCR result □̌iand the targeted ideal result yi. The first distance metric d(ŷi; yi) is then normalized against the comparative second distance metric d(□̌i; yi) by calculating the improvement score d(□̌i; yi)−d(ŷi; yi). The calculated improvement score and first distance metric d(ŷi; yi) are together used to categorize the cooperative result of the filter and OCR into one of the five performance outcome categories listed earlier (I0E0, I0E+, 1+E0, I+E+, I-E0, I-E+). These performance categories are mapped by the pseudo policy to values usable by a standard loss function li, which is then used to update the filter sub-model.

One both sub-models have been fully trained, they are stored in one or more non-transitory computer readable media together among accompanying computer-executable instructions for execution by one or more computer processors of a computer system composed of at least one computer, or a plurality of networked computers.FIG.12shows a localized single-device implementation, where the computer readable memory of the same computing device in which the cooperative model is stored also stores a locally executable OCR engine.FIG.12Aillustrates one example of distributed multi-device implementation, where the cooperative model is stored locally on a single computer, which is connected via the internet or other network to a remotely executed OCR engine hosted by one or more other computers, whether a dedicated server, or a cloud server or other distributed computing system. In another example, not shown, the cooperative model itself may also be distributed among a plurality of computing devices, providing they are communicably interconnected by a suitable communications network to enable passage of data therebetween. The executable instructions enable receipt, or retrieval from memory, of an input image xifrom which a user desires text extraction via OCR, and which, once received or retrieved, is inputted to the inspector sub-model, whose execution then results in calculation of the predicted corrective warping parameter, followed by performance of a warp-transformation on the originally received/retrieved input image using the calculated corrective warping parameter. The resulting inspector-transformed image Îxiis then passed as input to the filter sub-model, whose execution derives a convolution kernel, which is then applied to the inspector-transformed image. The resulting filtered image {circumflex over (F)}xicooperatively transformed by the inspector and filter is then inputted to the separate black-box OCR process for extraction of the text ŷifrom the cooperatively transformed image, and subsequent viewing of the extracted text by a user on a display device, and/or local or remote storing of the extracted text in a usable format in computer readable memory for later retrieval, viewing, printing, etc.

Tested Working Example

Training Data

The following example documents the training and testing procedures performed, and the results obtained, during development of the tested working embodiment. In order to eliminate the possibility of a natural language model within the OCR engine improving the extracted text, the training images depict model/serial numbers. Model/serial number corpus was extracted from a set of source images. The model/serial number corpus used for this example contained 7855 unique model and serial numbers. The histograms ofFIG.6chart the lengths of the unique model/serial number strings used. The median and mode length was 10 characters, but the distribution had a slight positive skew with a mean length of ˜10.556 characters.

Tesseract OCR [6] was the OCR engine chosen for this example. Quite simply: Tesseract OCR could be run locally, played nice with other processes, processed images quickly, and was available at no financial expense. The most important factors in the selection process were local computation and speed. Other OCR engines were tried, but they drastically increased the training time. Calls to networked resources, extended output processing/parsing, and resource sharing incompatibilities made other OCR engines less viable for the purposes of prototype development and testing. None of Tesseract's default parameters were changed, and none of the source code was examined to tune the model. The choice of OCR engine was made purely out of time and resource constraints. The results of this example are expected to generalize to other OCR engines since none of the work was tuned for any particular engine.

Text images were generated from the source model/serial number strings, with a randomly selected font, then distorted with distortion parameters randomly selected from a specified distribution, as schematically shown inFIG.7. A collection of 25 fonts were used. This font collection includes serif, sans serif, italic, bold, oblique, mono, and font family combinations thereof. Multiple fonts and font faces were used in order to ensure the model was not specialized to a single font, and was instead trained to work on all major font families. The generated text image was returned with the source text and parameters of warp distortions applied. Each of the distortions applied corresponded to common distortions found in the source image set from which the model/serial numbers were extracted, in this case, captured images of machine dataplates having model and serial numbers thereon. The distortion types and parameter ranges were:1. Rotate (−20 deg, 20 deg): simulates rotation due to poor capture angle, or as a remnant of perspective correction. In the source images, 95% of images were rotated −20 to 20 degrees, thus the rotation distortion applied is selected from −20 to 20 degrees.2. Gaussian Noise(0, 0.375): Simulates defects of the text to be captured, the capture environment, and the camera lens. Parameters were chosen as a qualitative assessment of defects seen in source images.3. Brightness, Contrast, Saturation (0.9, 1.1): Simulates differences in lighting and surface finish. Parameters were chosen as a qualitative assessment of differences seen in source images.4. Hue (−0.1, 0.1): simulates differences in image sensor, lens coating/filter, and natural color fade. Parameters were chosen as a qualitative assessment of differences seen in source images.
FIG.7Ashows a small sample of the resulting training images derived from the intentional distortion of the generated text images. During training, a new set of images was generated for each epoch; so although the same model/serial number strings were used between epochs, the manifestation of each model/serial number as an image changed. Thus, each epoch used a novel image set. Note: the sample images shown in the figure were saved in JPEG format and resized for proper document formatting, and high frequency noise was removed. Actual training image tensors were very slightly different.

The initial image corpus consisted of 15,000+ machine dataplate images. A machine's dataplate is a placard affixed to the machine displaying brand name, product/model/serial number, and information relevant to the installation, maintenance, or certification of the machine.FIG.8shows select samples of source machine dataplate images. Though some distortions, occlusions, and perspective problems are present, all three dataplates shown have a legible model and serial number. Model and serial numbers were the primary fields utilized in this example, since many other fields involve natural languages where improvements may be due to language modelling and not image correction.

A ground truth text corpus was built using a three transcriber majority rule through Amazon Mechanical Turk, with random quality control checks for accuracy. Not all fields were legible on every dataplate, and not every image captures a unique dataplate (i.e. some images capture the same plate during different service/inspections, or the same plate from different angles). Using Turker extracted text and other metadata relevant to the image the image and service history of the machine, images of the same plate were used in aggregate to cross-validate and complete the Turker-extracted text. The final ground truth text corpus contained 7855 unique model and serial numbers.

The initial source images were insufficiently constrained for the scope of initial prototyping. The following considerations were tested when preparing the training set:Image Segmentation By FieldExclude extraneous text from edit distance calculation between true text and OCR output of the image. E.g. exclude electrical hazard warnings that are printed near a model/serial number.Field StackingStack multiple segments from the same dataplate, or from dataplates of the same style to increase the amount of context provided to the OCR engine.Image CroppingStandardize the size of input images to avoid dynamic changes to the computation graph during training.Reduce the size of images (without changing pixel density) in order to reduce computational cost of training.Perspective CorrectionUtilize close-form four-point perspective transform solutions to correct perspective on off-angle images.

Several tests were conducted on the field captured images, and certain limitations were exhibited, both as a computer vision task and as a Human Intelligence Task (HIT). The results of the tests are as follows:Image Segmentation By FieldComputer Vision Based Segmentation:Where possible, the corners of field bounding boxes were captured, and the regions contained by the convex hulls of the corners were made into a single field segment. When no bounding/format box was present, pixels were clustered by normalized color and position. The convex hull containing each cluster was made into a field segment. The candidate segments were then run through OCR, and segments that did not contain any text were discarded. Unfortunately, low quality images have very high segmentation error, especially when character recognition based elimination is used. An OCR engine can recognize noise as characters, and fail to recognize true characters. Furthermore, connecting a segment to the appropriate extracted field text is complicated by the fact that there are many more segments than extracted fields. There may be a segment for a non-target field that was correctly identified, but does not match any extracted fields. Further tuning of an image segmentation algorithm is beyond the scope of this research.HIT Based Segmentation:A HIT was created asking the Turker to box a set of target fields. This method solved the problem of linking segment to extracted text, but still presented issues. Namely, not every Turker enclosed the same area or the same content. Some Turkers enclose the field label (e.g. ‘MODEL NO:’), some Turkers leave little to no padding around the text, some Turkers slightly clip the text, etc. . . . . Ultimately, HIT based segmentation solved some of the problem present in computer vision based segmentation, but still had many issues. Future research may involve a better HIT environment for the Turkers, or additional preprocessing to simplify the HIT. However, such improvements are beyond the scope of this research.Field StackingFields that could be successfully segmented were sorted by the type of dataplate from which they were extracted, and then stacked (e.g. all Trane branded condenser unit dataplates from the 1980s have the same font and layout, and thus combinations of field segments from that group were stacked into a single image). Field stacking was limited by the efficacy of field segmentation, and of the stacks that were tested, no significant improvement in OCR accuracy was observed.Perspective CorrectionComputer Vision Based Perspective Correction:The corners of dataplates were identified using a combination of Harris corner detection and the intersections of Hough lines. Unfortunately, the artifacts present in low quality images made identifying the corners of a dataplate difficult. Since the perspective transform to right a quadrilateral is sensitive to the corners chosen, small errors in corner detection expanded into large errors in post-transform images. Improvements to corner detection are ultimately beyond the scope of this research.HIT Based Perspective Correction:A HIT was created asking the Turker to locate the corners of the dataplate present in the image displayed. This worked reasonably well for dataplates with sharp corners, but proved to be more difficult when dataplates had rounded corners. The Hough line intersections used in the computer vision task helped circumvent the problem of rounded corners, but the Turkers struggled to approximate the intersection of dataplate edges. The HIT was edited to ask for Turkers to click the center of the rounded corner (instead of approximating the intersection of edges), but this new HIT did not achieve any improvement in usability of the final data.
Results

‘Raw edit distance’ describes the non-normalized distance between true text and the image at a particular stage of the transformation pipeline. Raw edit distance does not measure improvement or detriment due to a particular transformation; it represents the OCR performance—not model performance—of a particular stage in the image transformation pipeline. Improvement due to model performance can be calculated by comparing the raw edit distance between transitions in the image transformation pipeline. There are three raw edit distances to consider:ED1: True Text vs OCR(Original Image) The baseline edit distance before any transformations have been performed.ED2: True Text vs OCR(Inspector-Transformed Image) The edit distance after corrective warping is applied to the original image by the inspector.ED3: True Text vs OCR(Inspector→Filter-Transformed Image)The edit distance after corrective filtering has been applied to the inspector-transformed image by the filter.
FIG.9shows a comparison of raw edit distance between true text and original images, inspector-transformed images, and inspector→filter-transformed images. Histograms plot the results of 1000 sample images selected randomly from the corpus of 7855. Inspector→filter-transformed images are images generated by transforming an original image using the inspector, and then transforming the inspector-transformed image using the filter. Inspector→filter-transformed images represent the complete pipeline of transformations applied by the inspector and filter sub-models. NOTE: The histogram of raw edit distance of inspector-transformed images contains several outliers>100. All 3 histograms share the same x-axis, so the outliers for ED2 are not shown. However, the bin widths have been kept the same to ensure fair comparison.

The distribution for ED1 (FIG.9A) is centered near the mean length of true text (seeFIG.6for distribution of true text string length), but has a larger standard deviation. The large mean edit distance, and clustering about the mean edit distance, indicates minimal OCR success; either many incorrect characters were extracted, or few characters were extracted at all. Such a distribution demonstrates a high degree of distortion in the original images. The distribution of ED2 (FIG.9B) is multi-model with a high and low mode. The high mode is near the third quartile—near the mean of ED1. The low mode is near 0, indicating that some images could be substantially improved through corrective warping by the inspector. The distribution has negative skew (mean<median), but there are several large outliers (beyond the x-range of the histogram). The ED3 distribution (FIG.9C) is unimodal with a mode of 0, and monotonically decreasing; the high mode of ED2 has been removed. The mean and median are very close, but the distribution still has a very slight positive skew. The inter-quartile range (IQR) of ED3 is equal to that of ED1, but the mean and median are closer and smaller. ED3 is a clear improvement from ED1 and ED2.

The edit distance improvement score of a transformation (or set of transformations) is the difference between the raw edit distance of the input and output image; the comparative normalized distance. E.g. the improvement score of the inspector is ED1-ED2, which measures the reduction in raw edit distance between the input and output of the inspector, namely, the original images and the inspector-transformed images.FIG.10shows edit distance improvements for said 1000 sample images. The first histogram represents the improvement of the original image due to inspector transformations, the second histogram represents the improvement of the inspector-transformed images due to filter transformations, the third histogram represents the improvement of the original image due to the transformation of the inspector and filter used in series. The third histogram represents the total improvement due to the overall image transformer, and bounds for 95% and 99% confidence intervals are shown.

The improvement distributions of the inspector and filter look similar in general shape—equal IQR and bimodal —, but the mean and median improvement of the filter are larger, and the right tail of the filter's improvement distribution is shorter. However, both the inspector and filter have non-zero average improvement, with the filter slightly less likely to have large negative improvement. When used in series, the inspector and filter achieve significant improvement at α=0.01, with a distribution centered slightly lower than the mean true text string length; indicating a large proportion of the true text is extracted due to improvement. The tested working embodiment thus provides clearly discernable improvement in the technological field of optical character recognition, where the performance a computer-executed OCR engine is improved by computer-implemented pre-processing of the OCR's input data using separate transformation and filter sub-models that have been trained by machine learning on minimization of a normalized distance metric of the OCR output.

One of the most surprising results was the non-intuitive nature of the transformations and corresponding OCR performance. The cooperative image transformation model of the tested working embodiment learns transformations that improve OCR engine performance, not human legibility; the learned transformations do not match what a human reader would intuitively pick as an improvement, yet produce far better OCR performance. As discussed in the preceding paragraph, a significant (at α=0.01) improvement was achieved by the image transformer, and the average final edit distance between true text and transformed image was small. Quantitatively, the effectiveness of the model can be clearly understood; qualitatively, it is difficult for the human eye to distinguish why the learned transformations are so effective.FIG.11shows a set of sample images at different stages of the image transformation pipeline paired with the output of Tesseract OCR on the image.

Letting μ symbolize the mean edit distance improvement due to model transformations, consider an Upper-Tailed Z-test:

H0⁢:⁢⁢μ=0HA⁢:⁢⁢μ>0z=μ-0σ≈9.2993.355≈2.772⁢;⁢->p≈0.003
For α>0:003, H0may be rejected. With 99.7% confidence, the improvement to edit distance due to model transformations was significant. The image transformer created a significant increase in OCR performance. 95% of images received an edit distance improvement between 2.723 and 15.874, and of 1000 test images, only 6 were made worse.

Edit DistanceTransformedOriginal≤379.0%0.6%≤266.1%0.1%≤147.1%0.1%027.3%0.1%
As displayed by the table above, over a quarter of the images received perfect correction, and nearly half produced an OCR output within a single edit operation of the true text.

The image transformation model did not make any alterations to the OCR engine used, Tesseract OCR. All parameters were default, and no inspection of Tesseract was performed to tune the model, or adjust the training set. Thereby, the OCR engine was treated as a black-box, and the training regimen generalizes to any other OCR engine. The true text strings from which text images were generated were model/serial numbers; the source text did not follow any natural language, and the OCR engine used, Tesseract, was not adjusted for recognizing strings from non-natural languages. Furthermore, text images were generated using many different fonts and font families; serif, san-serif, mono, oblique, italic, bold, condensed, and combinations thereof. As such, the model was independent of any particular font face. All of the generated text images in the tested working embodiment were a single line of text, though it is anticipated that similar result could be achieved with multi-line extraction and advanced mathematical typesetting. To the extent that advanced typesetting and symbolism is tested, further experimentation could be conducted on different alphabets and phoning marks. A natural extension of the testing working example would be to generate text images of typeset math. This would preserve language independence, but allow for testing multi-line text and less trivial character relationships.

The teachings of the present invention may be applied to less constrained images than the particular examples disclosed above in relation to the tested working embodiment. In one non-limiting example of a further embodiment, an additional “detective” sub-model could be added in upstream relation to the “inspector” and “filter” sub-models of the illustrated embodiment, and could be trained to perform additional preprocessing tasks on very poorly constrained images. The detective could assemble a ‘dossier’ on the image detailing the bounding boxes of target fields, text orientation, and segmentation/crop parameters. The detective could be trained to prepare poorly constrained images for input to the inspector. It will therefore be appreciated that the input image to the inspector need not necessarily be a raw input image in its originally captured or received form.

Not all images will benefit from both warping and filtering transformations. Although the inspector and filter could theoretically learn a no-op for such images, it may be more efficient to include a ‘valve’ network that directs images to the appropriate sub-models. The valve network could learn both order and exclusion—the order in which the sub-models are applied, and what sub-models are used. Such a valve network may provide a similar efficiency gain as that introduced by the separation of warping and filtering; the valve network offloads part of the warping and filtering task to a specialized sub-model.

Other Use Cases

It will be appreciated that application of the forgoing operating components and principles of the present invention is not limited specifically to OCR; the input/output of any other optical recognition model could be used in place of an OCR engine, and gain similar benefit from the novel aspects of the cooperative model and associated training methodologies disclosed herein. In each case, while the specific type of data concerned may vary from one example to another, the training process follows the same general workflow shown inFIGS.5and14, and the end-use application likewise follows the same general workflow shown inFIGS.12and13.

Object Recognition/Classification

In the case of optical classification tasks, the OCR engine could be substituted with a classifier, and the pseudo-policy could be replaced with a classifier evaluation metric—e.g. F1, precision, recall. So training images, instead of captured imagery of containing known text content, would be captured imagery containing objects of known types, against which the classifier evaluation metric would evaluate generated classification labels of objects detected by the classifier, with the above described comparative normalization being used between the inspector-transformed images and the original images during training of the inspector, and being used between the inspector→filter-transformed images and the inspector-transformed images during training of the filter, optionally using different training images from those used to train the inspector.

In this example, the inspector pre-training data (z) would be images containing a target object and any surrounding objects. The inspector pre-training labels (6) applied to this pre-training data would be corrective warp parameters (e.g. angle of rotation, perspective transform homography, etc. . . . ) and/or bounding contour of the target object. The primary/filter-training data (x) would be Images containing the target object and any surrounding objects, and the primary labels (y) would be the known class label for the target object. As with the OCR example, the inspector pre-training image data and the primary/filter-training image data can optionally be the same, as long as the appropriate labels for the two distinct training tasks are provided, or the two datasets can contain different image data. The inspector can be trained more generally to isolate the foreground/background and perform corrective warping.

The cooperative inspector-filter model can be trained upstream of any object recognition process, for example in black-box relation to existing off-the-shelf object recognition software (e.g. Google Lens, Amazon Rekognition, IBM Watson Visual Recognition, etc.). The inspectors learn corrective warping (much like the inspector in the OCR example) and or image segmentation. For example, the inspector could learn general corrective warping and object/background segmentation. The filter sub-models could learn to filter the inspector-transformed image to improve object recognition. The filters are updated using comparative normalization of the cross-entropy improvement between the transcript of the inspector-transformed image and the filter-transformed image. One of these filtering operations could be to increase the contrast between phonemes. Referring to the object recognition software as ORS for brevity, the filter-affected ORS result ŷiwould be a resultant classification output of the ORS based on the filter-transformed image {circumflex over (F)}xi, and the comparative filter-unaffected ORS result y̌iwould be a resultant classification output of the ORS based on the inspector-transformed image Îxi.

In end-use application, the trained cooperative model is run on captured images before being passed to black-box ORS. For example, an image is captured, corrective warping is applied and the foreground is segmented from the background by the inspector. The warped foreground segment is filtered by the filter, and then passed to ORS to classify the foreground object. To demonstrate a specific non-limiting example of use, consider that a customer captures an image of an unknown vegetable at the grocery store. Before the cooperative model can be used together with ORS to perform optimized object recognition on that image, the inspector is first pre-trained to apply corrective warping and segment foreground/background on a general image set. The filter is trained using labeled images of vegetables, and updated by comparative normalization of cross-entropy improvement in ORS generated classification labels derived from the inspector-transformed image and filter-transformed image. During end use of the trained model on the grocery customer's captured image, the inspector applies corrective warping and segments the vegetable in the customer's hand (the foreground) from the vegetables on the shelf (the background). Then the foreground segment is filtered by the filter, and the filtered image is passed to black-box ORS for classification.

Application of the cooperative model is also not particularly limited to optical analysis of image data, and may be applied to pre-optimize other types of input data for other categories of computer-implemented analysis. Other examples include applications where timeseries data, rather than image data, is the input.

Speech Recognition

In the technological field of audio processing, one such example would be speech recognition, where the training data is timeseries audio data derived from captured audio containing known spoken words against which the distance metric of detected words by the speech recognition process can be taken during the comparative normalization steps.

In this example, the inspector pre-training data (z) would be captured audio tracks containing the speaking voice of a particular target speaker whose voice the model is being trained to recognize, along with the speaking voice of one or more other nearby speakers and/or other background noise. The inspector pre-training labels (θ) applied to this pre-training data would be time warping parameters of audio tracks containing the target speaker's voice in isolation. The primary/filter-training data (x) would be raw audio containing the speech of the target speaker, along with speech of other nearby speakers and/or background noise, and the primary labels (y) would be text transcripts of the targeted speaker's recorded speech in that raw audio. The inspector pre-training audio data and the primary/filter-training audio data can optionally be the same, as long as the appropriate labels for the two distinct training tasks are provided, or the two datasets can contain different audio data from one another. The inspector can be trained more generally to isolate the voice of the target speaker.

The cooperative inspector-filter model can be trained upstream of any speech recognition process, for example in black-box relation to existing off-the-shelf speech recognition software (e.g. Nuance Dragon, Apple Siri, Microsoft Cortana, etc.). The inspectors learn speaker recognition and speech normalization (independent of speech recognition) to isolate and normalize the voice of the target speaker. For example, the inspector could learn dynamic time warping to model a target speaker's voice, and normalize the cadence to a standard form. The filter sub-models could learn to filter the inspector-transformed audio track to improve speech recognition. Referring to the speech recognition software as SRS for brevity, the filters could be updated using comparative normalization of the edit distance improvement between the SRS resultant transcript of the inspector-transformed audio and the filter-transformed audio. So, the filter-affected SRS result ŷiwould be a resultant text transcript outputted by the SRS based on the filter-transformed audio {circumflex over (F)}xi, and the comparative filter-unaffected SRS result y̌lwould be a resultant text transcript outputted by the SRS based on the inspector-transformed audio Îxi.

In end-use application, the trained cooperative model is run on captured audio before being passed to the black-box SRS. For example, an audio track is captured, the target speaker's voice is isolated and normalized by the inspector. The isolated target speaker audio is then filtered by the filter, and finally passed to the SRS to produce a transcript of the audio, which then may be put to any variety of uses (saved for later retrieval, displayed in real time, transmitted elsewhere, scanned for keywords, etc.). To demonstrate a specific non-limiting example of use, consider that a politician or other orator giving a speech at a public venue is recorded, and the recorded audio contains the politician's speech, as well as voices among the crowd and various background noise. Before the cooperative model can be used together with SRS to perform optimized transcription of that speech, the inspector is pre-trained to isolate and normalize the politician's voice using prior radio/TV interviews in which the politician's voice is isolated. Transcripts of those interviews released by the politician's staff and attending journalists are used as true text labels when measuring edit distance between true text and the text transcript output by the SRS. The filter is trained using the comparative normalization of the edit distance improvement between the text transcript from the inspector-transformed audio and the text transcript from the filter-transformed audio. During end use of the trained model on the recorded audio of the politician's speech (i.e. in the intended input to the SRS), the inspector first isolates and normalizes the target speaker's speech, after which the filter then filters the speech and passes it on to the black-box SRS to produce a transcript of the speech.

Motion Tracking Analysis

One non-limiting example in this category of end use for the cooperative model of the present invention is analyzing the signal feeds of exercise/health equipment that tracks the motion of the human body to improve form/therapeutic benefit of an exercise. In this example, the inspector pre-training data (z) would be timeseries data representing the acceleration/position of motion tracking components of the equipment. The inspector pre-training labels (θ) applied to this pre-training data would be time warp and scale parameters of the signal feeds from the motion tracking components. The primary/filter-training data (x) would be timeseries data representing the acceleration/position of motion tracking components, and the primary labels (y) would be classification labels denoting relative correctness of motion. The inspector pre-training timeseries data and the primary/filter-training timeseries data can optionally be the same, as long as the appropriate labels for the two distinct training tasks are provided, or the two datasets can contain different timeseries data from one another. The inspector can be trained more generally to approximate the transforms necessary for the particular morphology of the human subject.

The cooperative inspector-filter model can be trained upstream of any motion tracking system, for example in black-box relation to existing off-the-shelf motion tracking software, referred to herein as MTS for short. The inspectors learn time warping of the feeds of the motion tracking components. For an MTS that analyzes exercise form (EFMTS), differences in body morphology create differences in motion independent of the correctness of form (e.g. shorter arms trace a shorter arc when swung). The inspector can be pre-trained using general motion tracking data from the subject. In this example of exercise form analysis, the filter sub-models learn to filter the inspector-transformed timeseries to improve form failure recognition. One of these filtering operations could be to remove noise from the motion capture, or remove superfluous movements not related to form. The filters are updated using comparative normalization of the cross-entropy improvement of form error detection. So, the filter-affected EFMTS result ŷiwould be a form correctness classification output of the black-box EFMTS given the filter-transformed timeseries {circumflex over (F)}xi, and the comparative filter-unaffected EFMTS result y̌lwould be a form correctness classification output of the black-box EFMTS given the inspector-transformed timeseries Îxi.

In end-use application, the trained cooperative model is run on captured motion data before being passed to black-box EFMTS. For example, motion data is captured by the equipment, to which time warping and motion scaling are applied by the inspector. The warped timeseries is filtered by the filter, and then passed to EFMTS to classify the correctness of motion. To demonstrate a specific non-limiting example of use, consider a patient of a physical therapist who uses motion tracking equipment to identify errors in the patient's exercise form. Before the cooperative model can be used together with EFMTS to optimize the results thereof, the inspector is first pre-trained using the general motion and morphology of the patient. The filter is trained by comparative normalization of cross entropy improvement in black-box exercise form classification software between the inspector-transformed timeseries and the filter-transformed timeseries (using a set of motions labeled by the physical therapist for correctness of form). During end use of the trained model, the patient's motion is captured, warped by the inspector, then filtered by the filter, and passed to the physical therapist's EFMTS to be classified by correctness of form.

Other Timeseries Applications

In the technological field of medical diagnostic equipment, a computer-implemented arrhythmia classification process (ACP) receiving timeseries electrocardiogram data as its input can benefit from pre-optimization of this input data by the cooperative model when having been trained on electrocardiogram data of cardiological patients of previously diagnosed arrhythmia type. In the technological field of radar/sonar signal processing, another application example involving timeseries data is a radar/sonar signature classification process (SCP), which receives radar/sonar timeseries data as its input, and can benefit from pre-optimization of this input data by the cooperative model when having been trained on radar/sonar signature data of known objects. From these non-limiting examples, it will be appreciated that the disclosed cooperative transformation model has potential for broad application to a variety of recognition/perception tasks.

Since various modifications can be made in my invention as herein above described, and many apparently widely different embodiments of same made, it is intended that all matter contained in the accompanying specification shall be interpreted as illustrative only and not in a limiting sense.

REFERENCES

[1] Bassil, Youssef, and Mohammad Alwani. Ocr post-processing error correction algorithm using google online spelling suggestion. Journal of Emerging Trends in Computing and Information Sciences, 3(1), 2012.[2] Beitzel, Steven M., Eric C. Jensen, and David A. Grossman. Retrieving ocr text: A survey of current approaches. 2003.[3] W. Bieniecki, S. Grabowski, and W. Rozenberg. Image preprocessing for improving ocr accuracy. In 2007 International Conference on Perspective Technologies and Methods in MEMS Design, pages 75-80. IEEE, 2007.[4] Cormen and Thomas H. et al. Introduction to algorithms. MIT press, 3rd edition, 2009.[5] Dengel and Andreas et al. Techniques for improving ocr results. pages 227-258, 1997.[6] Ray. Smith. An overview of the tesseract ocr engine.[7] Xiang Tong and David A. Evans. A statistical approach to automatic ocr error correction in context. 1996.[8] Wick, Michael, M. Ross, and E. Learned-Miller. Context-sensitive error correction: Using topic models to improve ocr. In Ninth International Conference on Document Analysis and Recognition (ICDAR 2007), volume 2. IEEE, 2007.[9] Yujian, Li, and Liu Bo. A normalized levenshtein distance metric. IEEE transactions on pattern analysis and machine intelligence, 29:1091-1095, 2007.