# A Study of Spatial Attention and Squeeze Excitation Block Fusion Improved ResNet for Identifying Bank Notes

Authors: Junjun Huo
Journal: Security and Communication Networks
 (2021)

---

## Abstract

Based on deep learning and digital image processing algorithms, we design and implement an accurate automatic recognition system for bank note text and propose an improved recognition method based on ResNet for the problems of difficult image text extraction and insufficient recognition accuracy. Firstly, a deep hyperparameterized convolution (DO-Conv) is used instead of the traditional convolution in the network to improve the recognition rate while reducing the model parameters. Then, the spatial attention model (SAM) and the squeezed excitation block (SE-Block) are fused and applied to a modified ResNet to extract detailed features of bank note images in the channel and spatial domains. Finally, the label-smoothed cross-entropy (LSCE) loss function is used to train the model to automatically calibrate the network to prevent classification errors. The experimental results demonstrate that the improved model is not easily affected by the image quality, and the model in this paper has good performance in text detection and recognition in specific business ticket scenarios.


---

## Body

## 1. Introduction

Automatic text recognition is one of the popular research topics in the field of computer vision [1], and its technology mainly includes two parts: text detection and text recognition. Traditional Optical Character Recognition (OCR) is based on image processing (minimization, texture analysis, connected domain analysis, etc.) [2–4]. Modern business bills are of many types and placed randomly, so it is difficult to achieve good recognition results with traditional OCR detection methods. In addition, traditional OCR uses manually designed extracted features to train text recognition models, which is a time-consuming and laborious process. Chinese characters have many categories and complex character structures, and the recognition effect is often poor [5].With the rapid development of deep learning, the Convolutional Neural Network (CNN) has achieved great success in the field of computer vision. Compared with the traditional shallow features extracted by manual design, the CNN can naturally integrate low/medium/high/different levels of features, which are more conducive to discriminators to make decisions. In image classification tasks, starting from AlexNet [6], excellent network structures such as VGG [7], Inception [8], ResNet [9], DenseNet [10], and SeNet [11] have been derived. The excellent performance of CNNs in image classification tasks has led more and more users to migrate them to general-purpose target detection tasks. The R-CNN [11] was the first algorithm that successfully applied deep learning to target detection. Since then, Fast R-CNN [12], Faster R-CNN [13], Mask R-CNN [14], and other detection models have been continuously optimized and improved to substantially improve the accuracy and speed of detection. At present, most of the regional mainstream suggestion-based target detection networks are based on Faster R-CNN for improvement. The original Faster R-CNN is for general-purpose target detection tasks, and we have improved and optimized it to make it better adapted to text detection, especially for bank notes.In recent years, text recognition techniques combining the CNN and RNN (Recurrent Neural Network) have received a lot of attention. The CNN is used to extract representational image features, and the RNN is naturally suitable for the recognition problem of sequence data, so this network architecture is well suited for image-based text line recognition. Convolutional RNN [15] is a representative approach for this type of network architecture, which uses CNN networks to extract high-level semantic features of images, transforms the extracted features into feature sequences, and then, uses a bidirectional long- and short-term (BiLSTM) memory network [2, 16]. This model uses a CNN network to extract high-level semantic features, converts the extracted features into feature sequences, and then, uses a BiLSTM network [17–19] to capture the contextual information in both directions before and after the sequences and uses a CTC (Connectionist Temporal Classifier) [20] to decode the sequence features to obtain the final text recognition results. This CNN + BiLSTM + CTC-based network model has become the mainstream framework for ticket text recognition.Based on deep learning and image processing algorithms, this paper designs and implements an automatic bill recognition system that can accurately recognize text information for the specific task of recognizing the content of banking bills.


## 2. Related Work

