An offline writer identification method and device, electronic equipment and medium
By combining sliding window local attention with global residual modeling, and using the Swing Transformer model to capture local and global features, the problem of insufficient recognition accuracy in word-level offline writer recognition is solved, and higher recognition accuracy is achieved.
Patent Information
- Application Number
- CN202411371415.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-29
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2044-09-29
AI Technical Summary
Existing offline writer recognition methods struggle to fully capture a writer's unique handwriting style at the word level, resulting in insufficient recognition accuracy.
We adopt a method based on sliding window local attention and global residual modeling. We capture local features through the window self-attention mechanism and sliding window self-attention mechanism in the Swing Transformer model, and extract global features through residual learning. We then integrate these features with the global module for deep integration.
It significantly improves the accuracy of writer recognition at the word level, forms a more robust representation of writing style, and enhances the robustness of the model.
Smart Images

Figure CN119399780B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of deep learning and pattern recognition, and in particular to an offline writer recognition method, apparatus, electronic device, and medium. Background Technology
[0002] Handwriting, as a unique behavioral biometric, is widely present in daily life, such as in handwritten signatures, personal notes, and legal documents. Each person's writing style is unique in detail, making handwriting play a crucial role in fields such as identity verification, forensic identification, and financial security. With the advent of the digital age, the application of online handwriting is becoming increasingly widespread. However, due to the existence of physical handwritten documents, offline handwriting has extensive applications. Therefore, identifying the writer of handwriting—that is, offline writer identification technology—remains an important and challenging issue.
[0003] Currently, most offline writer recognition methods focus on processing entire pages or sentences of handwriting data, achieving relatively high recognition rates. However, in word-level offline writer recognition, the limited number of effective handwriting elements on a single word image makes it difficult to fully capture the writer's unique handwriting style, thus restricting the accuracy of the recognition model. Summary of the Invention
[0004] In order to at least partially solve one of the technical problems existing in the prior art, the present invention aims to provide an offline writer recognition method, device, electronic device and medium based on sliding window local attention and global residual modeling.
[0005] The first technical solution adopted in this invention is:
[0006] An offline writer identification method includes the following steps:
[0007] Acquire handwritten word image data;
[0008] The handwritten image is converted into a grayscale image, the grayscale image is binarized, the size of the processed image is adjusted to a preset size, and a training set is constructed.
[0009] A handwriting recognition model is constructed and trained using a training set. The handwriting recognition model includes a local modeling module, an identity branch, and a global module. The local modeling module is used to capture local features, the identity branch is used to extract global features, and the global module is used to integrate local and global features.
[0010] The handwritten image to be recognized is input into the trained handwriting recognition model to obtain the results of the model's final classification layer. Softmax probability calculation is then performed, and the writer with the highest probability is taken as the recognition result.
[0011] Further, the process of converting the handwritten image into a grayscale image, binarizing the grayscale image, adjusting the size of the processed image to a preset size, and constructing a training set includes:
[0012] The handwritten image is converted to a grayscale image, and a Gaussian filter is used to remove noise from the image.
[0013] The OTSU algorithm is used to adaptively binarize the denoised image to obtain a binary handwriting image:
[0014] After adjusting the binary handwriting image to a preset size, a training set is constructed by combining it with the label data.
[0015] Furthermore, adjusting the binary handwriting image to a preset size includes:
[0016] First, scale the binary handwriting image while maintaining its original aspect ratio. Then, fill the left and right or top and bottom edges of the binary handwriting image with white pixels to achieve the preset size.
[0017] Furthermore, the local modeling module employs the window self-attention mechanism and sliding window self-attention mechanism in the Swin Transformer model to divide word handwriting into blocks and learn local style features by calculating (sliding) window self-attention between word handwriting blocks.
[0018] The identity branch directly adds the block-based input to the local features extracted by the local modeling module, and adds the global features through residuals to introduce a global writing style dependency. After the local and global features are fused, they are sent to the global module for deep integration. Finally, the integrated features are input to the classification head to classify the writer's identity to complete the recognition.
[0019] Furthermore, the local modeling module includes multiple Swing Transformer layers; each Swing Transformer layer includes multiple Swing Transformer blocks;
[0020] The Swin Transformer block includes a window multi-head self-attention mechanism, a sliding window multi-head self-attention mechanism, and a feedforward network;
[0021] In the multi-head self-attention mechanism, the input feature sequence is divided into multiple non-overlapping windows, and multi-head self-attention is calculated separately between each window. Based on this, sliding each window by half the window length results in the sliding window multi-head self-attention mechanism, which introduces connections between adjacent non-overlapping windows in the previous layer and increases the receptive field. Finally, the features are output through a feedforward network composed of multilayer perceptrons and enter the next SwingTransformer layer for further feature extraction.
[0022] Furthermore, the identity branch includes a block embedding layer, average pooling, and a fully connected layer; the block embedding layer is used to cut the entire image into blocks, then average pooling is used to compress the spatial dimension, and finally the fully connected layer is used to map the vector dimension to extract and integrate global features.
[0023] Further, the step of inputting the handwritten image to be identified into the trained handwriting recognition model, obtaining the result of the model's final classification layer, and performing softmax probability calculation, taking the writer with the highest probability as the recognition result, includes:
[0024] The handwritten image to be recognized is input into the trained handwriting recognition model. The model's classification layer outputs a vector whose dimension is equal to the number of writers in the training set. Each element corresponds to the original score of a specific writer.
[0025] The softmax probability is calculated based on the output vector, and the category with the highest probability is selected as the final recognition result, that is, the handwritten image is assigned to the writer with the highest probability.
[0026] The second technical solution adopted in this invention is:
[0027] An offline writer identification device, comprising:
[0028] The data acquisition module is used to acquire image data of handwritten words;
[0029] The image processing module is used to convert handwritten images into grayscale images, perform binarization on the grayscale images, adjust the size of the processed images to a preset size, and construct a training set.
[0030] The model building module is used to build a handwriting recognition model and train the handwriting recognition model using a training set. The handwriting recognition model includes a local modeling module, an identity branch, and a global module. The local modeling module is used to capture local features, the identity branch is used to extract global features, and the global module is used to integrate local and global features.
[0031] The handwriting recognition module is used to input the handwritten image to be recognized into the trained handwriting recognition model, obtain the result of the model's final classification layer, and perform softmax probability calculation, taking the writer with the highest probability as the recognition result.
[0032] The third technical solution adopted in this invention is:
[0033] An electronic device includes a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set, or an instruction set, and the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by the processor to implement an offline writer identification method as described above.
[0034] The fourth technical solution adopted in this invention is:
[0035] A computer-readable storage medium storing at least one instruction, at least one program, a code set, or an instruction set, wherein the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by a processor to implement an offline writer identification method as described above.
[0036] The fifth technical solution adopted in this invention is:
[0037] A computer program product or computer program includes computer instructions stored in a computer-readable storage medium. A processor of a computer device can read the computer instructions from the computer-readable storage medium and execute the computer instructions, causing the computer device to perform the aforementioned offline writer identification method.
[0038] The beneficial effects of this invention are as follows: In the handwriting recognition model of this invention, the local modeling module meticulously captures the local dependencies between letter strokes through a (sliding) window multi-head self-attention mechanism, while the identity branch extracts global features through global average pooling and fully connected layers. The global module integrates local and global features to form a more robust handwriting style representation, effectively extracting robust feature representations from a limited number of handwriting strokes, achieving recognition accuracy far exceeding that of other methods. Furthermore, this invention is the first in the field to utilize sliding window local attention and comprehensively model local and global handwriting style features, providing new ideas for subsequent work in the field. Attached Figure Description
[0039] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following description is provided with accompanying drawings of the relevant technical solutions in the embodiments of the present invention or the prior art. It should be understood that the accompanying drawings described below are only for the purpose of clearly illustrating some embodiments of the technical solutions of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0040] Figure 1 This is a flowchart illustrating the steps of an offline writer identification method according to an embodiment of the present invention;
[0041] Figure 2 This is a schematic diagram of the handwriting recognition model in an embodiment of the present invention. Detailed Implementation
[0042] The embodiments of the present invention are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention. The step numbers in the following embodiments are set only for ease of explanation, and there is no limitation on the order between the steps. The execution order of each step in the embodiments can be adaptively adjusted according to the understanding of those skilled in the art.
[0043] In the description of this invention, it should be understood that the orientation descriptions, such as up, down, front, back, left, right, etc., are based on the orientation or positional relationship shown in the accompanying drawings. They are only for the convenience of describing this invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limiting this invention.
[0044] In the description of this invention, "several" means one or more, "more than" means two or more, "greater than," "less than," and "exceeding" are understood to exclude the stated number, while "above," "below," and "within" are understood to include the stated number. The use of "first" and "second" in the description is merely for distinguishing technical features and should not be construed as indicating or implying relative importance, or implicitly indicating the number of indicated technical features, or implicitly indicating the order of the indicated technical features.
[0045] In the description of this invention, unless otherwise explicitly defined, terms such as "set up," "install," and "connect" should be interpreted broadly, and those skilled in the art can reasonably determine the specific meaning of the above terms in this invention in conjunction with the specific content of the technical solution.
[0046] To address existing technical problems and improve the performance of word-level offline handwriting recognition, this invention proposes a classifier based on residual sliding window self-attention. This method innovatively combines the ideas of the Swing Transformer, using sliding window attention to mine local handwriting features, and incorporating residual learning to extract global features. Through joint modeling of local and global features, this method can extract robust feature representations with a limited amount of handwriting, significantly improving recognition accuracy.
[0047] Example 1
[0048] like Figure 1 As shown, this embodiment provides an offline writer identification method, including the following steps:
[0049] S1. Obtain handwritten word image data;
[0050] S2. Convert the handwritten image into a grayscale image, perform binarization on the grayscale image, adjust the size of the processed image to a preset size, and construct a training set.
[0051] S3. Construct a handwriting recognition model and train it using a training set. The handwriting recognition model includes a local modeling module, an identity branch, and a global module. The local modeling module is used to capture local features, the identity branch is used to extract global features, and the global module is used to integrate local and global features.
[0052] S4. Input the handwritten image to be recognized into the trained handwriting recognition model, obtain the result of the final classification layer of the model, and perform softmax probability calculation. Take the writer with the highest probability as the recognition result.
[0053] This embodiment uses sliding window self-attention to learn local features and input-output residuals to learn global features. By combining local and global features in joint modeling, it effectively enhances the representation ability of the handwriting style of the handwriter, thereby improving the accuracy of recognition.
[0054] The above method will be explained in detail below with reference to the accompanying drawings and specific embodiments.
[0055] This embodiment provides an offline writer recognition method based on sliding window local attention and global residual modeling, including the following steps:
[0056] Step 1, Data Preparation: Obtain handwritten word image data.
[0057] Specifically, handwritten word images can be obtained from several publicly available offline handwriting datasets.
[0058] Step 2, Data Preprocessing: Convert the handwritten image into a grayscale image, remove noise using a Gaussian filter, and perform binarization using the OTSU algorithm. Then, adjust the image size to a fixed value.
[0059] In some embodiments, step S2 specifically includes the following steps:
[0060] Step 2.1: Convert the handwritten image into a binary image.
[0061] Step 2.2: Use a Gaussian filter with a kernel size of 3×3 to remove smaller noise points in the handwriting image, making it smoother.
[0062] Step 2.3: Use the OTSU algorithm to perform adaptive binarization processing on the handwriting image to obtain a binary handwriting image.
[0063] Step 2.4: Standardize image size. First, maintain the original aspect ratio of the image while scaling it. Then, fill the left and right or top and bottom edges of the image with white pixels to achieve the specified size.
[0064] Step 3, Model Training: Input the processed handwritten image into the handwriting recognition model. The model includes a local modeling module for capturing local features, an identity branch for extracting global features, and a global module for integrating local and global features.
[0065] In some embodiments, see Figure 2 The handwriting recognition model comprises a local modeling module, an identity branch, and a global module. The local modeling module employs the window self-attention and sliding window self-attention mechanisms from the Swin Transformer model, learning local style features by calculating (sliding) window self-attention between word handwriting blocks. The identity branch directly adds the block-based input to the local features extracted by the local modeling module, and sums the global features using residuals, introducing a global handwriting style dependency. After the local and global features are summed, they are fed into the global module for deep modeling. Finally, the features are input to a classification head to classify the writer's identity, thus completing the recognition process.
[0066] As one implementation, the structure of the local modeling module is shown in Table 1, and Table 2 lists the structure of the Swin Transformer block in its SwinTransformer layer.
[0067] Table 1 Structure of the Local Modeling Module
[0068] Network layer Specific operations Output size enter Input Channel 1 192×96×1 Block embedding Embedding dimension 96, block size 4 1152×96 Swin Transformer layer 2 Swing Transformer blocks 48×24×96 Swin Transformer layer 2 Swing Transformer blocks 48×24×192 Swin Transformer layer 6 Swing Transformer blocks 24×12×384 Swin Transformer layer 2 Swing Transformer blocks 12×6×768
[0069] Table 2. Structure of the Swing Transformer block
[0070]
[0071] The local modeling module comprises multiple Swing Transformer layers, each containing multiple Swing Transformer blocks. Taking one Swing Transformer layer as an example, it first halves the length of image features and doubles the feature dimension through block fusion. Each Swing Transformer block consists of window multi-head self-attention, sliding window multi-head self-attention, and a feedforward network. Both mechanisms utilize the multi-head self-attention mechanism proposed by Transformers, weighting features based on autocorrelation similarity to adaptively enhance highly discriminative parts and weaken less informative parts. In the window multi-head self-attention mechanism, the input feature sequence is divided into multiple non-overlapping windows, and multi-head self-attention is calculated separately for each window. Sliding each window by half a window length yields the sliding window self-attention mechanism, introducing connections between adjacent non-overlapping windows in the previous layer and increasing the receptive field. These two methods reduce the computational cost of attention calculation because the attention mechanism only considers a pair of windows, rather than the entire sequence, while effectively focusing on local features. Finally, the features are passed through a feedforward network composed of multilayer perceptrons to become the output, and then enter the next Swin Transformer layer to further extract features.
[0072] After extraction through multiple Swing Transformer layers, the model effectively extracts local features from word images and feeds these features into the next part of the network for processing. The final feature shape output by the local modeling module is 1×768.
[0073] As one implementation, the identity branch uses a block embedding layer to segment the entire image into blocks, then performs average pooling to compress the spatial dimensions, and finally uses a fully connected layer to map the 256-dimensional vector to 768 dimensions. The structure of the identity branch is shown in Table 3:
[0074] Table 3 Structure of the identity branches
[0075] Network layer Specific operations Output size enter - 192×96×1 Block embedding Embedding dimension 256, block size 4 1152×256 Average pooling - 1×256 Fully connected layer 256 input channels, 768 output channels 1×768
[0076] In one implementation, after extracting local and global features, the model adds and fuses the two features, and then inputs the fused features into the global module for deep feature extraction. Finally, these extracted features are fed into the classification layer to output the final result of writer recognition. The structure of the global module is shown in Table 4:
[0077] Table 4 Structure of the Global Module
[0078]
[0079] As an optional implementation, the handwriting recognition model uses cross-entropy as a loss function during training to optimize the writer recognition results and updates the model parameters through gradient backpropagation.
[0080] The training parameters are as follows:
[0081] 1) Number of iterations: 100; Number of iterations per generation: 245;
[0082] 2) Optimizer: AdamW; Learning rate: 0.0001; Weight decay: 0.00001.
[0083] As an alternative implementation, to further improve the performance of the model, the handwriting recognition model is first pre-trained using a word recognition task, and then the pre-trained weights are used as a basis for further training on a writer recognition task.
[0084] Step 4, Model Inference: Input the handwritten image to be recognized into the model, obtain the results of the final classification layer of the model, and perform softmax probability calculation. Take the writer with the highest probability as the recognition result.
[0085] The handwritten image to be recognized is input into the model. The last layer (classification layer) of the handwriting recognition model outputs a vector with a dimension equal to the number of writers in the training set. Each element corresponds to the raw score of a specific writer. To convert these raw scores into an interpretable probability distribution, we apply the softmax function to the output vector. The softmax function converts the raw scores into probability values ranging from 0 to 1, preserving the relative magnitudes of the scores while ensuring that the sum of the probabilities of all categories (i.e., writers) equals 1. In this probability distribution, each element represents the probability that the input handwritten image belongs to the corresponding writer. Finally, we select the category with the highest probability as the final recognition result, that is, assigning the handwritten image to the writer with the highest probability.
[0086] In summary, the method of the present invention has at least the following advantages and beneficial effects compared with the prior art:
[0087] (1) This invention proposes a residual sliding window self-attention classifier for word-level offline writer recognition, especially for enhancing writer recognition under conditions of limited handwriting data. Compared with traditional convolutional neural network (CNN) or recurrent neural network (RNN) methods, this invention can more effectively combine local and global features, significantly improve recognition accuracy, and show significant performance advantages on word-level handwritten data.
[0088] (2) This invention innovatively introduces a local modeling module to capture local handwriting features. This module effectively models the relationship between adjacent strokes through the (sliding) window multi-head self-attention mechanism of SwinTransformer, overcoming the limitations of traditional CNNs in handling sparse connections and enhancing the model's ability to finely model local writing style features.
[0089] (3) This invention proposes an identity branch and a global module for extracting and integrating global features. The identity branch encodes the entire image through global average pooling and fully connected layers to obtain global handwriting style features; the global module deeply integrates local and global features to form a more robust feature representation.
[0090] (4) This invention utilizes pre-training technology to effectively transfer relevant knowledge to the writer recognition task by pre-training the model on the word recognition task. This method significantly improves the model's performance on the target task, especially when dealing with limited data.
[0091] Example 2
[0092] This embodiment provides an offline writer recognition device, including:
[0093] The data acquisition module is used to acquire image data of handwritten words;
[0094] The image processing module is used to convert handwritten images into grayscale images, perform binarization on the grayscale images, adjust the size of the processed images to a preset size, and construct a training set.
[0095] The model building module is used to build a handwriting recognition model and train the handwriting recognition model using a training set. The handwriting recognition model includes a local modeling module, an identity branch, and a global module. The local modeling module is used to capture local features, the identity branch is used to extract global features, and the global module is used to integrate local and global features.
[0096] The handwriting recognition module is used to input the handwritten image to be recognized into the trained handwriting recognition model, obtain the result of the model's final classification layer, and perform softmax probability calculation, taking the writer with the highest probability as the recognition result.
[0097] Since this device is an offline writer identification device according to an embodiment of the present invention, and the principle by which this device solves the problem is similar to... Figure 1 The methods shown are similar, so the implementation of this device can refer to the implementation process of the above method embodiments, and repeated parts will not be described again.
[0098] Example 3
[0099] This invention also provides an electronic device, which includes a processor and a memory. The memory stores at least one instruction, at least one program, a code set, or an instruction set. The at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by the processor to achieve the following: Figure 1 This illustrates an offline writer identification method.
[0100] It is understood that the memory may include random access memory (RAM) or read-only memory. Optionally, the memory may include non-transitory computer-readable storage medium. The memory can be used to store instructions, programs, code, code sets, or instruction sets. The memory may include a stored program area and a stored data area, wherein the stored program area may store instructions for implementing an operating system, instructions for at least one function, instructions for implementing the various method embodiments described above, etc.; the stored data area may store data created according to the use of the server, etc.
[0101] A processor may include one or more processing cores. The processor connects to various parts of the server via various interfaces and lines, executing instructions, programs, code sets, or instruction sets stored in memory, and accessing data stored in memory to perform various server functions and process data. Optionally, the processor may be implemented using at least one of the following hardware forms: Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), and Programmable Logic Array (PLA). The processor may integrate one or more of the following: Central Processing Unit (CPU) and Modem. The CPU primarily handles the operating system and applications; the modem handles wireless communication. It is understood that the modem may also be implemented as a separate chip without being integrated into the processor.
[0102] Since this electronic device is an electronic device corresponding to an offline writer identification method in an embodiment of the present invention, and the principle of solving the problem by this electronic device is similar to that of this method, the implementation of this electronic device can refer to the implementation process of the above method embodiment, and repeated parts will not be described again.
[0103] Example 4
[0104] This invention also provides a computer-readable storage medium storing at least one instruction, at least one program, a code set, or an instruction set, wherein the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by a processor to achieve the following: Figure 1 This illustrates an offline writer identification method.
[0105] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, including read-only memory (ROM), random access memory (RAM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), one-time programmable read-only memory (OTPROM), electrically-Erasable Programmable Read-Only Memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, disk storage, magnetic tape storage, or any other computer-readable medium capable of carrying or storing data.
[0106] Since this storage medium is the storage medium corresponding to an offline writer identification method in an embodiment of the present invention, and the principle of the storage medium in solving the problem is similar to that of the method, the implementation of this storage medium can refer to the implementation process of the above method embodiment, and repeated parts will not be described again.
[0107] Example 5
[0108] In some possible implementations, various aspects of the methods of the embodiments of the present invention can also be implemented as a program product comprising program code that, when run on a computer device, causes the computer device to perform the steps of an offline writer identification method according to various exemplary embodiments of this application as described above. The executable computer program code or "code" for performing the various embodiments can be written in high-level programming languages such as C, C++, C#, Smalltalk, Java, JavaScript, Visual Basic, Structured Query Language (e.g., Transact-SQL), Perl, or in various other programming languages.
[0109] It should be understood that various parts of the present invention can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0110] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the present invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.
[0111] The above embodiments are merely illustrative of the technical concept and features of the present invention, and are intended to enable those skilled in the art to understand the content of the present invention and implement it accordingly. They should not be construed as limiting the scope of protection of the present invention. All equivalent changes or modifications made based on the essence of the content of the present invention should be covered within the scope of protection of the present invention.
Claims
1. An offline writer identification method, characterized in that, Includes the following steps: Acquire handwritten word image data; The handwritten image is converted into a grayscale image, the grayscale image is binarized, the size of the processed image is adjusted to a preset size, and a training set is constructed. A handwriting recognition model is constructed and trained using a training set. The handwriting recognition model includes a local modeling module, an identity branch, and a global module. The local modeling module is used to capture local features, the identity branch is used to extract global features, and the global module is used to integrate local and global features. The handwritten image to be identified is input into the trained handwriting recognition model to obtain the results of the model's final classification layer, and softmax probability calculation is performed. The writer with the highest probability is taken as the recognition result. The local modeling module employs the window self-attention mechanism and sliding window self-attention mechanism in the Swing Transformer model to divide word handwriting into blocks and learn local style features by calculating window self-attention between word handwriting blocks. The identity branch directly adds the block-based input to the local features extracted by the local modeling module, and adds the global features through residuals to introduce global writing style dependency; after the local and global features are fused, they are sent to the global module for deep integration; finally, the integrated features are input to the classification head to classify the writer's identity to complete the recognition. The local modeling module includes multiple Swin Transformer layers; each Swin Transformer layer includes multiple Swin Transformer blocks. The Swin Transformer block includes a window multi-head self-attention mechanism, a sliding window multi-head self-attention mechanism, and a feedforward network; In the multi-head self-attention mechanism, the input feature sequence is divided into multiple non-overlapping windows, and multi-head self-attention is calculated separately between each window. Based on this, sliding each window by half the window length results in the sliding window multi-head self-attention mechanism, which introduces connections between adjacent non-overlapping windows in the previous layer and increases the receptive field. Finally, the features are passed through a feedforward network composed of multilayer perceptrons to become the output, which enters the next Swing Transformer layer for further feature extraction. The identity branch includes a block embedding layer, average pooling, and a fully connected layer. The block embedding layer is used to cut the entire image into blocks, then average pooling is used to compress the spatial dimension, and finally the fully connected layer is used to map the vector dimension to extract and integrate global features.
2. The offline writer identification method according to claim 1, characterized in that, The process of converting the handwritten image to a grayscale image, binarizing the grayscale image, adjusting the size of the processed image to a preset size, and constructing a training set includes: The handwritten image is converted to a grayscale image, and a Gaussian filter is used to remove noise from the image. The OTSU algorithm is used to adaptively binarize the denoised image to obtain a binary handwriting image: After adjusting the binary handwriting image to a preset size, a training set is constructed by combining it with the label data.
3. The offline writer identification method according to claim 2, characterized in that, The step of adjusting the binary handwriting image to a preset size includes: First, scale the binary handwriting image while maintaining its original aspect ratio. Then, fill the left and right or top and bottom edges of the binary handwriting image with white pixels to achieve the preset size.
4. The offline writer identification method according to claim 1, characterized in that, The process of inputting the handwritten image to be identified into the trained handwriting recognition model, obtaining the results of the model's final classification layer, and performing softmax probability calculation, taking the writer with the highest probability as the recognition result, includes: The handwritten image to be recognized is input into the trained handwriting recognition model. The model's classification layer outputs a vector whose dimension is equal to the number of writers in the training set. Each element corresponds to the original score of a specific writer. The softmax probability is calculated based on the output vector, and the category with the highest probability is selected as the final recognition result, that is, the handwritten image is assigned to the writer with the highest probability.
5. An offline writer identification device, characterized in that, include: The data acquisition module is used to acquire image data of handwritten words; The image processing module is used to convert handwritten images into grayscale images, perform binarization on the grayscale images, adjust the size of the processed images to a preset size, and construct a training set. The model building module is used to build a handwriting recognition model and train the handwriting recognition model using a training set. The handwriting recognition model includes a local modeling module, an identity branch, and a global module. The local modeling module is used to capture local features, the identity branch is used to extract global features, and the global module is used to integrate local and global features. The handwriting recognition module is used to input the handwritten image to be recognized into the trained handwriting recognition model, obtain the result of the model's final classification layer, and perform softmax probability calculation, taking the writer with the highest probability as the recognition result. The local modeling module employs the window self-attention mechanism and sliding window self-attention mechanism in the Swing Transformer model to divide word handwriting into blocks and learn local style features by calculating window self-attention between word handwriting blocks. The identity branch directly adds the block-based input to the local features extracted by the local modeling module, and adds the global features through residuals to introduce global writing style dependency; after the local and global features are fused, they are sent to the global module for deep integration; finally, the integrated features are input to the classification head to classify the writer's identity to complete the recognition. The local modeling module includes multiple Swin Transformer layers; each Swin Transformer layer includes multiple Swin Transformer blocks. The Swin Transformer block includes a window multi-head self-attention mechanism, a sliding window multi-head self-attention mechanism, and a feedforward network; In the multi-head self-attention mechanism, the input feature sequence is divided into multiple non-overlapping windows, and multi-head self-attention is calculated separately between each window. Based on this, sliding each window by half the window length results in the sliding window multi-head self-attention mechanism, which introduces connections between adjacent non-overlapping windows in the previous layer and increases the receptive field. Finally, the features are passed through a feedforward network composed of multilayer perceptrons to become the output, which enters the next Swing Transformer layer for further feature extraction. The identity branch includes a block embedding layer, average pooling, and a fully connected layer. The block embedding layer is used to cut the entire image into blocks, then average pooling is used to compress the spatial dimension, and finally the fully connected layer is used to map the vector dimension to extract and integrate global features.
6. An electronic device, characterized in that, The electronic device includes a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set, or an instruction set, and the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by the processor to implement the method as described in any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that, The storage medium stores at least one instruction, at least one program, code set, or instruction set, wherein the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by a processor to implement the method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Cross-modal character handwriting verification method, system and equipment and storage medium
CN115620312A
Target detection method and system based on Transform and fusion attention mechanism
CN115908772A