English (unofficial) translations of posts at kexue.fm
Source

A Brief Exploration of OCR Technology: 6. Optical Recognition

Translated by DeepSeek V4 Pro. Translations can be inaccurate, please refer to the original post for important stuff.

After the first and second steps, we are already able to identify the regions of individual characters within an image. Next, we can build a corresponding model to recognize these individual characters.

Model Selection

In terms of the model, we have chosen the Convolutional Neural Network (CNN) model from deep learning. By utilizing multiple layers of convolutional neural networks, we have constructed a recognition model for individual characters.

A Convolutional Neural Network is a type of artificial neural network that has become the mainstream model in the current field of image recognition. It reduces the complexity of the network model and the number of weights through local receptive fields and weight sharing methods. Its network structure is more similar to biological neural networks, which suggests it will inevitably yield superior results. In fact, the main reasons we chose convolutional neural networks are:

  1. Automatic feature extraction from raw images: The CNN model can directly take raw images as input, eliminating the difficult core part of traditional models—manual feature extraction.

  2. Higher precision than traditional models: For example, in the MNIST handwritten digit recognition task, it can achieve an accuracy of over 99%, which is much higher than the accuracy of traditional models.

  3. Better generalization ability than traditional models: This means that the deformation of the image itself (scaling, rotation) and noise on the image do not significantly affect the recognition results, which is exactly what a good OCR system requires.

Training Data

To train a good model, there must be a sufficient amount of training data. Fortunately, although there is no ready-made data available, since we are only performing recognition of printed fonts, we can use a computer to automatically generate a batch of training data. Through the following steps, we constructed a fairly comprehensive set of training data:

  1. More details: Since the structure of Chinese characters is more complex than digits and English letters, I used 48 \times 48 grayscale images to construct samples as input for the model to capture more detailed information.

  2. Common Chinese characters: To ensure the practicality of the model, we crawled hundreds of thousands of articles from the WeChat Official Accounts Platform, merged them to count their respective frequencies, and finally selected the 3,000 most frequent Chinese characters (in this article, we only consider simplified characters). Adding 26 letters (both cases) and 10 digits, a total of 3,062 characters were chosen as the model output.

  3. Sufficient data: We manually collected 45 different fonts, ranging from formal styles like SimSun, SimHei, and KaiTi to non-standard handwritten styles, basically covering various printed fonts comprehensively.

  4. Artificial noise: For each font, we constructed images in 5 different font sizes (46 to 50), with 2 images per size. To enhance the generalization ability of the model, 5% random noise was added to each sample.

Through the above steps, we generated a total of 3062 \times 45 \times 5 \times 2 = 1,377,900 samples as training data, which is clearly sufficient.

Model Structure

Regarding the model structure, there is previous work to reference. A similar example is the recognition of MNIST handwritten digits—which often serves as a "touchstone" for new image recognition models—where over 60,000 handwritten digit images of size 28 \times 28 pixels are recognized. This case shares certain similarities with our Chinese character recognition system, so we can learn from its structure. A common model structure for recognizing MNIST handwritten digits via CNN is shown in the figure below:

A network structure used for MNIST handwritten digit recognition
The network structure used in this article for recognizing printed Chinese characters

After sufficient training, a network structure like the one in Figure 17 can achieve an accuracy of over 99%, indicating that this structure is indeed viable. However, it is obvious that there are only 10 handwritten digits, while there are thousands of commonly used Chinese characters. In the classification task of this article, there are 3,062 targets. This means Chinese characters have much more complex and fine structures; therefore, various aspects of the model need to be adjusted. First, for the model input, we increased the image size from 28 \times 28 to 48 \times 48 to preserve more details. Second, the model structure was adjusted for complexity, including: increasing the number of convolution kernels, increasing the number of hidden nodes, and adjusting weights. Our final network structure is shown in Figure 18.

For the activation function, we chose the ReLU function: ReLu(x)=\left\{\begin{aligned}&x,\quad x>0\\ &0,\quad x\leq 0\end{aligned}\right. \tag{13} Experiments show that compared to traditional activation functions like sigmoid and tanh, it can significantly improve model performance [3][4]. To prevent overfitting, we used Dropout [5], the most commonly used method in deep learning networks, which randomly deactivates some neurons. This is equivalent to training multiple different networks simultaneously, thereby preventing overfitting that might occur in certain nodes.

It should be noted that regarding the model structure, we actually performed a large amount of screening work. For example, for the number of neurons in the hidden layer, we spent several days trying values such as 512, 1024, 2048, 4096, and 8192, finally obtaining 1024 as a suitable value. Too many neurons make the model too large and prone to overfitting; too few lead to underfitting and poor results. Our tests found that from 512 to 1024, there was a significant improvement in performance; however, further increasing the nodes did not yield significant improvements and sometimes even caused a noticeable decline.

Model Implementation

Our model was completed on a server running CentOS 7 (24-core CPU + 96G RAM + GTX960 GPU), using Python 2.7 for coding, Keras as the deep learning library, and Theano as the GPU acceleration backend (Tensorflow repeatedly prompted memory overflow and configuration was unsuccessful).

For the training algorithm, the Adam optimization method was used. The batch size was 1024, and the model was iterated for 30 epochs, with each epoch taking approximately 700 seconds.

When visually similar characters appear, high-frequency characters should be more likely. A typical example is the character "Ri" (sun/day) and "Yue" (to say). Their features are very similar, but the frequency of "Ri" is much higher than "Yue"; therefore, "Ri" should be prioritized. Consequently, while training the model, we also adjusted the final loss function of the model so that high-frequency characters have higher weights, which improves the model’s predictive performance.

After multiple rounds of debugging, we finally obtained a reliable model. The convergence process of the model is shown in the figure below.

Training curves: Loss and Accuracy (Acc)

Model Verification

For individual character recognition, our model outperforms Google’s open-source OCR system, Tesseract.

Training Set Verification

The verification report of the final trained model on the training set is shown in Table 1.

Summary of model training results

As seen in Table 1, even with samples containing random noise, the model’s accuracy remains at 99.7%. Therefore, we can confidently say that from the perspective of individual character recognition alone, our results have reached the state of the art level. Furthermore, in regular fonts such as SimHei and SimSun (regular font samples refer to training samples where the font is SimHei, SimSun, KaiTi, Microsoft YaHei, or Arial Unicode MS, which are common in printed materials), the accuracy is even higher!

Test Set Verification

We separately selected 5 fonts and generated a batch of test samples using the same method (30,620 images per font, totaling 153,100 images) to test the model. The model achieved a test accuracy of 92.11%. The test results for the five fonts are shown in Table 2.

Model results on the test set (5% random noise)

The table shows that even for samples outside the training set, the model performance is quite good. Next, we increased the random noise to 15% (which is quite severe for a 48 \times 48 character image). The test results are shown in Table 3.

Model results on the test set (15% random noise)

The average accuracy was 87.59%, meaning the impact of noise is not significant, and the model can maintain an accuracy of around 90%. This indicates that the model has fully reached a practical level.

When reposting, please include the original address of this article: https://kexue.fm/archives/3831

For more detailed reposting matters, please refer to: "Scientific Space FAQ"