Using some dimensionality reduction methods, important information may also be missed [21]. Compared with traditional methods, CNNs are robust to noise, and therefore, the CNN is less influenced by preprocessing [22]. CNNs use a large amount of data to train the model, and the trained model is more generalized. In recent years, with the development of deep learning, bank instrument recognition methods based on CNNs have emerged [23–25]. In [26], the VGG-16 network framework was used for bank note recognition, and although good results were obtained after training a large amount of data, the computational complexity of the model was large and the training time was too long. In [27], a full convolutional network was proposed to extract bill features, which is very capable of feature extraction but insensitive to image details and prone to misclassification. The work in [28] used a deep DenseNet network with differential images as network input, which makes training and verification less susceptible to noise, but the training time is longer. In [29], a four-layer CNN with fused convolution was proposed for bank note recognition, and although good recognition results were obtained, their method and experiments were not evaluated using a public database. In [30], a combination of random forest and neural network for palm vein recognition reduces the storage space and the classification error and has a good performance, but the images need to be reprocessed, which takes longer time [31].In order to obtain better bank note recognition results, this paper improves on the ResNet network by first reducing the ResNet network to 8 layers and using deep hyperparameterized convolution (DO-Conv) instead of traditional convolution to reduce network computation and improve network performance. Then, SAM and the SE-Block dual attention mechanism are fused to pay attention to the channel and space to effectively extract the detailed information of the image in the channel and space. Finally, label smoothing is applied to the cross-entropy loss function to bring the classification probability results closer to the correct classification and further improve the accuracy of image classification.


## 3. ResNet Network Model

ResNet is a deep CNN architecture published by Microsoft Research. When training a network model, the deeper the network is, the more likely it is to experience gradient disappearance and gradient explosion, which affects the performance of the model [32]. In order to solve this problem, a residual block is used to build a directly connected channel, which directly bypasses the input information to the output and improves the network performance. Because of this advantage, the residual network is widely used in the field of image recognition. The structure of the residual block is shown in Figure 1, where the input XL is directly passed through two convolutional layers to obtain the output XL+1, and the FXL in the figure is the residual mapping function of the solver network:(1)XL+1=XL+FXL.Figure 1
Residual module.Texture features are generally used as features for banknote recognition. However, some different individuals have high similarity in the texture features of bank notes, so more detailed features are needed to distinguish them. The residual network can learn new features while the network performance and parameters remain unchanged, which makes the residual network more suitable for the hand banknote image database. Based on ResNet, the network is optimized in terms of running time and recognition accuracy.


## 4. Improvement Based on the ResNet Network

### 4.1. Deep Hyperparametric Convolution

The CNN uses convolution kernel to extract the characteristics of hand bank bills and adds an additional depth convolution to the traditional convolution layer to form a deep hypercalcemia convolution. This combination constitutes over parameterization, which increases the network reasonable parameters and improves the quality of extracting the texture characteristics of hand bank bills so that the network model is more suitable for bank bill recognition. The traditional convolution layer is shown in Figure2. In the figure, P is a two-dimensional tensor, p∈RM×Cin, where M represents the spatial dimension of the characteristic graph and Cin is the number of channels of the input characteristic graph. Convolution kernel K is a three-dimensional tensor, K∈RCout×M×Cin, of which Cout is the number of channels of the output characteristic graph, and the output after convolution operation is a Cout-dimensional characteristic graph [33].(2)O=∑iM×CinKCoutPi.Figure 2
Traditional convolution.Unlike traditional convolution, one convolution kernel is responsible for one channel in deep convolution, and a channel can only be convolved by one convolution kernel. In traditional convolution kernels, the convolution kernel of each channel is dotted with the entire feature map. In deep convolution, each input channel of the feature map P is convolved with theD channel of the convolution kernel. Therefore, each channel of the input feature map (an M-dimensional feature) is convolved into a D-dimensional feature, and D is referred to as the depth multiplier [34]. As shown in Figure 3, K is a three-dimensional tensor, and each input channel is convolved into a D-dimensional feature, and the output is(3)O=∑iMKiDCinPiCin.Figure 3
Depth convolution.The deep hypercalcemia convolution is a combination of a deep convolution kernelJ and a conventional convolution K. The deep convolution kernel is first convolved with the conventional convolution kernel to form a new convolution kernel, and then, the new convolution kernel is convoluted with the feature map to obtain the final feature.(4)O=JT·K∗P.From Figure4, J and K are computed to obtain K′=JT.K, K′. Since K′ is exactly the same size as the conventional convolution kernel, the computational effort is the same as using the conventional convolution kernel. Only when D ≥ M, K′ can perform the same linear transformation as K in the conventional convolution [35]. The deep hypercalcemia convolution gives the network a kind of overparameterization, which not only increases the reasonable parameters and accelerates the training of the network but also improves the quality of extracting texture features while maintaining the original computational effort.Figure 4
Deep hyperparameterized convolution.


