A method, device, computer equipment and storage medium for generating image samples
By combining character filters and generative adversarial networks, handwritten sample text images are generated, which solves the problem of insufficient diversity of training data in traditional methods and improves sample authenticity and the training effect of deep learning networks.
Patent Information
- Application Number
- CN202111015851.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-31
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2041-08-31
AI Technical Summary
The traditional handwriting picture sample generation method has the problem of insufficient diversity of training data, resulting in weak authenticity of the generated samples and the inability to effectively enrich the training data of the deep learning network.
Character filters are used to extract character features of original handwritten text images, and through the trained generative adversarial network generator and discriminator, combined with the authenticity classifier, relatively smooth sample text images are generated to increase the diversity of training data.
The generated sample text images are more realistic and have diverse styles, which effectively improves the diversity of training data and enhances the training effect of the deep learning network.
Smart Images

Figure CN113688927B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology in artificial intelligence, and in particular to a method, device, computer equipment and storage medium for generating image samples for handwriting. Background Art
[0002] Calligraphy is a unique form of artistic expression of the beauty of Chinese characters in China and neighboring countries and regions that have been deeply influenced by Chinese culture. It is also a traditional art unique to Chinese characters. Handwriting is a type of text written purely by hand using a hard or soft pen. Handwriting represents the essence of Chinese character culture. Therefore, applying deep learning networks to handwriting text processing technology has become a focus of attention. However, since deep neural networks have very strong learning capabilities, when there is no large amount of training data, it will cause overfitting, and the trained model is difficult to apply.
[0003] There is currently a method for generating image samples for handwriting, which involves performing affine transformations such as rotation and shifting on handwritten text images, or using mirror transformation and other methods to obtain image samples suitable for handwriting deep learning networks.
[0004] However, the applicant found that traditional methods for generating image samples for handwriting are generally not intelligent. Since the handwriting image samples generated by simply editing and transforming the images have weak authenticity and cannot enrich the diversity of training data, it can be seen that traditional methods for generating image samples for handwriting have the problem of insufficient diversity of training data. Summary of the invention
[0005] The purpose of the embodiments of the present application is to provide a method, device, computer equipment and storage medium for generating image samples applied to handwriting, so as to solve the problem of insufficient diversity of training data in traditional methods for generating image samples applied to handwriting.
[0006] In order to solve the above technical problems, the embodiment of the present application provides a method for generating image samples for handwriting, which adopts the following technical solution:
[0007] Receiving a sample generation request carrying an original handwritten text image;
[0008] Performing a character feature extraction operation on the original handwritten text image according to a character filter to obtain original character features;
[0009] Performing an adjacent feature extraction operation on the original handwritten text image according to the trained recognition module to obtain original adjacent features;
[0010] A sample text image corresponding to the original character features is generated according to a generator of a trained generative adversarial network, wherein a discriminator of the generative adversarial network is formed by splicing a true-false classifier according to the original adjacent features;
[0011] The sample text image is output.
[0012] In order to solve the above technical problems, the embodiment of the present application further provides a device for generating image samples for handwriting, which adopts the following technical solution:
[0013] A request receiving module, used for receiving a sample generation request carrying an original handwritten text image;
[0014] A character feature extraction module, used for performing a character feature extraction operation on the original handwritten text image according to a character filter to obtain original character features;
[0015] An adjacent feature extraction module is used to perform an adjacent feature extraction operation on the original handwritten text image according to the trained recognition module to obtain original adjacent features;
[0016] A sample generation module, used to generate a sample text image corresponding to the original character features according to a trained generator of a generative adversarial network, wherein the discriminator of the generative adversarial network is formed by splicing the true and false classifiers according to the original adjacent features;
[0017] The sample output module is used to output the sample text image.
[0018] In order to solve the above technical problems, the embodiment of the present application further provides a computer device, which adopts the following technical solution:
[0019] The invention comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the above-mentioned method for generating a picture sample applied to handwriting when executing the computer-readable instructions.
[0020] In order to solve the above technical problems, the embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solution:
[0021] The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the method for generating a picture sample applied to handwriting as described above are implemented.
[0022] Compared with the prior art, the embodiments of the present application have the following beneficial effects:
[0023] The present application provides a method for generating image samples for handwriting, including: receiving a sample generation request carrying an original handwritten text image; performing a character feature extraction operation on the original handwritten text image according to a character filter to obtain the original character feature; performing an adjacent feature extraction operation on the original handwritten text image according to a trained recognition module to obtain the original adjacent feature; generating a sample text image corresponding to the original character feature according to a generator of a trained generative adversarial network, wherein the discriminator of the generative adversarial network is spliced by a true and false classifier according to the original adjacent feature; and outputting the sample text image. When constructing a generative adversarial network, the present application splices the true and false classifier in the discriminator according to the original adjacent features interacting in the overlapping area between characters of the original handwritten text image, so that the trained generative adversarial network can generate a relatively smooth text image, and finally generates a sample text image corresponding to the original character feature according to the generator of the trained generative adversarial network, so that the generated sample text image is more realistic and diverse in style, thereby effectively increasing the diversity of training data. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the scheme in the present application, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0025] Figure 1 is a flowchart of the implementation of the method for generating a picture sample applied to handwriting provided in the first embodiment of the present application;
[0026] Figure 2 yes Figure 1 A flowchart of a specific implementation of step S102;
[0027] Figure 3 is a schematic diagram of the structure of the identifier provided in Example 1 of the present application;
[0028] Figure 4 yes Figure 1 A flowchart of a specific implementation of step S104;
[0029] Figure 5 is a schematic diagram of the structure of a device for generating a picture sample applied to handwriting provided in Embodiment 2 of the present application;
[0030] Figure 6 It is a structural schematic diagram of another device for generating image samples for handwriting provided in the second embodiment of the present application;
[0031] Figure 7It is a structural diagram of an embodiment of a computer device according to the present application. DETAILED DESCRIPTION
[0032] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0033] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0034] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.
[0035] like Figure 1 As shown, a flowchart of the implementation of the method for generating image samples applied to handwriting provided in the first embodiment of the present application is shown. For the sake of convenience of explanation, only the parts related to the present application are shown.
[0036] The above-mentioned method for generating a picture sample applied to handwriting includes the following steps:
[0037] Step S101: receiving a sample generation request carrying an original handwritten text image.
[0038] In the embodiments of the present application, the original handwritten text image refers to the handwritten text input by the user. The handwritten text may be obtained by photographing the corresponding handwritten text with a camera device to obtain the corresponding original handwritten text image; the handwritten text may also be obtained by collecting the user's input information through a handwriting board to obtain the corresponding original handwritten text image. It should be understood that the example of obtaining the original handwritten text image here is only for the convenience of understanding and is not used to limit the present application.
[0039] In an embodiment of the present application, the sample generation request can be a request information sent by a requesting terminal, or a user can directly input the above-mentioned original handwritten text image as the sample generation request, wherein the requesting terminal can be a mobile terminal such as a mobile phone, a smart phone, a laptop computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a navigation device, etc., and a fixed terminal such as a digital TV, a desktop computer, etc. It should be understood that the examples of the requesting terminal here are only for convenience of understanding and are not used to limit the present application.
[0040] Step S102: performing a character feature extraction operation on the original handwritten text image according to the character filter to obtain original character features.
[0041] In an embodiment of the present application, the character filter is mainly used to filter out those parts of the original handwritten text image where the text features are not obvious, while retaining those parts where the text features are more obvious (such as edges, angles, shapes, etc.). Specifically, the size of the character filter is 32×8192.
[0042] In an embodiment of the present application, the character feature extraction operation may be to scale the original handwritten text image to a height of 32 pixels according to the original aspect ratio to obtain the original character features.
[0043] Step S103: performing an adjacent feature extraction operation on the original handwritten text image according to the trained recognition module to obtain original adjacent features.
[0044] In an embodiment of the present application, the trained recognition model is obtained based on the CNN (Convolutional Neural Network) part in the CRNN (Convolutional Recurrent Neural Network) structure. The present application utilizes the overlapping property of CNN receptive fields to explain the influence of neighboring characters. This overlapping area allows adjacent characters to interact with each other, so that when a sample text image is subsequently generated, a more realistic sample text image corresponding to the original handwritten text can be generated.
[0045] In an embodiment of the present application, before obtaining a trained recognition model, sample data is first constructed. The sample data includes pixel area features of the gaps between texts in different text images. The pixel area features and the corresponding text images are used as a feature information group, and the original untrained recognition model is trained based on the feature information group. When the recognition model completes the training of all sample data, the above-mentioned trained recognition model is obtained.
[0046] In the embodiments of the present application, most recognition networks use a recurrent module (LSTM module), which uses the information of previous and subsequent image segments, that is, contextual information, to improve the accuracy of text recognition. However, in the present application, since the focus of the present application is not on text recognition, but on generating a sample text image similar to the style of the handwritten text based on the input handwritten text, and with an LSTM module, the training speed will be reduced; therefore, we only retain the CNN part in the CRNN structure.
[0047] In the embodiment of the present application, the adjacent feature extraction operation is to obtain the original adjacent feature data by extracting the overlapping area of adjacent characters.
[0048] Step S104: Generate a sample text image corresponding to the original character features according to the trained generator of the generative adversarial network, and the discriminator of the generative adversarial network is spliced by the true and false classifiers according to the original adjacent features.
[0049] In the embodiment of the present application, the generative adversarial network (GAN) refers to a network composed of two competing neural networks, namely the generator and the discriminator, based on the concept of adversarial training. Among them, the generator or generative model attempts to capture the data distribution, and the discriminator or discriminant model estimates the probability that the sample comes from the training data instead of G. That is, the generator tries to create the same sample as the training set and the discriminator tries to distinguish what the generator is creating from the original sample in the training set.
[0050] In an embodiment of the present application, when training a generative adversarial network, already labeled "text picture-text annotation" training samples can be obtained from the system database, and all of the "text picture-text annotation" training samples can be input into a preset generative adversarial network for training to obtain the above-mentioned trained generative adversarial network.
[0051] In the embodiment of the present application, the receptive field width of the generator is set to 16 pixels. The generator can be regarded as a splicing of conditional generators of different classes, each class represents a character in the dictionary, and each generator generates a new segment containing its input character.
[0052] In an embodiment of the present application, the discriminator is composed of different true and false classifiers, which have overlapping receptive fields (i.e., the original adjacent features mentioned above), and the scores of all classifiers are aggregated into the final discriminator output through a pooling layer. Because the model does not rely on character-level annotations, there is no need to use class supervision for each classifier. One advantage of this is that unlabeled images can be used to train the discriminator, and even other data corpora that the model has not seen can be used.
[0053] In an embodiment of the present application, since the above-mentioned adjacent feature extraction operation has obtained the original adjacent features used to connect the context, when constructing the discriminator, the classifier corresponding to the above-mentioned original handwritten text can be first obtained, and then spliced according to the original adjacent features to obtain the discriminator corresponding to the above-mentioned original handwritten text image.
[0054] In an embodiment of the present application, the method for generating the above-mentioned sample text image may be to obtain the above-mentioned character filter corresponding to the number of characters of the above-mentioned original handwritten text image; splicing the above-mentioned character filters, and multiplying the spliced character filters with the noise vector to obtain a noise matrix; deforming the above-mentioned noise matrix to obtain a deformation matrix; inputting the above-mentioned deformation matrix into the residual block of the generator of the above-mentioned generative adversarial network for upsampling operation, thereby obtaining the above-mentioned sample text image.
[0055] Step S105: Output the sample text image.
[0056] In an embodiment of the present application, a method for generating a picture sample applied to handwriting is provided, including: receiving a sample generation request carrying an original handwritten text image; performing a character feature extraction operation on the original handwritten text image according to a character filter to obtain the original character feature; performing an adjacent feature extraction operation on the original handwritten text image according to a trained recognition module to obtain the original adjacent feature; generating a sample text image corresponding to the original character feature according to a generator of a trained generative adversarial network, wherein the discriminator of the generative adversarial network is spliced by a true-false classifier according to the original adjacent features; and outputting a sample text image. When constructing a generative adversarial network, the present application splices the true-false classifier in the discriminator according to the original adjacent features interacting with each other in the overlapping area between characters of the original handwritten text image, so that the trained generative adversarial network can generate a relatively smooth text image, and finally generates a sample text image corresponding to the original character feature according to the generator of the trained generative adversarial network, so that the generated sample text image is more realistic and diverse in style, thereby effectively increasing the diversity of training data.
[0057] Continue reading Figure 2 , showing Figure 1A flowchart of a specific implementation of step S102 is shown in FIG. 1 . For ease of explanation, only the part related to the present application is shown.
[0058] In some optional implementations of this embodiment, step S102 specifically includes: step S201.
[0059] Step S201: scaling the original handwritten text image to a height of 32 pixels according to the original aspect ratio to obtain original character features.
[0060] In an embodiment of the present application, the above-mentioned original handwritten text image is scaled to a height of 32 pixels while maintaining the aspect ratio of the original image to obtain original character features with more obvious text features, wherein the original handwritten text image is scaled to 32 pixels while maintaining the aspect ratio, so as to minimize the destruction of text details in the image (of course, the input image can also be scaled to a fixed width, but this will definitely cause performance degradation due to the destruction of the shape of the text).
[0061] In some optional implementations of this embodiment, the discriminator consists of 4 residual blocks and one fully connected layer, and is obtained through supervised training based on the maximum margin loss.
[0062] In the embodiment of the present application, the structure of the discriminator is inspired by the BiGAN (Bidirectional GAN) structure, and the discriminator is designed to learn meaningful feature representations. Figure 3 In the original GAN, D receives samples as input and uses the learned intermediate representation as the feature representation of the relevant task without any additional mechanism. It is not very clear about the semantically meaningful features of generated data and real data. In fact, when G generates real data, D will completely ignore the generated data and unconditionally predict p=1 / 2, and will not learn any meaningful intermediate representation. BiGAN hopes to make GAN learn meaningful representations.
[0063] In some optional implementations of this embodiment, the trained recognition module is obtained by supervised training based on CTC loss.
[0064] In the embodiments of the present application, the full name of CTC is Connectionist Temporal Classification. This method mainly solves the problem of misalignment between the neural network label and output (Alignment problem). This problem often occurs in applications such as scene text recognition, speech recognition, and handwriting recognition. For example, the speech recognition in Fig. 1 will recognize many ww and many r. If no processing is done, it will become wworrrlld. I ignored the blank. A simple and crude method is to treat all repeated letters as one letter. However, this will result in the failure to recognize words such as happy. At this time, the role of blank is very important. Here it separates the same letter, such as happy, which will become hhh aaaa ppp ppp yyyy-->happy.
[0065] In the embodiment of the present application, the CTC calculation includes a softmax output layer, and there is also an additional label (blank). The probability calculation of a path is as follows:
[0066]
[0067] Among them, x is the input data, y is the output data, both are sequences; L is the label of the sequence label, L` is the sequence label + blank. The above formula explains that given an input, the probability of each time point from time t=1 to T is multiplied, and finally the probability of the corresponding path is obtained.
[0068] Continue reading Figure 4 , showing Figure 1 A flowchart of a specific implementation of step S104 is shown in FIG. 1 . For ease of explanation, only the part related to the present application is shown.
[0069] In some optional implementations of this embodiment, step S104 specifically includes: step S401, step S402, step S403 and step S404.
[0070] Step S401: Obtain a character filter corresponding to the number of characters in the original handwritten text image.
[0071] In the embodiment of the present application, since the focus of the present application is to generate a handwritten text image with a style similar to the input text based on the input handwritten text, in order to generate a number of characters corresponding to the number of characters n in the original handwritten text image, the generative adversarial network needs to obtain character filters corresponding to the number of characters to generate a corresponding number of handwritten text images.
[0072] Step S402: concatenate character filters, and multiply the concatenated character filters with the noise vector to obtain a noise matrix.
[0073] In an embodiment of the present application, after the generative adversarial network completes splicing the character filter, it multiplies the character filter with a 32-dimensional noise vector z to obtain an n×8192 matrix, namely the above-mentioned noise matrix.
[0074] Step S403: deform the noise matrix to obtain a deformed matrix.
[0075] In the embodiment of the present application, deforming the noise matrix refers to deforming the above-mentioned n×8192 noise matrix into a 512×4×4n matrix, that is, the above-mentioned deformed matrix, and the size of each character in the deformed matrix is 4×4.
[0076] Step S404: input the deformation matrix into the residual block of the generator of the generative adversarial network to perform an upsampling operation to obtain a sample text image.
[0077] In the embodiment of the present application, after obtaining the deformation matrix of 512×4×4n, the deformation matrix is input into the residual block of the generator for upsampling to obtain the above-mentioned sample text image with a size of 32×16n.
[0078] In an embodiment of the present application, the generative adversarial network skips some connections by means of residual blocks, allowing the generator to use the latent space to directly affect features of different resolutions and levels.
[0079] In some optional implementations of this embodiment, the generator also includes a conditional instance normalization layer and a convolution layer with a tanh activation layer.
[0080] In the embodiment of the present application, the generator introduces a conditional instance normalization layer to modulate the noise vector used in the above residual block. At the same time, a convolutional layer with a tanh activation layer is used to output the final image.
[0081] In summary, the present application provides a method for generating image samples for handwriting, including: receiving a sample generation request carrying an original handwritten text image; performing a character feature extraction operation on the original handwritten text image according to a character filter to obtain the original character feature; performing an adjacent feature extraction operation on the original handwritten text image according to a trained recognition module to obtain the original adjacent feature; generating a sample text image corresponding to the original character feature according to a generator of a trained generative adversarial network, wherein the discriminator of the generative adversarial network is spliced by a true-false classifier according to the original adjacent features; and outputting a sample text image. When constructing a generative adversarial network, the present application splices the true-false classifier in the discriminator according to the original adjacent features interacting in the overlapping areas between characters of the original handwritten text image, so that the trained generative adversarial network can generate a relatively smooth text image, and finally generates a sample text image corresponding to the original character feature according to the generator of the trained generative adversarial network, so that the generated sample text image is more realistic and diverse in style, thereby effectively increasing the diversity of training data. At the same time, the original handwritten text image is scaled to 32 pixels while maintaining the aspect ratio, so as not to destroy the text details in the image as much as possible; the generator introduces a conditional instance normalization layer to modulate the noise vector used in the residual block. At the same time, a convolutional layer with a tanh activation layer is used to output the final image.
[0082] It should be emphasized that in order to further ensure the privacy and security of the above-mentioned original handwritten text image and sample text image, the above-mentioned original handwritten text image and sample text image can also be stored in a node of a blockchain.
[0083] The blockchain referred to in this application is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0084] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0085] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0086] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0087] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing related hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the computer-readable instructions are executed, they can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0088] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0089] Embodiment 2
[0090] Further references Figure 5 , as a response to the above Figure 1 The present application provides an embodiment of a device for generating a handwritten image sample. Figure 1 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0091] like Figure 5 As shown, the image sample generation device 100 applied to handwriting of this embodiment includes: a request receiving module 110, a character feature extraction module 120, an adjacent feature extraction module 130, a sample generation module 140 and a sample output module 150. Among them:
[0092] A request receiving module 110, configured to receive a sample generation request carrying an original handwritten text image;
[0093] The character feature extraction module 120 is used to perform a character feature extraction operation on the original handwritten text image according to the character filter to obtain the original character features;
[0094] The adjacent feature extraction module 130 is used to perform an adjacent feature extraction operation on the original handwritten text image according to the trained recognition module to obtain the original adjacent features;
[0095] A sample generation module 140 is used to generate a sample text image corresponding to the original character features according to the trained generator of the generative adversarial network, and the discriminator of the generative adversarial network is formed by splicing the true and false classifiers according to the original adjacent features;
[0096] The sample output module 150 is used to output a sample text image.
[0097] In the embodiments of the present application, the original handwritten text image refers to the handwritten text input by the user. The handwritten text may be obtained by photographing the corresponding handwritten text with a camera device to obtain the corresponding original handwritten text image; the handwritten text may also be obtained by collecting the user's input information through a handwriting board to obtain the corresponding original handwritten text image. It should be understood that the example of obtaining the original handwritten text image here is only for the convenience of understanding and is not used to limit the present application.
[0098] In an embodiment of the present application, the sample generation request can be a request information sent by a requesting terminal, or a user can directly input the above-mentioned original handwritten text image as the sample generation request, wherein the requesting terminal can be a mobile terminal such as a mobile phone, a smart phone, a laptop computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a navigation device, etc., and a fixed terminal such as a digital TV, a desktop computer, etc. It should be understood that the examples of the requesting terminal here are only for convenience of understanding and are not used to limit the present application.
[0099] In an embodiment of the present application, the character filter is mainly used to filter out those parts of the original handwritten text image where the text features are not obvious, while retaining those parts where the text features are more obvious (such as edges, angles, shapes, etc.). Specifically, the size of the character filter is 32×8192.
[0100] In an embodiment of the present application, the character feature extraction operation may be to scale the original handwritten text image to a height of 32 pixels according to the original aspect ratio to obtain the original character features.
[0101] In an embodiment of the present application, the trained recognition model is obtained based on the CNN (Convolutional Neural Network) part in the CRNN (Convolutional Recurrent Neural Network) structure. The present application utilizes the overlapping property of CNN receptive fields to explain the influence of neighboring characters. This overlapping area allows adjacent characters to interact with each other, so that when a sample text image is subsequently generated, a more realistic sample text image corresponding to the original handwritten text can be generated.
[0102] In an embodiment of the present application, before obtaining a trained recognition model, sample data is first constructed. The sample data includes pixel area features of the gaps between texts in different text images. The pixel area features and the corresponding text images are used as a feature information group, and the original untrained recognition model is trained based on the feature information group. When the recognition model completes the training of all sample data, the above-mentioned trained recognition model is obtained.
[0103] In the embodiments of the present application, most recognition networks use a recurrent module (LSTM module), which uses the information of previous and subsequent image segments, that is, contextual information, to improve the accuracy of text recognition. However, in the present application, since the focus of the present application is not on text recognition, but on generating a sample text image similar to the style of the handwritten text based on the input handwritten text, and with an LSTM module, the training speed will be reduced; therefore, we only retain the CNN part in the CRNN structure.
[0104] In the embodiment of the present application, the adjacent feature extraction operation is to obtain the original adjacent feature data by extracting the overlapping area of adjacent characters.
[0105] In the embodiment of the present application, the generative adversarial network (GAN) refers to a network composed of two competing neural networks, namely the generator and the discriminator, based on the concept of adversarial training. Among them, the generator or generative model attempts to capture the data distribution, and the discriminator or discriminant model estimates the probability that the sample comes from the training data instead of G. That is, the generator tries to create the same sample as the training set and the discriminator tries to distinguish what the generator is creating from the original sample in the training set.
[0106] In an embodiment of the present application, when training a generative adversarial network, already labeled "text picture-text annotation" training samples can be obtained from the system database, and all of the "text picture-text annotation" training samples can be input into a preset generative adversarial network for training to obtain the above-mentioned trained generative adversarial network.
[0107] In the embodiment of the present application, the receptive field width of the generator is set to 16 pixels. The generator can be regarded as a splicing of conditional generators of different classes, each class represents a character in the dictionary, and each generator generates a new segment containing its input character.
[0108] In an embodiment of the present application, the discriminator is composed of different true and false classifiers, which have overlapping receptive fields (i.e., the original adjacent features mentioned above), and the scores of all classifiers are aggregated into the final discriminator output through a pooling layer. Because the model does not rely on character-level annotations, there is no need to use class supervision for each classifier. One advantage of this is that unlabeled images can be used to train the discriminator, and even other data corpora that the model has not seen can be used.
[0109] In an embodiment of the present application, since the above-mentioned adjacent feature extraction operation has obtained the original adjacent features used to connect the context, when constructing the discriminator, the classifier corresponding to the above-mentioned original handwritten text can be first obtained, and then spliced according to the original adjacent features to obtain the discriminator corresponding to the above-mentioned original handwritten text image.
[0110] In an embodiment of the present application, the method for generating the above-mentioned sample text image may be to obtain the above-mentioned character filter corresponding to the number of characters of the above-mentioned original handwritten text image; splicing the above-mentioned character filters, and multiplying the spliced character filters with the noise vector to obtain a noise matrix; deforming the above-mentioned noise matrix to obtain a deformation matrix; inputting the above-mentioned deformation matrix into the residual block of the generator of the above-mentioned generative adversarial network for upsampling operation, thereby obtaining the above-mentioned sample text image.
[0111] In an embodiment of the present application, a device 100 for generating image samples for handwriting is provided, including: a request receiving module 110, for receiving a sample generation request carrying an original handwritten text image; a character feature extraction module 120, for performing a character feature extraction operation on the original handwritten text image according to a character filter to obtain original character features; an adjacent feature extraction module 130, for performing an adjacent feature extraction operation on the original handwritten text image according to a trained recognition module to obtain original adjacent features; a sample generation module 140, for generating a sample text image corresponding to the original character features according to a generator of a trained generative adversarial network, the discriminator of the generative adversarial network being spliced by a true or false classifier according to the original adjacent features; and a sample output module 150, for outputting a sample text image. When constructing a generative adversarial network, the present application uses the authenticity classifier in the original adjacent feature splicing discriminator based on the interaction between the overlapping areas of the characters in the original handwritten text image, so that the trained generative adversarial network can generate a relatively smooth text image. Finally, a sample text image corresponding to the original character features is generated based on the generator of the trained generative adversarial network, so that the generated sample text image is more realistic and diverse in style, thereby effectively increasing the diversity of training data.
[0112] Continue reading Figure 6 , shows a schematic diagram of the structure of another device for generating image samples for handwriting provided in the second embodiment of the present application. For the sake of convenience of explanation, only the parts related to the present application are shown.
[0113] In some optional implementations of this embodiment, the character feature extraction module 120 further includes: a character feature extraction submodule 121. Among them:
[0114] The character feature extraction submodule 121 is used to scale the original handwritten text image to a height of 32 pixels according to the original aspect ratio to obtain the original character features.
[0115] In an embodiment of the present application, the above-mentioned original handwritten text image is scaled to a height of 32 pixels while maintaining the aspect ratio of the original image to obtain original character features with more obvious text features, wherein the original handwritten text image is scaled to 32 pixels while maintaining the aspect ratio, so as to minimize the destruction of text details in the image (of course, the input image can also be scaled to a fixed width, but this will definitely cause performance degradation due to the destruction of the shape of the text).
[0116] In some optional implementations of this embodiment, the discriminator consists of 4 residual blocks and one fully connected layer, and is obtained through supervised training based on the maximum margin loss.
[0117] In the embodiment of the present application, the structure of the discriminator is inspired by the BiGAN (Bidirectional GAN) structure, and the discriminator is designed to learn meaningful feature representations. Figure 3 In the original GAN, D receives samples as input and uses the learned intermediate representation as the feature representation of the relevant task without any additional mechanism. It is not very clear about the semantically meaningful features of generated data and real data. In fact, when G generates real data, D will completely ignore the generated data and unconditionally predict p=1 / 2, and will not learn any meaningful intermediate representation. BiGAN hopes to make GAN learn meaningful representations.
[0118] In some optional implementations of this embodiment, the trained recognition module is obtained by supervised training based on CTC loss.
[0119] In the embodiments of the present application, the full name of CTC is Connectionist Temporal Classification. This method mainly solves the problem of misalignment between the neural network label and output (Alignment problem). This problem often occurs in applications such as scene text recognition, speech recognition, and handwriting recognition. For example, the speech recognition in Fig. 1 will recognize many ww and many r. If no processing is done, it will become wworrrlld. I ignored the blank. A simple and crude method is to treat all repeated letters as one letter. However, this will result in the failure to recognize words such as happy. At this time, the role of blank is very important. Here it separates the same letter, such as happy, which will become hhh aaaa ppp ppp yyyy-->happy.
[0120] In the embodiment of the present application, the CTC calculation includes a softmax output layer, and there is also an additional label (blank). The probability calculation of a path is as follows:
[0121]
[0122] Among them, x is the input data, y is the output data, both are sequences; L is the label of the sequence label, L` is the sequence label + blank. The above formula explains that given an input, the probability of each time point from time t=1 to T is multiplied, and finally the probability of the corresponding path is obtained.
[0123] In some optional implementations of this embodiment, the sample generation module 140 includes:
[0124] A filter acquisition submodule, used to acquire character filters corresponding to the number of characters in the original handwritten text image;
[0125] A noise matrix acquisition submodule is used to concatenate character filters and multiply the concatenated character filters with the noise vector to obtain a noise matrix;
[0126] The matrix deformation submodule is used to deform the noise matrix to obtain a deformation matrix;
[0127] The upsampling submodule is used to input the deformation matrix into the residual block of the generator of the generative adversarial network to perform an upsampling operation to obtain a sample text image.
[0128] In the embodiment of the present application, since the focus of the present application is to generate a handwritten text image with a style similar to the input text based on the input handwritten text, in order to generate a number of characters corresponding to the number of characters n in the original handwritten text image, the generative adversarial network needs to obtain character filters corresponding to the number of characters to generate a corresponding number of handwritten text images.
[0129] In an embodiment of the present application, after the generative adversarial network completes splicing the character filter, it multiplies the character filter with a 32-dimensional noise vector z to obtain an n×8192 matrix, namely the above-mentioned noise matrix.
[0130] In the embodiment of the present application, deforming the noise matrix refers to deforming the above-mentioned n×8192 noise matrix into a 512×4×4n matrix, that is, the above-mentioned deformed matrix, and the size of each character in the deformed matrix is 4×4.
[0131] In the embodiment of the present application, after obtaining the deformation matrix of 512×4×4n, the deformation matrix is input into the residual block of the generator for upsampling to obtain the above-mentioned sample text image with a size of 32×16n.
[0132] In an embodiment of the present application, the generative adversarial network skips some connections by means of residual blocks, allowing the generator to use the latent space to directly affect features of different resolutions and levels.
[0133] In some optional implementations of this embodiment, the generator also includes a conditional instance normalization layer and a convolution layer with a tanh activation layer.
[0134] In the embodiment of the present application, the generator introduces a conditional instance normalization layer to modulate the noise vector used in the above residual block. At the same time, a convolutional layer with a tanh activation layer is used to output the final image.
[0135] In summary, the present application provides a device 100 for generating image samples for handwriting, including: a request receiving module 110, used to receive a sample generation request carrying an original handwritten text image; a character feature extraction module 120, used to perform a character feature extraction operation on the original handwritten text image according to a character filter to obtain the original character feature; an adjacent feature extraction module 130, used to perform an adjacent feature extraction operation on the original handwritten text image according to a trained recognition module to obtain the original adjacent feature; a sample generation module 140, used to generate a sample text image corresponding to the original character feature according to a trained generator of a generative adversarial network, the discriminator of the generative adversarial network being spliced by a true or false classifier according to the original adjacent features; a sample output module 150, used to output the sample text image. When constructing a generative adversarial network, the present application uses the original adjacent feature splicing discriminator based on the interaction of overlapping areas between characters in the original handwritten text image to generate a relatively smooth text image, and finally generates a sample text image corresponding to the original character features based on the generator of the trained generative adversarial network, so that the generated sample text image is more realistic and diverse in style, thereby effectively increasing the diversity of training data. At the same time, the original handwritten text image is scaled to 32 pixels while maintaining the aspect ratio, so as to minimize the destruction of text details in the image; the generator introduces a conditional instance normalization layer to modulate the noise vector used in the residual block. At the same time, a convolutional layer with a tanh activation layer is used to output the final image.
[0136] To solve the above technical problems, the present application also provides a computer device. Figure 7 , Figure 7 This is a basic structural block diagram of the computer device in this embodiment.
[0137] The computer device 200 includes a memory 210, a processor 220, and a network interface 230 that are interconnected and communicated through a system bus. It should be noted that the figure only shows a computer device 200 having components 210-230, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.
[0138] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.
[0139] The memory 210 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 210 can be an internal storage unit of the computer device 200, such as a hard disk or memory of the computer device 200. In other embodiments, the memory 210 can also be an external storage device of the computer device 200, such as a plug-in hard disk equipped on the computer device 200, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card, etc. Of course, the memory 210 can also include both the internal storage unit of the computer device 200 and its external storage device. In this embodiment, the memory 210 is generally used to store an operating system and various application software installed on the computer device 200, such as computer-readable instructions for a method for generating a handwritten image sample. In addition, the memory 210 can also be used to temporarily store various data that have been output or are to be output.
[0140] The processor 220 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments. The processor 220 is generally used to control the overall operation of the computer device 200. In this embodiment, the processor 220 is used to run computer-readable instructions stored in the memory 210 or process data, such as running computer-readable instructions for the method for generating a handwritten image sample.
[0141] The network interface 230 may include a wireless network interface or a wired network interface. The network interface 230 is generally used to establish a communication connection between the computer device 200 and other electronic devices.
[0142] The computer device provided by the present application, when constructing a generative adversarial network, uses the authenticity classifier in the original adjacent feature splicing discriminator that interacts with the overlapping areas between characters in the original handwritten text image, so that the trained generative adversarial network can generate a relatively smooth text image. Finally, a sample text image corresponding to the original character features is generated according to the generator of the trained generative adversarial network, so that the generated sample text image is more realistic and diverse in style, thereby effectively increasing the diversity of training data.
[0143] The present application also provides another embodiment, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the above-mentioned method for generating image samples applied to handwriting.
[0144] The computer-readable storage medium provided by the present application, when constructing a generative adversarial network, uses the original adjacent feature splicing discriminator based on the interaction of overlapping areas between characters in the original handwritten text image to generate a true or false classifier, so that the trained generative adversarial network can generate a relatively smooth text image. Finally, a sample text image corresponding to the original character features is generated based on the generator of the trained generative adversarial network, so that the generated sample text image is more realistic and diverse in style, thereby effectively increasing the diversity of training data.
[0145] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0146] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.
Claims
1. A method for generating image samples for handwriting, characterized in that: The method comprises the following steps: Receiving a sample generation request carrying an original handwritten text image; Performing a character feature extraction operation on the handwritten text image according to a character filter to obtain original character features; Performing an adjacent feature extraction operation on the handwritten text image according to the trained recognition module to obtain original adjacent features, wherein the trained recognition module is obtained based on the CNN part in the CRNN structure, and the adjacent feature extraction operation is to obtain the original adjacent feature data by extracting the overlapping area of adjacent characters; A sample text image corresponding to the original character features is generated according to a generator of a trained generative adversarial network, wherein a discriminator of the generative adversarial network is formed by splicing a true-false classifier according to the original adjacent features; Outputting the sample text image; The step of generating a sample text image corresponding to the original character features according to the generator of the trained generative adversarial network specifically comprises the following steps: Acquire the character filter corresponding to the number of characters in the original handwritten text image; Splicing the character filters, and multiplying the spliced character filters with a noise vector to obtain a noise matrix; Deforming the noise matrix to obtain a deformation matrix; The deformation matrix is input into the residual block of the generator of the generative adversarial network for upsampling operation to obtain the sample text image.
2. The method for generating image samples for handwriting according to claim 1, characterized in that: The step of performing a character feature extraction operation on the handwritten text image according to the character filter to obtain the original character features specifically comprises the following steps: The original handwritten text image is scaled to a height of 32 pixels according to the original aspect ratio to obtain the original character features.
3. The method for generating image samples for handwriting according to claim 1, characterized in that: The discriminator consists of 4 residual blocks and a fully connected layer, and is trained using supervised maximum margin loss.
4. The method for generating image samples for handwriting according to claim 3, characterized in that: The trained recognition module is obtained by supervised training based on CTC loss.
5. The method for generating image samples for handwriting according to claim 4, characterized in that: The generator also includes a conditional instance normalization layer and a convolutional layer with a tanh activation layer.
6. A device for generating image samples for handwriting, characterized in that: include: A request receiving module, used for receiving a sample generation request carrying an original handwritten text image; A character feature extraction module, used for performing a character feature extraction operation on the handwritten text image according to a character filter to obtain original character features; An adjacent feature extraction module is used to perform an adjacent feature extraction operation on the handwritten text image according to a trained recognition module to obtain original adjacent features, wherein the trained recognition module is obtained based on the CNN part in the CRNN structure, and the adjacent feature extraction operation is to obtain the original adjacent feature data by extracting the overlapping area of adjacent characters; A sample generation module, used to generate a sample text image corresponding to the original character features according to a trained generator of a generative adversarial network, wherein the discriminator of the generative adversarial network is formed by splicing the true and false classifiers according to the original adjacent features; A sample output module, used for outputting the sample text image; The sample generation module includes: a filter acquisition submodule, a noise matrix acquisition submodule, a matrix deformation submodule and an upsampling submodule, wherein: The filter acquisition submodule is used to acquire the character filter corresponding to the number of characters in the original handwritten text image; The noise matrix acquisition submodule is used to splice the character filters and multiply the spliced character filters with the noise vector to obtain a noise matrix; The matrix deformation submodule is used to deform the noise matrix to obtain a deformation matrix; The upsampling submodule is used to input the deformation matrix into the residual block of the generator of the generative adversarial network to perform an upsampling operation to obtain the sample text image.
7. The image sample generating device for handwriting according to claim 6, characterized in that: The character feature extraction module comprises: The character feature extraction submodule is used to scale the original handwritten text image to a height of 32 pixels according to the original aspect ratio to obtain the original character features.
8. A computer device, characterized in that: The method comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the method for generating a picture sample applied to handwriting according to any one of claims 1 to 5 when executing the computer-readable instructions.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the method for generating a picture sample applied to handwriting according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
A text image super-resolution reconstruction method based on a conditional generative adversarial network
CN109410239A
Text recognition method and device
CN112749695A