### 4.2. Attentional Mechanisms

In this paper, we use SAM and the SE-Block dual attention mechanism and add them to the ResNet network, which can further improve the network’s ability to extract deeper detailed features of bank notes in channel and spatial domains. Compared with the original attention mechanism of the convolutional module, the SAM and SE-Block dual attention mechanisms use a global pooling layer instead of a maximum pooling layer and an average pooling layer to compress the features, which can avoid excessive loss of parameters in the module and, thus, accomplish accurate prediction. Figure5 shows the structure of the improved attention mechanism.(5)Zc=1H×W∑i=1H∑j=1Wuci,j.Figure 5
Dual attention mechanism structure.A linear rectification function (ReLU) [36] layer is used, and a sigmoid function, which generates weights for the feature channels using the parameter w, is(6)s=σw2δw1z.The spatial attention map is obtained by a 3 × 3 standard convolutional layerf3×3:(7)Mss=σf3×3s.The new residual module is obtained by putting the improved attention mechanism in the residual module and replacing the ReLU with SELU to amplify the small changes. The structure of the residual module with the attention mechanism is shown in Figure6.Figure 6
Improved residual module.


### 4.3. Cross-Entropy Loss Function

In order to solve the problem of overconfidence, this paper performs label smoothing on the cross-entropy function.The label-smoothed cross-entropy (LSCE) loss function is formulated as(8)Lce=−∑ytruelnypred.Using label smoothing for the cross-entropy function is essentially adding a smoothing factorε. The cross-entropy function after using label smoothing is(9)L1sce=−∑1−ε∗ytrue+εN,Inypred=1−ε∑ytruelnypred−εN∑lnypred,where ytrue denotes the true result; ypred denotes the predicted result; and N is the number of bank note categories. From equation (9), it can be seen that the label smoothing makes the difference between the maximum prediction and the average of other bank note categories smoother, which can be used in the network to prevent overfitting and enhance the prediction and generalization ability of the network.In this paper, we improve the network model for the characteristics of small differences between classes of hand bank notes and many subtle features. The improved residual network structure is shown in Figure7, which has obvious advantages compared with the traditional network model. Firstly, the number of layers of the network is reduced to 8, which reduces the model parameters and the running time, and the use of DO-Conv can improve the quality of the network in extracting the texture features of hand bank notes. Finally, the cross-entropy function of label smoothing is used to solve the problem of overconfidence and effectively distinguish the images of hand bank notes with high similarity, which further improves the recognition accuracy.Figure 7
Improved residual network.


## 4.1. Deep Hyperparametric Convolution

The CNN uses convolution kernel to extract the characteristics of hand bank bills and adds an additional depth convolution to the traditional convolution layer to form a deep hypercalcemia convolution. This combination constitutes over parameterization, which increases the network reasonable parameters and improves the quality of extracting the texture characteristics of hand bank bills so that the network model is more suitable for bank bill recognition. The traditional convolution layer is shown in Figure2. In the figure, P is a two-dimensional tensor, p∈RM×Cin, where M represents the spatial dimension of the characteristic graph and Cin is the number of channels of the input characteristic graph. Convolution kernel K is a three-dimensional tensor, K∈RCout×M×Cin, of which Cout is the number of channels of the output characteristic graph, and the output after convolution operation is a Cout-dimensional characteristic graph [33].(2)O=∑iM×CinKCoutPi.Figure 2
Traditional convolution.Unlike traditional convolution, one convolution kernel is responsible for one channel in deep convolution, and a channel can only be convolved by one convolution kernel. In traditional convolution kernels, the convolution kernel of each channel is dotted with the entire feature map. In deep convolution, each input channel of the feature map P is convolved with theD channel of the convolution kernel. Therefore, each channel of the input feature map (an M-dimensional feature) is convolved into a D-dimensional feature, and D is referred to as the depth multiplier [34]. As shown in Figure 3, K is a three-dimensional tensor, and each input channel is convolved into a D-dimensional feature, and the output is(3)O=∑iMKiDCinPiCin.Figure 3
Depth convolution.The deep hypercalcemia convolution is a combination of a deep convolution kernelJ and a conventional convolution K. The deep convolution kernel is first convolved with the conventional convolution kernel to form a new convolution kernel, and then, the new convolution kernel is convoluted with the feature map to obtain the final feature.(4)O=JT·K∗P.From Figure4, J and K are computed to obtain K′=JT.K, K′. Since K′ is exactly the same size as the conventional convolution kernel, the computational effort is the same as using the conventional convolution kernel. Only when D ≥ M, K′ can perform the same linear transformation as K in the conventional convolution [35]. The deep hypercalcemia convolution gives the network a kind of overparameterization, which not only increases the reasonable parameters and accelerates the training of the network but also improves the quality of extracting texture features while maintaining the original computational effort.Figure 4
Deep hyperparameterized convolution.


## 4.2. Attentional Mechanisms

In this paper, we use SAM and the SE-Block dual attention mechanism and add them to the ResNet network, which can further improve the network’s ability to extract deeper detailed features of bank notes in channel and spatial domains. Compared with the original attention mechanism of the convolutional module, the SAM and SE-Block dual attention mechanisms use a global pooling layer instead of a maximum pooling layer and an average pooling layer to compress the features, which can avoid excessive loss of parameters in the module and, thus, accomplish accurate prediction. Figure5 shows the structure of the improved attention mechanism.(5)Zc=1H×W∑i=1H∑j=1Wuci,j.Figure 5
Dual attention mechanism structure.A linear rectification function (ReLU) [36] layer is used, and a sigmoid function, which generates weights for the feature channels using the parameter w, is(6)s=σw2δw1z.The spatial attention map is obtained by a 3 × 3 standard convolutional layerf3×3:(7)Mss=σf3×3s.The new residual module is obtained by putting the improved attention mechanism in the residual module and replacing the ReLU with SELU to amplify the small changes. The structure of the residual module with the attention mechanism is shown in Figure6.Figure 6
Improved residual module.


## 4.3. Cross-Entropy Loss Function

In order to solve the problem of overconfidence, this paper performs label smoothing on the cross-entropy function.The label-smoothed cross-entropy (LSCE) loss function is formulated as(8)Lce=−∑ytruelnypred.Using label smoothing for the cross-entropy function is essentially adding a smoothing factorε. The cross-entropy function after using label smoothing is(9)L1sce=−∑1−ε∗ytrue+εN,Inypred=1−ε∑ytruelnypred−εN∑lnypred,where ytrue denotes the true result; ypred denotes the predicted result; and N is the number of bank note categories. From equation (9), it can be seen that the label smoothing makes the difference between the maximum prediction and the average of other bank note categories smoother, which can be used in the network to prevent overfitting and enhance the prediction and generalization ability of the network.In this paper, we improve the network model for the characteristics of small differences between classes of hand bank notes and many subtle features. The improved residual network structure is shown in Figure7, which has obvious advantages compared with the traditional network model. Firstly, the number of layers of the network is reduced to 8, which reduces the model parameters and the running time, and the use of DO-Conv can improve the quality of the network in extracting the texture features of hand bank notes. Finally, the cross-entropy function of label smoothing is used to solve the problem of overconfidence and effectively distinguish the images of hand bank notes with high similarity, which further improves the recognition accuracy.Figure 7
Improved residual network.


## 5. Experiment

The experiments in this paper train and test text detection and text recognition, respectively. All experiments are conducted on an unguent 18.04 system with an 8-thread Corei7-7700k CPU @4.2 GHZ hardware configuration, 32 G of RAM, and a GTX1080ti graphics card.We use the public bank note dataset [25, 28], whose sample image is shown in Figure 8.Figure 8
Sample of different bank notes.The data used in this paper contain a total of 100 images of nearly 10 different types of business bills. The pixel size of the images varies, ranging from 1,500 × 1,000 to 2,000 × 3,000. Depending on the source of the characters in the images, the characters in the business notes can be divided into two categories: printed characters and printed characters. Printed characters include title, item area type description characters, etc.


### 5.1. Text Detection Experiment

In the process of model training, we judge the convergence speed by the length of model training and the convergence effect of the model by the final value of loss. We randomly divide the labeled 100 images into a training set and a test set by 8 : 2. The input images are scaled to a uniform size so that the long side of the image is less than or equal to 1,800 and the short side is less than or equal to 1,500 (at least one of them is equal to and maintains the aspect ratio of the original image). Our target detection model, Faster-RCNN, is fine-tuned on the training set. If the ratio of the intersection of the recognized character box and the marked rectangular box to their concatenation is greater than 0.5, the detection is considered as true.We use Average Precision (AP) as the evaluation metric in our test phase. The loss curve generated during the model training is shown in Figure9.Figure 9
Text detection training loss curve.Compared with the original anchor frame scale of Faster R-CNN, we redesigned 9 different scales of anchor frames based on the area distribution of the text in the statistical training set. The results in Table1 show that our new anchor frame scales are very effective in improving the detection effect.Table 1
Experimental results of text detection.
Anchor frame settingsRoIAPOriginal settingsRoIPooI0.66Article settingsRoIPooI0.95Article settingsRoIPAlign0.96From Table1, we can see that ROIAlign improves the AP by 8 percentage points compared with ROIPool, which shows the effectiveness of the ROIAlign feature extraction strategy in this paper.


### 5.2. Text Recognition Experiment

The dictionary contains 5,990 characters of Chinese characters, punctuation, English, and numbers (corpus word frequency statistics, full and half corner merging), and each sample is fixed at 10 characters. Each sample is fixed with 10 characters, and the characters are randomly intercepted from the sentences in the corpus, and the resolution of the images is unified at 280 × 32.The ADAM (Adaptive Moment Estimation) optimizer algorithm [37] was used with an initial learning rate of 0.001, a batch size of 256, and 100 000 iterations, and the learning rate was adjusted to 0.000 01 at the 70000th iteration.In order to better verify the performance of SRU, we conducted several sets of comparison experiments on CRNN models using SRU and LSTM, respectively. Figure10 shows the accuracy curves of different models on the validation set, and Table 2 shows the comparison of the experimental results of different models on the validation set after training. The accuracy of the 2-layer model is slightly improved, but the recognition time also increases. The experimental results show that the model using SRU can effectively reduce the recognition time without sacrificing accuracy compared to LSTM.Figure 10
Verification set recognition accuracy curve.Table 2
Experimental results on the SRU/LSTM validation set.
ModelLine recognition accuracyRecognition time of each picture/MS1st floor LSTM0.99676.871st floor LSRU0.99684.892nd floor LSTM0.99738.992nd floor SRU0.99755.73The test set for text recognition uses 236 bill images that are cut from the field part of the test set images in the text detection dataset. Table3 shows the field recognition accuracy, single-word recognition accuracy, and the average recognition time of different models on the test set. The results in Table 3 show that the use of SRU instead of LSTM can effectively reduce the recognition time without sacrificing accuracy.Table 3
Experimental results on the SRU/LSTM validation set.
ModelField recognition accuracySingle-word recognition accuracyRecognition time of each picture/MS1st floor LSTM0.92370.98027.271st floor LSRU0.92790.97885.322nd floor LSTM0.93640.98239.292nd floor SRU0.93220.98136.62


## 5.1. Text Detection Experiment

In the process of model training, we judge the convergence speed by the length of model training and the convergence effect of the model by the final value of loss. We randomly divide the labeled 100 images into a training set and a test set by 8 : 2. The input images are scaled to a uniform size so that the long side of the image is less than or equal to 1,800 and the short side is less than or equal to 1,500 (at least one of them is equal to and maintains the aspect ratio of the original image). Our target detection model, Faster-RCNN, is fine-tuned on the training set. If the ratio of the intersection of the recognized character box and the marked rectangular box to their concatenation is greater than 0.5, the detection is considered as true.We use Average Precision (AP) as the evaluation metric in our test phase. The loss curve generated during the model training is shown in Figure9.Figure 9
Text detection training loss curve.Compared with the original anchor frame scale of Faster R-CNN, we redesigned 9 different scales of anchor frames based on the area distribution of the text in the statistical training set. The results in Table1 show that our new anchor frame scales are very effective in improving the detection effect.Table 1
Experimental results of text detection.
Anchor frame settingsRoIAPOriginal settingsRoIPooI0.66Article settingsRoIPooI0.95Article settingsRoIPAlign0.96From Table1, we can see that ROIAlign improves the AP by 8 percentage points compared with ROIPool, which shows the effectiveness of the ROIAlign feature extraction strategy in this paper.


## 5.2. Text Recognition Experiment

The dictionary contains 5,990 characters of Chinese characters, punctuation, English, and numbers (corpus word frequency statistics, full and half corner merging), and each sample is fixed at 10 characters. Each sample is fixed with 10 characters, and the characters are randomly intercepted from the sentences in the corpus, and the resolution of the images is unified at 280 × 32.The ADAM (Adaptive Moment Estimation) optimizer algorithm [37] was used with an initial learning rate of 0.001, a batch size of 256, and 100 000 iterations, and the learning rate was adjusted to 0.000 01 at the 70000th iteration.In order to better verify the performance of SRU, we conducted several sets of comparison experiments on CRNN models using SRU and LSTM, respectively. Figure10 shows the accuracy curves of different models on the validation set, and Table 2 shows the comparison of the experimental results of different models on the validation set after training. The accuracy of the 2-layer model is slightly improved, but the recognition time also increases. The experimental results show that the model using SRU can effectively reduce the recognition time without sacrificing accuracy compared to LSTM.Figure 10
Verification set recognition accuracy curve.Table 2
Experimental results on the SRU/LSTM validation set.
ModelLine recognition accuracyRecognition time of each picture/MS1st floor LSTM0.99676.871st floor LSRU0.99684.892nd floor LSTM0.99738.992nd floor SRU0.99755.73The test set for text recognition uses 236 bill images that are cut from the field part of the test set images in the text detection dataset. Table3 shows the field recognition accuracy, single-word recognition accuracy, and the average recognition time of different models on the test set. The results in Table 3 show that the use of SRU instead of LSTM can effectively reduce the recognition time without sacrificing accuracy.Table 3
Experimental results on the SRU/LSTM validation set.
ModelField recognition accuracySingle-word recognition accuracyRecognition time of each picture/MS1st floor LSTM0.92370.98027.271st floor LSRU0.92790.97885.322nd floor LSTM0.93640.98239.292nd floor SRU0.93220.98136.62


## 6. Conclusions

To address the difficulties in bank note recognition, this paper improves the performance of the network by using DO-Conv instead of traditional convolution based on the ResNet network, which improves the quality of extracted features without increasing the computational complexity. Secondly, an attention mechanism is introduced to enhance the extraction of detailed features in the channel and spatial domains of banking instrument images. Finally, the cross-entropy function of label smoothing is used as the loss function to solve the overconfidence problem and improve the accuracy of classification. The experimental results show that the recognition accuracy of the improved network is 99.4919%, which is a 3.4553% improvement compared with the base network, proving the effectiveness of the improved model. In future work, we will conduct in-depth research on attack detection and software and hardware optimization.



---

*Source: 8541867-2021-12-20.xml*