WO2023221422A1 - Neural network used for text recognition, training method thereof and text recognition method - Google Patents

Neural network used for text recognition, training method thereof and text recognition method Download PDF

Info

Publication number
WO2023221422A1
WO2023221422A1 PCT/CN2022/131189 CN2022131189W WO2023221422A1 WO 2023221422 A1 WO2023221422 A1 WO 2023221422A1 CN 2022131189 W CN2022131189 W CN 2022131189W WO 2023221422 A1 WO2023221422 A1 WO 2023221422A1
Authority
WO
WIPO (PCT)
Prior art keywords
feature map
pixel
feature
subnetwork
convolution
Prior art date
Application number
PCT/CN2022/131189
Other languages
French (fr)
Chinese (zh)
Inventor
殷晓婷
杜宇宁
李晨霞
杨烨华
赖宝华
毕然
马艳军
胡晓光
于佃海
Original Assignee
北京百度网讯科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 北京百度网讯科技有限公司 filed Critical 北京百度网讯科技有限公司
Publication of WO2023221422A1 publication Critical patent/WO2023221422A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/25Fusion techniques
    • G06F18/253Fusion techniques of extracted features
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/045Combinations of networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods

Definitions

  • the present disclosure relates to the field of artificial intelligence, specifically to machine learning technology, computer vision technology, image processing technology and deep learning technology, and in particular to a neural network for text recognition, a method of text recognition using a neural network, and the training of a neural network Methods, electronic devices, computer-readable storage media, and computer program products.
  • Artificial intelligence is the study of using computers to simulate certain human thinking processes and intelligent behaviors (such as learning, reasoning, thinking, planning, etc.). It has both hardware-level technology and software-level technology. Artificial intelligence hardware technology generally includes technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing, etc.; artificial intelligence software technology mainly includes computer vision technology, speech recognition technology, natural language processing technology, and machine learning/depth Learning, big data processing technology, knowledge graph technology and other major directions.
  • OCR Optical Character Recognition
  • the present disclosure provides a neural network for text recognition, a method for text recognition using a neural network, a neural network training method, an electronic device, a computer-readable storage medium and a computer program product.
  • a neural network for text recognition including: a first convolution subnetwork configured to perform convolution processing on an image to be recognized to output a first feature map; a local fusion subnetwork , configured to use the self-attention mechanism for each pixel in the first feature map to determine the local feature vector of the pixel based on the feature vector corresponding to the pixel and the respective feature vectors of multiple target pixels in the first feature map.
  • the second convolution subnetwork is configured to convolve the second feature map Process to output the third feature map
  • the global fusion sub-network is configured to target each pixel in the third feature map, using the self-attention mechanism based on the feature vector corresponding to the pixel and each pixel in the third feature map
  • Respective feature vectors determine the global feature vector of the pixel to obtain the fourth feature map
  • the output sub-network is configured to output the text recognition result based on the fourth feature map.
  • a method for text recognition using a neural network includes a first convolution subnetwork, a local fusion subnetwork, a second convolution subnetwork, a global fusion subnetwork, and an output sub-network, the method includes: inputting the image to be recognized into a first convolution sub-network, the first convolution sub-network being configured to perform convolution processing on the image to be recognized to output a first feature map; inputting the first feature map into local fusion sub-network, the local fusion sub-network is configured to use the self-attention mechanism for each pixel in the first feature map to determine based on the feature vector corresponding to the pixel and the respective feature vectors of multiple target pixels in the first feature map.
  • the plurality of target pixels include multiple pixels located in the neighborhood of the pixel in the first feature map; input the second feature map into the second convolution subnetwork , the second convolution sub-network is configured to perform convolution processing on the second feature map to output the third feature map; the third feature map is input to the global fusion sub-network, and the global fusion sub-network is configured to target the third feature map For each pixel in, use the self-attention mechanism to determine the global feature vector of the pixel based on the feature vector corresponding to the pixel and the respective feature vector of each pixel in the third feature map, to obtain the fourth feature map; and The fourth feature map inputs and outputs the sub-network, and the output sub-network is configured to output the text recognition result based on the fourth feature map.
  • a training method for a neural network includes a first convolution subnetwork, a local fusion subnetwork, a second convolution subnetwork, a global fusion subnetwork, and an output subnetwork, The method includes: determining the sample image and the corresponding real result; inputting the sample image into a first convolution subnetwork, and the first convolution subnetwork is configured to perform convolution processing on the sample image to output the first feature map; The feature map inputs the local fusion sub-network, and the local fusion sub-network is configured to target each pixel in the first feature map, using the self-attention mechanism based on the feature vector corresponding to the pixel and each of the multiple target pixels in the first feature map.
  • the feature vector determine the local feature vector of the pixel to obtain the second feature map, in which the multiple target pixels include multiple pixels located in the neighborhood of the pixel in the first feature map; input the second feature map into the Two convolution sub-networks, the second convolution sub-network is configured to perform convolution processing on the second feature map to output the third feature map; the third feature map is input to the global fusion sub-network, and the global fusion sub-network is configured as For each pixel in the third feature map, the self-attention mechanism is used to determine the global feature vector of the pixel based on the feature vector corresponding to the pixel and the respective feature vectors of each pixel in the third feature map to obtain the fourth feature map; input the fourth feature map into the output sub-network, and the output sub-network is configured to output the prediction result of text recognition on the sample image based on the fourth feature map; calculate the loss value based on the real result and the prediction result; and based on the loss Adjust the parameters of the neural network to obtain the trained neural network.
  • an electronic device including: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are At least one processor executes, so that at least one processor can execute the above method.
  • a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause a computer to perform the above method.
  • a computer program product including a computer program, wherein the computer program implements the above method when executed by a processor.
  • image features can be processed in parallel, thereby improving training speed and prediction speed, and by using local fusion sub-networks and global fusion sub-networks, This enables the local correlation and global correlation between text characters to be considered, thereby improving prediction accuracy.
  • convolutional subnetworks enables the use of existing deep learning acceleration libraries for acceleration, thereby further improving the training speed and prediction speed of the inference stage.
  • FIG. 1 illustrates a schematic diagram of an exemplary system in which various methods described herein may be implemented in accordance with embodiments of the present disclosure
  • Figure 2 shows a structural block diagram of a neural network for text recognition according to an exemplary embodiment of the present disclosure
  • Figure 3 shows a flowchart of a method of text recognition according to an exemplary embodiment of the present disclosure
  • Figure 4 shows a flow chart of a training method of a neural network according to an exemplary embodiment of the present disclosure.
  • FIG. 5 illustrates a structural block diagram of an exemplary electronic device that can be used to implement embodiments of the present disclosure.
  • first”, “second”, etc. to describe various elements is not intended to limit the positional relationship, timing relationship, or importance relationship of these elements. Such terms are only used for Distinguish one element from another.
  • the first element and the second element can refer to the same instance of the element, and in some cases, based on contextual description, they can refer to different instances.
  • RNN Recursive Neural Network
  • the present disclosure enables parallel processing of image features by using a network module that utilizes a self-attention mechanism, thereby improving training speed and prediction speed, and by using local fusion sub-networks and global fusion sub-networks, allowing text to be considered Local correlation and global correlation between characters, thereby improving prediction accuracy.
  • the use of convolutional subnetworks enables the use of existing deep learning acceleration libraries for acceleration, thereby further improving the training speed and prediction speed of the inference stage.
  • FIG. 1 shows a schematic diagram of an exemplary system 100 in which various methods and apparatus described herein may be implemented in accordance with embodiments of the present disclosure.
  • the system 100 includes one or more client devices 101 , 102 , 103 , 104 , 105 , and 106 , a server 120 , and one or more communication networks coupling the one or more client devices to the server 120 110.
  • Client devices 101, 102, 103, 104, 105, and 106 may be configured to execute one or more applications.
  • the server 120 may run one or more services or software applications that enable performing methods of text recognition and/or training methods of neural networks.
  • server 120 may also provide other services or software applications that may include non-virtual environments and virtual environments.
  • these services may be provided as web-based services or cloud services, such as under a Software as a Service (SaaS) network to users of client devices 101, 102, 103, 104, 105, and/or 106 .
  • SaaS Software as a Service
  • server 120 may include one or more components that implement the functions performed by server 120 . These components may include software components, hardware components, or combinations thereof that are executable by one or more processors. Users operating client devices 101, 102, 103, 104, 105, and/or 106 may, in turn, utilize one or more client applications to interact with server 120 to utilize services provided by these components. It should be understood that a variety of different system configurations are possible, which may differ from system 100 . Accordingly, Figure 1 is one example of a system for implementing the various methods described herein and is not intended to be limiting.
  • the client device may provide an interface that enables the user of the client device to interact with the client device. For example, the user may use a camera of the client device to collect an image to be recognized, or use the client device to upload to the server an image stored in the client device. image.
  • the client device can also output information to the user via the interface. For example, the client can output to the user text obtained by recognizing the image to be recognized uploaded by the user using a text recognition method running on the server.
  • FIG. 1 depicts only six client devices, those skilled in the art will understand that the present disclosure can support any number of client devices.
  • Client devices 101, 102, 103, 104, 105, and/or 106 may include various types of computer devices, such as portable handheld devices, general purpose computers (such as personal computers and laptop computers), workstation computers, wearable devices, Smart screen equipment, self-service terminal equipment, service robots, game systems, thin clients, various messaging equipment, sensors or other sensing equipment, etc.
  • These computer devices can run various types and versions of software applications and operating systems, such as MICROSOFT Windows, APPLE iOS, UNIX-like operating systems, Linux or Linux-like operating systems (such as GOOGLE Chrome OS); or include various mobile operating systems , such as MICROSOFT Windows Mobile OS, iOS, Windows Phone, Android.
  • Portable handheld devices may include cellular phones, smart phones, tablet computers, personal digital assistants (PDAs), and the like.
  • Wearable devices may include head-mounted displays (such as smart glasses) and other devices.
  • Gaming systems may include various handheld gaming devices, Internet-enabled gaming devices, and the like.
  • the client device is capable of executing a variety of different applications, such as various Internet-related applications, communication applications (such as email applications), Short Message Service (SMS) applications, and can use various communication protocols.
  • Network 110 may be any type of network known to those skilled in the art that may support data communications using any of a variety of available protocols (including, but not limited to, TCP/IP, SNA, IPX, etc.).
  • one or more networks 110 may be a local area network (LAN), an Ethernet-based network, a token ring, a wide area network (WAN), the Internet, a virtual network, a virtual private network (VPN), an intranet, an extranet, Public Switched Telephone Network (PSTN), infrared network, wireless network (e.g. Bluetooth, WIFI) and/or any combination of these and/or other networks.
  • LAN local area network
  • Ethernet-based network a token ring
  • WAN wide area network
  • VPN virtual private network
  • PSTN Public Switched Telephone Network
  • WIFI wireless network
  • Server 120 may include one or more general purpose computers, special purpose server computers (eg, PC (Personal Computer) servers, UNIX servers, midrange servers), blade servers, mainframe computers, server clusters, or any other suitable arrangement and/or combination .
  • Server 120 may include one or more virtual machines running a virtual operating system, or other computing architecture involving virtualization (eg, one or more flexible pools of logical storage devices that may be virtualized to maintain the server's virtual storage devices).
  • server 120 may run one or more services or software applications that provide the functionality described below.
  • Computing units in server 120 may run one or more operating systems, including any of the operating systems described above, as well as any commercially available server operating system.
  • Server 120 may also run any of a variety of additional server applications and/or middle-tier applications, including HTTP servers, FTP servers, CGI servers, JAVA servers, database servers, and the like.
  • server 120 may include one or more applications to analyze and incorporate data feeds and/or event updates received from users of client devices 101, 102, 103, 104, 105, and 106.
  • Server 120 may also include one or more applications to display data feeds and/or real-time events via one or more display devices of client devices 101 , 102 , 103 , 104 , 105 , and 106 .
  • the server 120 may be a server of a distributed system, or a server combined with a blockchain.
  • the server 120 may also be a cloud server, or an intelligent cloud computing server or intelligent cloud host with artificial intelligence technology.
  • Cloud server is a host product in the cloud computing service system to solve the shortcomings of difficult management and weak business scalability in traditional physical host and virtual private server (VPS) services.
  • System 100 may also include one or more databases 130.
  • these databases may be used to store data and other information.
  • databases 130 may be used to store information such as audio files and video files.
  • Database 130 may reside in various locations.
  • a data repository used by server 120 may be local to server 120, or may be remote from server 120 and may communicate with server 120 via a network-based or dedicated connection.
  • Database 130 may be of different types.
  • the database used by server 120 may be a database, such as a relational database.
  • One or more of these databases may store, update, and retrieve data to and from the database in response to commands.
  • one or more of databases 130 may also be used by applications to store application data.
  • the database used by the application can be different types of databases such as key-value repositories, object repositories or regular repositories backed by a file system.
  • the system 100 of Figure 1 may be configured and operated in various ways to enable the application of the various methods and apparatus described in accordance with the present disclosure.
  • the neural network 200 includes: a first convolution sub-network 204 configured to perform convolution processing on the image to be recognized 202 to output a first feature map; a local fusion sub-network 206 configured to perform convolution processing on the first feature map.
  • the self-attention mechanism is used to determine the local feature vector of the pixel based on the feature vector corresponding to the pixel and the feature vectors of multiple target pixels in the first feature map to obtain the second feature map.
  • the plurality of target pixels include multiple pixels located in the neighborhood of the pixel in the first feature map;
  • the second convolution subnetwork 208 is configured to perform convolution processing on the second feature map to output a third Feature map;
  • the global fusion sub-network 210 is configured to use a self-attention mechanism for each pixel in the third feature map based on the feature vector corresponding to the pixel and the respective feature vector of each pixel in the third feature map, Determine the global feature vector of the pixel to obtain a fourth feature map;
  • the output sub-network 212 is configured to output the text recognition result 214 based on the fourth feature map.
  • the network module that utilizes the self-attention mechanism, it is possible to process image features in parallel, thereby improving the training speed and prediction speed, and by using the local fusion sub-network and the global fusion sub-network, it is possible to consider the differences between text characters. Local correlation and global correlation, thereby improving prediction accuracy.
  • the use of convolutional subnetworks enables the use of existing deep learning acceleration libraries such as the Math Kernel Library for Deep Neural Networks (MKL-DNN) for acceleration, thereby further improving training speed and Prediction speed during the inference phase.
  • MKL-DNN Math Kernel Library for Deep Neural Networks
  • the neural network and its training method and text recognition method of the present disclosure can be applied to any text recognition scenario, including Chinese, English, multi-language, and so on.
  • the image to be recognized may be any image containing text.
  • the image to be recognized may be an image captured by the camera of the client device, an image already stored on the client device, or an image obtained in other ways, which is not limited here.
  • the size of the image to be recognized that is input to the neural network can be limited. In an exemplary embodiment, the size is 32 ⁇ 320. It is understandable that different input sizes can be set according to actual needs.
  • a preprocessing subnetwork can be set before the first convolutional subnetwork to preprocess the received original image, so that an image to be recognized that meets the input size and/or meets other input requirements can be obtained.
  • At least one of the first convolutional subnetwork and the second convolutional subnetwork may include depthwise separable convolutional layers.
  • the operation of the depthwise separable convolution layer on the received feature map can be divided into two steps: the first step is to use the corresponding N ⁇ N ⁇ 1 convolution kernel to process each channel of the original feature map to obtain the sum
  • the intermediate feature map has the same size as the original feature map; in the second step, k 1 ⁇ 1 convolution kernels are used to process the intermediate feature map to obtain a feature map with the same width and height as the original feature map, but with a depth of k.
  • Using depthwise separable convolutions can significantly reduce the number of multiplication operations, thereby significantly reducing computational costs and reducing the amount of parameters that need to be stored.
  • the first convolutional sub-network may also include a conventional convolutional layer to better extract image feature information from the image to be recognized.
  • At least one of the first convolutional subnetwork and the second convolutional subnetwork may include a first depthwise separable convolutional layer, and the second convolutional subnetwork may include a second depthwise separable convolutional layer.
  • the size of the convolution kernel of the first depth-separable convolution layer may be smaller than the size of the convolution kernel of the second depth-separable convolution layer.
  • the size of the convolution kernel of the first depth-separable convolution layer may be 3 ⁇ 3, and the size of the convolution kernel of the second depth-separable convolution layer may be 5 ⁇ 5.
  • the obtained feature map can also be processed using a compression and excitation network (Squeeze-and-Excitation Net, SENet) to further enhance the features.
  • SENet compression and excitation network
  • each of the first convolutional subnetwork and the second convolutional subnetwork may be a PaddlePaddle based Lightweight CPU Convolutional Neural Network (PaddlePaddle based Lightweight CPU Convolutional) suitable for a Central Processing Unit (CPU).
  • PaddlePaddle based Lightweight CPU Convolutional suitable for a Central Processing Unit (CPU).
  • CPU Central Processing Unit
  • Neural Network part of PP-LCNet.
  • PP-LCNet is a lightweight network that uses fewer parameters and requires less calculation in the training and inference stages.
  • MKL-DNN can be used for optimization at the CPU operation level, so it can be used for applications with higher performance requirements.
  • Mission scenario OCR tasks usually require rapid and accurate text recognition results, so using PP-LCNet can give full play to its above advantages.
  • PP-LCNet includes 5 stages (Stage), including:
  • Stage 1 consists of a regular convolutional layer with a convolution kernel of 3 ⁇ 3 and a stride of 2;
  • Stage 2 includes two depthwise separable convolutional layers with a convolution kernel of 3 ⁇ 3 and strides of 1 and 2 respectively;
  • Stage 3 includes two depthwise separable convolutional layers with a convolution kernel of 3 ⁇ 3 and strides of 1 and 2 respectively;
  • Stage 4 includes two depthwise separable convolutional layers with a convolution kernel of 3 ⁇ 3 and strides of 1 and 2 respectively;
  • Stage 5 consists of seven depthwise separable convolutional layers with a convolution kernel of 5 ⁇ 5.
  • the first five convolutional layers and the seventh convolutional layer have a stride of 1, and the sixth convolutional layer has a stride of 2.
  • SENet also called SE module
  • SENet is used after the sixth and seventh convolutional layers.
  • local fusion agents may be added at one or more of the four positions between stages 1 and 2, between stages 2 and 3, between stages 3 and 4, and between stages 4 and 5. network.
  • the local fusion sub-network is close to the input end of the neural network, which will significantly increase the amount of calculation (the number of pixels in the feature map output by two adjacent convolutional layers/stages is four times or even an exponential multiple of four, and the closer it is to the input The greater the end difference), and being close to the output end of the neural network will reduce the accuracy to a certain extent.
  • adding a local fusion sub-network between stages 3 and 4 can achieve the best balance between the two, thereby significantly improving the inference accuracy of the neural network at a reduced time cost.
  • a self-attention mechanism is used to determine the local feature vector of the pixel based on the feature vector corresponding to the pixel and the respective feature vectors of multiple target pixels in the first feature map.
  • to obtain the second feature map may include: determining the attention score of the feature vector corresponding to each target pixel in the plurality of target pixels with respect to the feature vector corresponding to the pixel; and based on the corresponding feature vector of each target pixel in the plurality of target pixels.
  • the feature vector of the feature vector corresponds to the attention score of the feature vector corresponding to the pixel, and the feature vectors corresponding to the multiple target pixels are fused to obtain the local feature vector of the pixel.
  • the pixels in the local neighborhood of each pixel in the first feature map are fused using the self-attention mechanism, and the local features between strokes are obtained, thus strengthening the feature vector of the pixel.
  • the above-mentioned processing method of the feature vector of the pixel and the feature vectors corresponding to the multiple target pixels can refer to the operation of the Transformer block on different input features in the prior art.
  • the inference accuracy can be improved, and on the other hand, features can be processed in parallel to speed up the training process and improve the inference speed.
  • the range of the local neighborhood can be set according to requirements, such as a rectangular area with a preset width and a preset height centered on the target pixel.
  • the specific values of the preset width and preset height can also be determined according to needs. It can be understood that local neighborhoods of other shapes or other ranges can also be set, which are not limited here.
  • the local fusion sub-network does not change the size of the feature map. That is, the first feature map and the second feature map have the same size.
  • the third feature map is processed.
  • the size of the image to be recognized is H ⁇ W
  • the size of the third feature map output by the second convolution subnetwork is H/32 ⁇ W/4
  • the size of the third feature map output by the second convolution subnetwork is H/32 ⁇ W/4
  • the size after further processing using the convolution layer is H/32 ⁇ W/8.
  • the height of the third feature map may be 1/32 of the height of the image to be recognized. In an embodiment where the height of the image to be recognized is 32, the height of the third feature map may be 1. It can be understood that the third feature map here may be the third feature map output by the second convolution subnetwork, or it may be the third feature map after size transformation. This setting is based on the fact that the prediction speed of the global fusion subnetwork is highly sensitive to the shape/size of the features it receives. Therefore, by limiting the input feature shape, its prediction speed can be improved, thereby improving the overall text recognition speed. In fact, the third feature map with a height of 1 is essentially equivalent to a feature vector sequence, and each feature vector in the sequence corresponds to an image area composed of several consecutive columns of pixels in the image to be recognized.
  • the global fusion sub-network also based on the self-attention mechanism can be used to process the third feature map. It can be understood that the way the global fusion sub-network processes the third feature map is similar to the way the local fusion sub-network processes the first feature map. The difference is that the global fusion sub-network calculates the sum for each target pixel in the third feature map. Each pixel in the third feature map corresponds to the attention score, and the feature vectors of all pixels are fused according to the attention score of each pixel to strengthen the feature vector of the target pixel.
  • the global fusion sub-network can achieve the merging of global features.
  • the global fusion sub-network also does not change the size of the feature map.
  • the third feature map and the fourth feature map have the same size.
  • the size of the third feature map and the fourth feature map are both 1 ⁇ 40.
  • the neural network may further include at least one of the following: a first fusion layer configured to fuse the first feature map and the second feature map to update the second feature map; and a second fusion layer configured To fuse the third feature map and the fourth feature map to update the fourth feature map.
  • a first fusion layer configured to fuse the first feature map and the second feature map to update the second feature map
  • a second fusion layer configured To fuse the third feature map and the fourth feature map to update the fourth feature map.
  • the output subnetwork can be any network structure capable of outputting text recognition results based on feature maps.
  • the output sub-network may be a fully connected layer or a multi-layer perceptron. It can be understood that other network structures can also be used as output subnetworks, which are not limited here.
  • a method for text recognition using a neural network includes a first convolution subnetwork, a local fusion subnetwork, a second convolution subnetwork, a global fusion subnetwork, and an output subnetwork.
  • the method includes: step S301, input the image to be recognized into the first convolution subnetwork, and the first convolution subnetwork is configured to perform convolution processing on the image to be recognized to output the first feature map; Step S302. Input the first feature map into the local fusion sub-network.
  • the local fusion sub-network is configured to use the self-attention mechanism for each pixel in the first feature map based on the feature vector corresponding to the pixel and the first feature map.
  • the respective feature vectors of multiple target pixels are used to determine the local feature vector of the pixel to obtain the second feature map, where the multiple target pixels include multiple pixels located in the neighborhood of the pixel in the first feature map; step S303 , input the second feature map into the second convolution sub-network, and the second convolution sub-network is configured to perform convolution processing on the second feature map to output the third feature map; Step S304, input the third feature map into the global Fusion sub-network, the global fusion sub-network is configured to use the self-attention mechanism for each pixel in the third feature map to determine based on the feature vector corresponding to the pixel and the respective feature vector of each pixel in the third feature map.
  • the global feature vector of the pixel is used to obtain the fourth feature map; and step S305, input the fourth feature map into the output sub-network, and the output sub-network is configured to output the text recognition result based on the fourth feature map.
  • steps S301 to S305 in FIG. 3 are similar to the operations of subnetwork 204 to subnetwork 212 in the neural network 200, respectively, and will not be described again.
  • the network module that utilizes the self-attention mechanism image features can be processed in parallel, thereby improving the prediction speed, and by using the local fusion sub-network and the global fusion sub-network, the local correlation between text characters can be considered and global correlation, thereby improving prediction accuracy.
  • the use of convolutional subnetworks enables the use of existing deep learning acceleration libraries for acceleration, thereby further improving the prediction speed of the inference stage.
  • At least one of the first convolutional subnetwork and the second convolutional subnetwork may include depthwise separable convolutional layers.
  • the first convolutional subnetwork may include a regular convolutional layer
  • at least one of the first convolutional subnetwork and the second convolutional subnetwork may include a first depthwise separable convolutional layer
  • the second convolutional subnetwork may
  • the product subnetwork may include a second depthwise separable convolutional layer.
  • the size of the convolution kernel used by the first depth-separable convolution layer is smaller than the size of the convolution kernel used by the second depth-separable convolution layer.
  • a self-attention mechanism is used to determine the local feature vector of the pixel based on the feature vector corresponding to the pixel and the respective feature vectors of multiple target pixels in the first feature map.
  • to obtain the second feature map may include: determining the attention score of the feature vector corresponding to each target pixel in the plurality of target pixels with respect to the feature vector corresponding to the pixel; and based on the corresponding feature vector of each target pixel in the plurality of target pixels.
  • the feature vector of the feature vector corresponds to the attention score of the feature vector corresponding to the pixel, and the feature vectors corresponding to the multiple target pixels are fused to obtain the local feature vector of the pixel.
  • the height of the third feature map may be 1/32 of the height of the image to be recognized.
  • the method of text recognition may further include at least one of the following: fusing the first feature map and the second feature map to update the second feature map; and fusing the third feature map and the fourth feature map to update the second feature map.
  • Four feature maps fusing the first feature map and the second feature map to update the second feature map.
  • a training method of a neural network includes a first convolution subnetwork, a local fusion subnetwork, a second convolution subnetwork, a global fusion subnetwork, and an output subnetwork.
  • the training method includes: step S401, determine the sample image and the corresponding real result; step S402, input the sample image into the first convolution subnetwork, and the first convolution subnetwork is configured to convolve the sample image. product processing to output the first feature map; step S403, input the first feature map into the local fusion sub-network, and the local fusion sub-network is configured to use the self-attention mechanism based on the pixel for each pixel in the first feature map.
  • the corresponding feature vector and the respective feature vectors of the multiple related pixels in the first feature map are used to determine the local feature vector of the pixel to obtain the second feature map; step S404, input the second feature map into the second convolution subnetwork , the second convolution sub-network is configured to perform convolution processing on the second feature map to output the third feature map; step S405, input the third feature map into the global fusion sub-network, and the global fusion sub-network is configured to target the third feature map.
  • the self-attention mechanism is used to determine the global feature vector of the pixel based on the feature vector corresponding to the pixel and the respective feature vectors of each pixel in the third feature map to obtain the fourth feature map.
  • Step S406 input the fourth feature map into the output sub-network, and the output sub-network is configured to output the prediction result of text recognition on the sample image based on the fourth feature map;
  • Step S407 calculate the loss value based on the real result and the prediction result ;
  • step S408, adjust the parameters of the neural network based on the loss value to obtain the trained neural network. It can be understood that the operations of steps S402 to S406 in FIG. 4 are similar to the operations of steps S301 to S305 in FIG. 3 and will not be described again.
  • the network module that utilizes the self-attention mechanism it is possible to process image features in parallel, thereby improving the training speed and prediction speed, and by using the local fusion sub-network and the global fusion sub-network, it is possible to consider the differences between text characters. Local correlation and global correlation, thereby improving prediction accuracy.
  • the use of convolutional subnetworks enables the use of existing deep learning acceleration libraries for acceleration, thereby further improving the training speed and prediction speed of the inference stage.
  • the loss value may include a connectionist temporal classification (CTC) loss value and a center loss value.
  • CTC loss is a commonly used loss value for predicting label sequences, and center loss can provide a category center for each category, minimizing the distance between each sample in each batch and the corresponding category center, thereby making the intra-class distance closer. Small. Therefore, by using CTC loss and center loss, on the one hand, it ensures the model prediction speed and supports variable-length text input. On the other hand, it further explores the correlation between characters and solves the problem of difficulty in distinguishing similar characters between texts.
  • CTC loss connectionist temporal classification
  • At least one of the first convolutional subnetwork and the second convolutional subnetwork may include depthwise separable convolutional layers.
  • the first convolutional subnetwork may include a regular convolutional layer
  • at least one of the first convolutional subnetwork and the second convolutional subnetwork may include a first depthwise separable convolutional layer
  • the second convolutional subnetwork may
  • the product subnetwork may include a second depthwise separable convolutional layer.
  • the size of the convolution kernel used by the first depth-separable convolution layer is smaller than the size of the convolution kernel used by the second depth-separable convolution layer.
  • a self-attention mechanism is used to determine the local feature vector of the pixel based on the feature vector corresponding to the pixel and the respective feature vectors of multiple target pixels in the first feature map.
  • to obtain the second feature map may include: determining the attention score of the feature vector corresponding to each target pixel in the plurality of target pixels with respect to the feature vector corresponding to the pixel; and based on the corresponding feature vector of each target pixel in the plurality of target pixels.
  • the feature vector of the feature vector corresponds to the attention score of the feature vector corresponding to the pixel, and the feature vectors corresponding to the multiple target pixels are fused to obtain the local feature vector of the pixel.
  • the height of the third feature map may be 1/32 of the height of the image to be recognized.
  • the method of text recognition may further include at least one of the following: fusing the first feature map and the second feature map to update the second feature map; and fusing the third feature map and the fourth feature map to update the second feature map.
  • Four feature maps fusing the first feature map and the second feature map to update the second feature map.
  • the collection, storage, use, processing, transmission, provision and disclosure of user personal information are in compliance with relevant laws and regulations and do not violate public order and good customs.
  • an electronic device a readable storage medium, and a computer program product are also provided.
  • Electronic devices are intended to refer to various forms of digital electronic computing equipment, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. Electronic devices may also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smart phones, wearable devices, and other similar computing devices.
  • the components shown herein, their connections and relationships, and their functions are examples only and are not intended to limit implementations of the disclosure described and/or claimed herein.
  • the device 500 includes a computing unit 501 that can execute according to a computer program stored in a read-only memory (ROM) 502 or loaded from a storage unit 508 into a random access memory (RAM) 503 Various appropriate actions and treatments. In the RAM 503, various programs and data required for the operation of the device 500 can also be stored.
  • Computing unit 501, ROM 502 and RAM 503 are connected to each other via bus 504.
  • An input/output (I/O) interface 505 is also connected to bus 504.
  • the input unit 506 may be any type of device capable of inputting information to the device 500.
  • the input unit 506 may receive input numeric or character information and generate key signal input related to user settings and/or function control of the electronic device, and may Including, but not limited to, mouse, keyboard, touch screen, trackpad, trackball, joystick, microphone and/or remote control.
  • Output unit 507 may be any type of device capable of presenting information, and may include, but is not limited to, a display, speakers, video/audio output terminal, vibrator, and/or printer.
  • the storage unit 508 may include, but is not limited to, magnetic disks and optical disks.
  • the communication unit 509 allows the device 500 to exchange information/data with other devices over a computer network such as the Internet and/or various telecommunications networks, and may include, but is not limited to, a modem, a network card, an infrared communication device, a wireless communication transceiver, and/or a chipset , such as BluetoothTM devices, 802.11 devices, WiFi devices, WiMax devices, cellular communication devices and/or the like.
  • Computing unit 501 may be a variety of general and/or special purpose processing components having processing and computing capabilities. Some examples of the computing unit 501 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning network algorithms, digital signal processing processor (DSP), and any appropriate processor, controller, microcontroller, etc.
  • the computing unit 501 performs various methods and processes described above, such as text recognition methods and/or neural network training methods and machine learning model training methods.
  • the text recognition method and/or the neural network training method and the machine learning model training method may be implemented as a computer software program, which is tangibly included in a machine-readable medium, such as the storage unit 508 .
  • part or all of the computer program may be loaded and/or installed onto device 500 via ROM 502 and/or communication unit 509.
  • the computer program When the computer program is loaded into the RAM 503 and executed by the computing unit 501, one or more steps of the text recognition method and/or the neural network training method and the machine learning model training method described above may be performed.
  • the computing unit 501 may be configured to perform the method of text recognition and/or the training method of the neural network and the training of the machine learning model in any other suitable manner (for example, by means of firmware). method.
  • Various implementations of the systems and techniques described above may be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on a chip implemented in a system (SOC), load programmable logic device (CPLD), computer hardware, firmware, software, and/or a combination thereof.
  • FPGAs field programmable gate arrays
  • ASICs application specific integrated circuits
  • ASSPs application specific standard products
  • SOC system
  • CPLD load programmable logic device
  • computer hardware firmware, software, and/or a combination thereof.
  • These various embodiments may include implementation in one or more computer programs executable and/or interpreted on a programmable system including at least one programmable processor, the programmable processor
  • the processor which may be a special purpose or general purpose programmable processor, may receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
  • An output device may be a special purpose or general purpose programmable processor, may receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
  • An output device may be a special purpose or general purpose programmable processor, may receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
  • Program code for implementing the methods of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing device, such that the program codes, when executed by the processor or controller, cause the functions specified in the flowcharts and/or block diagrams/ The operation is implemented.
  • the program code may execute entirely on the machine, partly on the machine, as a stand-alone software package, partly on the machine and partly on a remote machine or entirely on the remote machine or server.
  • a machine-readable medium may be a tangible medium that may contain or store a program for use by or in connection with an instruction execution system, apparatus, or device.
  • the machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium.
  • Machine-readable media may include, but are not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or devices, or any suitable combination of the foregoing.
  • machine-readable storage media would include one or more wire-based electrical connections, laptop disks, hard drives, random access memory (RAM), read only memory (ROM), erasable programmable read only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination of the above.
  • RAM random access memory
  • ROM read only memory
  • EPROM or flash memory erasable programmable read only memory
  • CD-ROM portable compact disk read-only memory
  • magnetic storage device or any suitable combination of the above.
  • the systems and techniques described herein may be implemented on a computer having a display device (eg, a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user ); and a keyboard and pointing device (eg, a mouse or a trackball) through which a user can provide input to the computer.
  • a display device eg, a CRT (cathode ray tube) or LCD (liquid crystal display) monitor
  • a keyboard and pointing device eg, a mouse or a trackball
  • Other kinds of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and may be provided in any form, including Acoustic input, voice input or tactile input) to receive input from the user.
  • the systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., A user's computer having a graphical user interface or web browser through which the user can interact with implementations of the systems and technologies described herein), or including such backend components, middleware components, or any combination of front-end components in a computing system.
  • the components of the system may be interconnected by any form or medium of digital data communication (eg, a communications network). Examples of communication networks include: local area network (LAN), wide area network (WAN), and the Internet.
  • Computer systems may include clients and servers. Clients and servers are generally remote from each other and typically interact over a communications network. The relationship of client and server is created by computer programs running on corresponding computers and having a client-server relationship with each other.
  • the server can be a cloud server, also known as cloud computing server or cloud host. It is a host product in the cloud computing service system to solve the problem of traditional physical host and VPS service ("Virtual Private Server", or "VPS" for short) Among them, there are defects such as difficult management and weak business scalability.
  • the server can also be a distributed system server or a server combined with a blockchain.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Evolutionary Computation (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Artificial Intelligence (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Health & Medical Sciences (AREA)
  • Software Systems (AREA)
  • Molecular Biology (AREA)
  • Computing Systems (AREA)
  • Biophysics (AREA)
  • Biomedical Technology (AREA)
  • Mathematical Physics (AREA)
  • Computational Linguistics (AREA)
  • Health & Medical Sciences (AREA)
  • Bioinformatics & Cheminformatics (AREA)
  • Bioinformatics & Computational Biology (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Evolutionary Biology (AREA)
  • Image Analysis (AREA)

Abstract

Provided in the present disclosure are a neural network used for text recognition, a training method thereof and a text recognition method, relating to the field of artificial intelligence, and particularly relating to computer vision and deep learning technology. The neural network comprises: a first convolutional sub-network configured to output a first feature map on the basis of an image to be recognized; a local fusion sub-network configured to determine, on the basis of a feature vector of each pixel in the first feature map and a feature vector of a plurality of target pixels in the first feature map, local feature vectors of the pixels by means of a self-attention mechanism, so as to obtain a second feature map; a second convolutional sub-network configured to output a third feature map on the basis of the second feature map; a global fusion sub-network configured to determine, on the basis of a feature vector corresponding to each pixel in the third feature map and a feature vector of each pixel itself in the third feature map, global feature vectors of the pixels by using the self-attention mechanism, so as to obtain a fourth feature map; and an output sub-network configured to output a text recognition result on the basis of the fourth feature map.

Description

用于文本识别的神经网络及其训练方法、文本识别的方法Neural network for text recognition and its training method, text recognition method
相关申请的交叉引用Cross-references to related applications
本申请要求于2022年5月18日提交的中国专利申请202210548237.8的优先权,其全部内容通过引用整体结合在本申请中。This application claims priority from Chinese patent application 202210548237.8 filed on May 18, 2022, the entire content of which is incorporated into this application by reference in its entirety.
技术领域Technical field
本公开涉及人工智能领域,具体涉及机器学习技术、计算机视觉技术、图像处理技术和深度学习技术,特别涉及一种用于文本识别的神经网络、利用神经网络进行文本识别的方法、神经网络的训练方法、电子设备、计算机可读存储介质和计算机程序产品。The present disclosure relates to the field of artificial intelligence, specifically to machine learning technology, computer vision technology, image processing technology and deep learning technology, and in particular to a neural network for text recognition, a method of text recognition using a neural network, and the training of a neural network Methods, electronic devices, computer-readable storage media, and computer program products.
背景技术Background technique
人工智能是研究使计算机来模拟人的某些思维过程和智能行为(如学习、推理、思考、规划等)的学科,既有硬件层面的技术也有软件层面的技术。人工智能硬件技术一般包括如传感器、专用人工智能芯片、云计算、分布式存储、大数据处理等技术;人工智能软件技术主要包括计算机视觉技术、语音识别技术、自然语言处理技术以及机器学习/深度学习、大数据处理技术、知识图谱技术等几大方向。Artificial intelligence is the study of using computers to simulate certain human thinking processes and intelligent behaviors (such as learning, reasoning, thinking, planning, etc.). It has both hardware-level technology and software-level technology. Artificial intelligence hardware technology generally includes technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing, etc.; artificial intelligence software technology mainly includes computer vision technology, speech recognition technology, natural language processing technology, and machine learning/depth Learning, big data processing technology, knowledge graph technology and other major directions.
OCR(Optical Character Recognition,光学字符识别)是一项可以将图片信息转换为更易编辑和存储的文本信息的技术。目前被广泛应用于各种场景,如票据识别、银行卡信息识别、公式识别等,此外OCR也帮助了很多下游任务,比如字幕翻译、安全监控等;同时也有助于其他视觉任务,如视频搜索等。OCR (Optical Character Recognition) is a technology that can convert image information into text information that is easier to edit and store. It is currently widely used in various scenarios, such as bill recognition, bank card information recognition, formula recognition, etc. In addition, OCR also helps many downstream tasks, such as subtitle translation, security monitoring, etc.; it also helps other visual tasks, such as video search wait.
在此部分中描述的方法不一定是之前已经设想到或采用的方法。除非另有指明,否则不应假定此部分中描述的任何方法仅因其包括在此部分中就被认为是现有技术。类似地,除非另有指明,否则此部分中提及的问题不应认为在任何现有技术中已被公认。The approaches described in this section are not necessarily those that have been previously envisioned or employed. Unless otherwise indicated, it should not be assumed that any method described in this section is prior art merely by virtue of its inclusion in this section. Similarly, unless otherwise indicated, the issues mentioned in this section should not be considered to be recognized in any prior art.
发明内容Contents of the invention
本公开提供了一种用于文本识别的神经网络、利用神经网络进行文本识别的方法、神经网络的训练方法、电子设备、计算机可读存储介质和计算机程序产品。The present disclosure provides a neural network for text recognition, a method for text recognition using a neural network, a neural network training method, an electronic device, a computer-readable storage medium and a computer program product.
根据本公开的一方面,提供了一种用于文本识别的神经网络,包括:第一卷积子网络,被配置为对待识别图像进行卷积处理,以输出第一特征图;局部融合子网络,被配置为针对第一特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和第一特征图中的多个目标像素各自的特征向量,确定该像素的局部特征向量,以得到第二特征图,其中,多个目标像素包括第一特征图中位于该像素的邻域中的多个像素;第二卷积子网络,被配置为对第二特征图进行卷积处理,以输出第三特征图;全局融合子网络,被配置为针对第三特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和第三特征图中的每一个像素各自的特征向量,确定该像素的全局特征向量,以得到第四特征图;以及输出子网络,被配置为基于第四特征图,输出文本识别结果。According to an aspect of the present disclosure, a neural network for text recognition is provided, including: a first convolution subnetwork configured to perform convolution processing on an image to be recognized to output a first feature map; a local fusion subnetwork , configured to use the self-attention mechanism for each pixel in the first feature map to determine the local feature vector of the pixel based on the feature vector corresponding to the pixel and the respective feature vectors of multiple target pixels in the first feature map. , to obtain the second feature map, wherein the plurality of target pixels include multiple pixels located in the neighborhood of the pixel in the first feature map; the second convolution subnetwork is configured to convolve the second feature map Process to output the third feature map; the global fusion sub-network is configured to target each pixel in the third feature map, using the self-attention mechanism based on the feature vector corresponding to the pixel and each pixel in the third feature map Respective feature vectors determine the global feature vector of the pixel to obtain the fourth feature map; and the output sub-network is configured to output the text recognition result based on the fourth feature map.
根据本公开的另一方面,提供了一种利用神经网络进行文本识别的方法,神经网络包括第一卷积子网络、局部融合子网络、第二卷积子网络、全局融合子网络、以及输出子网络,方法包括:将待识别图像输入第一卷积子网络,第一卷积子网络被配置为对待识别图像进行卷积处理,以输出第一特征图;将第一特征图输入局部融合子网络,局部融合子网络被配置为针对第一特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和第一特征图中的多个目标像素各自的特征向量,确定该像素的局部特征向量,以得到第二特征图,其中,多个目标像素包括第一特征图中位于该像素的邻域中的多个像素;将第二特征图输入第二卷积子网络,第二卷积子网络被配置为对第二特征图进行卷积处理,以输出第三特征图;将第三特征图输入全局融合子网络,全局融合子网络被配置为针对第三特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和第三特征图中的每一个像素各自的特征向量,确定该像素的全局特征向量,以得到第四特征图;以及将第四特征图输入输出子网络,输出子网络被配置为基于第四特征图,输出文本识别结果。According to another aspect of the present disclosure, a method for text recognition using a neural network is provided. The neural network includes a first convolution subnetwork, a local fusion subnetwork, a second convolution subnetwork, a global fusion subnetwork, and an output sub-network, the method includes: inputting the image to be recognized into a first convolution sub-network, the first convolution sub-network being configured to perform convolution processing on the image to be recognized to output a first feature map; inputting the first feature map into local fusion sub-network, the local fusion sub-network is configured to use the self-attention mechanism for each pixel in the first feature map to determine based on the feature vector corresponding to the pixel and the respective feature vectors of multiple target pixels in the first feature map. local feature vector of the pixel to obtain a second feature map, where the plurality of target pixels include multiple pixels located in the neighborhood of the pixel in the first feature map; input the second feature map into the second convolution subnetwork , the second convolution sub-network is configured to perform convolution processing on the second feature map to output the third feature map; the third feature map is input to the global fusion sub-network, and the global fusion sub-network is configured to target the third feature map For each pixel in, use the self-attention mechanism to determine the global feature vector of the pixel based on the feature vector corresponding to the pixel and the respective feature vector of each pixel in the third feature map, to obtain the fourth feature map; and The fourth feature map inputs and outputs the sub-network, and the output sub-network is configured to output the text recognition result based on the fourth feature map.
根据本公开的另一方面,提供了一种神经网络的训练方法,神经网络包括第一卷积子网络、局部融合子网络、第二卷积子网络、全局融合子网络、以及输出子网络,方法包括:确定样本图像和对应的真实结果;将样本图像输入第一卷积子网络,第一卷积子网络被配置为对样本图像进行卷积处理,以输出第一特征图;将第一特征图输入局部融合子网络,局部融合子网络被配置为针对第一特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和第一特征图中的多个目标像素各自的特征向量,确定该像素的局部特征向量,以得到第二特征图,其中,多个目标像素包括第一特征图中位于该像素的邻域中的多个像素;将第二特征图输入第二卷积子网络,第二卷积子网络被配置为对第二特征图进行卷积处理,以输出第三特征图;将第三特征图输入全局融合子网络,全局融合子网络被配置为针对第三特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和第三特征图中的每一个像素各自的特征向量,确定该像素的全局特征向量,以得到第四特征图;将第四特征图输入输出子网络,输出子网络被配置为基于第四特征图,输出对样本图像进行文本识别的预测结果;基于真实结果和预测结果,计算损失值;以及基于损失值调整神经网络的参数,以得到训练后的神经网络。According to another aspect of the present disclosure, a training method for a neural network is provided. The neural network includes a first convolution subnetwork, a local fusion subnetwork, a second convolution subnetwork, a global fusion subnetwork, and an output subnetwork, The method includes: determining the sample image and the corresponding real result; inputting the sample image into a first convolution subnetwork, and the first convolution subnetwork is configured to perform convolution processing on the sample image to output the first feature map; The feature map inputs the local fusion sub-network, and the local fusion sub-network is configured to target each pixel in the first feature map, using the self-attention mechanism based on the feature vector corresponding to the pixel and each of the multiple target pixels in the first feature map. feature vector, determine the local feature vector of the pixel to obtain the second feature map, in which the multiple target pixels include multiple pixels located in the neighborhood of the pixel in the first feature map; input the second feature map into the Two convolution sub-networks, the second convolution sub-network is configured to perform convolution processing on the second feature map to output the third feature map; the third feature map is input to the global fusion sub-network, and the global fusion sub-network is configured as For each pixel in the third feature map, the self-attention mechanism is used to determine the global feature vector of the pixel based on the feature vector corresponding to the pixel and the respective feature vectors of each pixel in the third feature map to obtain the fourth feature map; input the fourth feature map into the output sub-network, and the output sub-network is configured to output the prediction result of text recognition on the sample image based on the fourth feature map; calculate the loss value based on the real result and the prediction result; and based on the loss Adjust the parameters of the neural network to obtain the trained neural network.
根据本公开的另一方面,提供了一种电子设备,包括:至少一个处理器;以及与至少一个处理器通信连接的存储器;其中存储器存储有可被至少一个处理器执行的指令,这些指令被至少一个处理器执行,以使至少一个处理器能够执行上述方法。According to another aspect of the present disclosure, an electronic device is provided, including: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are At least one processor executes, so that at least one processor can execute the above method.
根据本公开的另一方面,提供了一种存储有计算机指令的非瞬时计算机可读存储介质,其中,计算机指令用于使计算机执行上述方法。According to another aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause a computer to perform the above method.
根据本公开的另一方面,提供了一种计算机程序产品,包括计算机程序,其中,计算机程序在被处理器执行时实现上述方法。According to another aspect of the present disclosure, a computer program product is provided, including a computer program, wherein the computer program implements the above method when executed by a processor.
根据本公开的一个或多个实施例,通过使用利用自注意力机制的网络模块,使得能够并行处理图像特征,从而提升训练速度和预测速度,而通过使用局部融合子网络和全局融合子网络,使得能够考虑文字字符之间的局部相关性和全局相关性,从而提升预测精度。此外,通过使用卷积子网 络使得能够利用现有的深度学习加速库进行加速,从而进一步提升训练速度和推理阶段的预测速度。According to one or more embodiments of the present disclosure, by using a network module that utilizes a self-attention mechanism, image features can be processed in parallel, thereby improving training speed and prediction speed, and by using local fusion sub-networks and global fusion sub-networks, This enables the local correlation and global correlation between text characters to be considered, thereby improving prediction accuracy. In addition, the use of convolutional subnetworks enables the use of existing deep learning acceleration libraries for acceleration, thereby further improving the training speed and prediction speed of the inference stage.
应当理解,本部分所描述的内容并非旨在标识本公开的实施例的关键或重要特征,也不用于限制本公开的范围。本公开的其它特征将通过以下的说明书而变得容易理解。It should be understood that what is described in this section is not intended to identify key or important features of the embodiments of the disclosure, nor is it intended to limit the scope of the disclosure. Other features of the present disclosure will become readily understood from the following description.
附图说明Description of the drawings
附图示例性地示出了实施例并且构成说明书的一部分,与说明书的文字描述一起用于讲解实施例的示例性实施方式。所示出的实施例仅出于例示的目的,并不限制权利要求的范围。在所有附图中,相同的附图标记指代类似但不一定相同的要素。The drawings illustrate exemplary embodiments and constitute a part of the specification, and together with the written description, serve to explain exemplary implementations of the embodiments. The embodiments shown are for illustrative purposes only and do not limit the scope of the claims. Throughout the drawings, the same reference numbers refer to similar, but not necessarily identical, elements.
图1示出了根据本公开的实施例的可以在其中实施本文描述的各种方法的示例性系统的示意图;1 illustrates a schematic diagram of an exemplary system in which various methods described herein may be implemented in accordance with embodiments of the present disclosure;
图2示出了根据本公开示例性实施例的用于文本识别的神经网络的结构框图;Figure 2 shows a structural block diagram of a neural network for text recognition according to an exemplary embodiment of the present disclosure;
图3示出了根据本公开示例性实施例的文本识别的方法的流程图;Figure 3 shows a flowchart of a method of text recognition according to an exemplary embodiment of the present disclosure;
图4示出了根据本公开示例性实施例的神经网络的训练方法的流程图;以及Figure 4 shows a flow chart of a training method of a neural network according to an exemplary embodiment of the present disclosure; and
图5出了能够用于实现本公开的实施例的示例性电子设备的结构框图。5 illustrates a structural block diagram of an exemplary electronic device that can be used to implement embodiments of the present disclosure.
具体实施方式Detailed ways
以下结合附图对本公开的示范性实施例做出说明,其中包括本公开实施例的各种细节以助于理解,应当将它们认为仅仅是示范性的。因此,本领域普通技术人员应当认识到,可以对这里描述的实施例做出各种改变和修改,而不会背离本公开的范围。同样,为了清楚和简明,以下的描述中省略了对公知功能和结构的描述。Exemplary embodiments of the present disclosure are described below with reference to the accompanying drawings, in which various details of the embodiments of the present disclosure are included to facilitate understanding and should be considered to be exemplary only. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope of the disclosure. Also, descriptions of well-known functions and constructions are omitted from the following description for clarity and conciseness.
在本公开中,除非另有说明,否则使用术语“第一”、“第二”等来描述各种要素不意图限定这些要素的位置关系、时序关系或重要性关系,这种术语只是用于将一个元件与另一元件区分开。在一些示例中,第一要素和第 二要素可以指向该要素的同一实例,而在某些情况下,基于上下文的描述,它们也可以指代不同实例。In this disclosure, unless otherwise stated, the use of the terms “first”, “second”, etc. to describe various elements is not intended to limit the positional relationship, timing relationship, or importance relationship of these elements. Such terms are only used for Distinguish one element from another. In some examples, the first element and the second element can refer to the same instance of the element, and in some cases, based on contextual description, they can refer to different instances.
在本公开中对各种所述示例的描述中所使用的术语只是为了描述特定示例的目的,而并非旨在进行限制。除非上下文另外明确地表明,如果不特意限定要素的数量,则该要素可以是一个也可以是多个。此外,本公开中所使用的术语“和/或”涵盖所列出的项目中的任何一个以及全部可能的组合方式。The terminology used in the description of the various described examples in this disclosure is for the purpose of describing the particular examples only and is not intended to be limiting. Unless the context clearly indicates otherwise, if the number of elements is not specifically limited, the element may be one or more. Furthermore, the term "and/or" as used in this disclosure encompasses any and all possible combinations of the listed items.
相关技术中,现有的OCR方法通常使用循环神经网络(Recursive Neural Network,RNN)进行序列建模,但RNN存在无法并行训练、训练预测效率较低的问题。In related technologies, existing OCR methods usually use Recursive Neural Network (RNN) for sequence modeling, but RNN has the problem of being unable to be trained in parallel and having low training prediction efficiency.
为解决上述问题,本公开通过使用利用自注意力机制的网络模块,使得能够并行处理图像特征,从而提升训练速度和预测速度,而通过使用局部融合子网络和全局融合子网络,使得能够考虑文字字符之间的局部相关性和全局相关性,从而提升预测精度。此外,通过使用卷积子网络使得能够利用现有的深度学习加速库进行加速,从而进一步提升训练速度和推理阶段的预测速度。In order to solve the above problems, the present disclosure enables parallel processing of image features by using a network module that utilizes a self-attention mechanism, thereby improving training speed and prediction speed, and by using local fusion sub-networks and global fusion sub-networks, allowing text to be considered Local correlation and global correlation between characters, thereby improving prediction accuracy. In addition, the use of convolutional subnetworks enables the use of existing deep learning acceleration libraries for acceleration, thereby further improving the training speed and prediction speed of the inference stage.
下面将结合附图详细描述本公开的实施例。Embodiments of the present disclosure will be described in detail below with reference to the accompanying drawings.
图1示出了根据本公开的实施例可以将本文描述的各种方法和装置在其中实施的示例性系统100的示意图。参考图1,该系统100包括一个或多个客户端设备101、102、103、104、105和106、服务器120以及将一个或多个客户端设备耦接到服务器120的一个或多个通信网络110。客户端设备101、102、103、104、105和106可以被配置为执行一个或多个应用程序。Figure 1 shows a schematic diagram of an exemplary system 100 in which various methods and apparatus described herein may be implemented in accordance with embodiments of the present disclosure. Referring to FIG. 1 , the system 100 includes one or more client devices 101 , 102 , 103 , 104 , 105 , and 106 , a server 120 , and one or more communication networks coupling the one or more client devices to the server 120 110. Client devices 101, 102, 103, 104, 105, and 106 may be configured to execute one or more applications.
在本公开的实施例中,服务器120可以运行使得能够执行文本识别的方法和/或神经网络的训练方法的一个或多个服务或软件应用。In embodiments of the present disclosure, the server 120 may run one or more services or software applications that enable performing methods of text recognition and/or training methods of neural networks.
在某些实施例中,服务器120还可以提供可以包括非虚拟环境和虚拟环境的其他服务或软件应用。在某些实施例中,这些服务可以作为基于web的服务或云服务提供,例如在软件即服务(SaaS)网络下提供给客户端设备101、102、103、104、105和/或106的用户。In some embodiments, server 120 may also provide other services or software applications that may include non-virtual environments and virtual environments. In some embodiments, these services may be provided as web-based services or cloud services, such as under a Software as a Service (SaaS) network to users of client devices 101, 102, 103, 104, 105, and/or 106 .
在图1所示的配置中,服务器120可以包括实现由服务器120执行的功能的一个或多个组件。这些组件可以包括可由一个或多个处理器执行的软 件组件、硬件组件或其组合。操作客户端设备101、102、103、104、105和/或106的用户可以依次利用一个或多个客户端应用程序来与服务器120进行交互以利用这些组件提供的服务。应当理解,各种不同的系统配置是可能的,其可以与系统100不同。因此,图1是用于实施本文所描述的各种方法的系统的一个示例,并且不旨在进行限制。In the configuration shown in FIG. 1 , server 120 may include one or more components that implement the functions performed by server 120 . These components may include software components, hardware components, or combinations thereof that are executable by one or more processors. Users operating client devices 101, 102, 103, 104, 105, and/or 106 may, in turn, utilize one or more client applications to interact with server 120 to utilize services provided by these components. It should be understood that a variety of different system configurations are possible, which may differ from system 100 . Accordingly, Figure 1 is one example of a system for implementing the various methods described herein and is not intended to be limiting.
用户可以使用客户端设备101、102、103、104、105和/或106来进行待识别图像的采集操作。客户端设备可以提供使客户端设备的用户能够与客户端设备进行交互的接口,例如,用户可以使用客户端设备的照相机采集待识别图像,或使用客户端设备向服务器上传客户端设备中存储的图像。客户端设备还可以经由该接口向用户输出信息,例如,客户端可以向用户输出服务器上运行的文本识别方法对用户上传的待识别图像进行识别而得到的文本。尽管图1仅描绘了六种客户端设备,但是本领域技术人员将能够理解,本公开可以支持任何数量的客户端设备。Users can use client devices 101, 102, 103, 104, 105 and/or 106 to perform collection operations of images to be recognized. The client device may provide an interface that enables the user of the client device to interact with the client device. For example, the user may use a camera of the client device to collect an image to be recognized, or use the client device to upload to the server an image stored in the client device. image. The client device can also output information to the user via the interface. For example, the client can output to the user text obtained by recognizing the image to be recognized uploaded by the user using a text recognition method running on the server. Although FIG. 1 depicts only six client devices, those skilled in the art will understand that the present disclosure can support any number of client devices.
客户端设备101、102、103、104、105和/或106可以包括各种类型的计算机设备,例如便携式手持设备、通用计算机(诸如个人计算机和膝上型计算机)、工作站计算机、可穿戴设备、智能屏设备、自助服务终端设备、服务机器人、游戏系统、瘦客户端、各种消息收发设备、传感器或其他感测设备等。这些计算机设备可以运行各种类型和版本的软件应用程序和操作系统,例如MICROSOFT Windows、APPLE iOS、类UNIX操作系统、Linux或类Linux操作系统(例如GOOGLE Chrome OS);或包括各种移动操作系统,例如MICROSOFT Windows Mobile OS、iOS、Windows Phone、Android。便携式手持设备可以包括蜂窝电话、智能电话、平板电脑、个人数字助理(PDA)等。可穿戴设备可以包括头戴式显示器(诸如智能眼镜)和其他设备。游戏系统可以包括各种手持式游戏设备、支持互联网的游戏设备等。客户端设备能够执行各种不同的应用程序,例如各种与Internet相关的应用程序、通信应用程序(例如电子邮件应用程序)、短消息服务(SMS)应用程序,并且可以使用各种通信协议。 Client devices 101, 102, 103, 104, 105, and/or 106 may include various types of computer devices, such as portable handheld devices, general purpose computers (such as personal computers and laptop computers), workstation computers, wearable devices, Smart screen equipment, self-service terminal equipment, service robots, game systems, thin clients, various messaging equipment, sensors or other sensing equipment, etc. These computer devices can run various types and versions of software applications and operating systems, such as MICROSOFT Windows, APPLE iOS, UNIX-like operating systems, Linux or Linux-like operating systems (such as GOOGLE Chrome OS); or include various mobile operating systems , such as MICROSOFT Windows Mobile OS, iOS, Windows Phone, Android. Portable handheld devices may include cellular phones, smart phones, tablet computers, personal digital assistants (PDAs), and the like. Wearable devices may include head-mounted displays (such as smart glasses) and other devices. Gaming systems may include various handheld gaming devices, Internet-enabled gaming devices, and the like. The client device is capable of executing a variety of different applications, such as various Internet-related applications, communication applications (such as email applications), Short Message Service (SMS) applications, and can use various communication protocols.
网络110可以是本领域技术人员熟知的任何类型的网络,其可以使用多种可用协议中的任何一种(包括但不限于TCP/IP、SNA、IPX等)来支持数据通信。仅作为示例,一个或多个网络110可以是局域网(LAN)、基于 以太网的网络、令牌环、广域网(WAN)、因特网、虚拟网络、虚拟专用网络(VPN)、内部网、外部网、公共交换电话网(PSTN)、红外网络、无线网络(例如蓝牙、WIFI)和/或这些和/或其他网络的任意组合。 Network 110 may be any type of network known to those skilled in the art that may support data communications using any of a variety of available protocols (including, but not limited to, TCP/IP, SNA, IPX, etc.). By way of example only, one or more networks 110 may be a local area network (LAN), an Ethernet-based network, a token ring, a wide area network (WAN), the Internet, a virtual network, a virtual private network (VPN), an intranet, an extranet, Public Switched Telephone Network (PSTN), infrared network, wireless network (e.g. Bluetooth, WIFI) and/or any combination of these and/or other networks.
服务器120可以包括一个或多个通用计算机、专用服务器计算机(例如PC(个人计算机)服务器、UNIX服务器、中端服务器)、刀片式服务器、大型计算机、服务器群集或任何其他适当的布置和/或组合。服务器120可以包括运行虚拟操作系统的一个或多个虚拟机,或者涉及虚拟化的其他计算架构(例如可以被虚拟化以维护服务器的虚拟存储设备的逻辑存储设备的一个或多个灵活池)。在各种实施例中,服务器120可以运行提供下文所描述的功能的一个或多个服务或软件应用。 Server 120 may include one or more general purpose computers, special purpose server computers (eg, PC (Personal Computer) servers, UNIX servers, midrange servers), blade servers, mainframe computers, server clusters, or any other suitable arrangement and/or combination . Server 120 may include one or more virtual machines running a virtual operating system, or other computing architecture involving virtualization (eg, one or more flexible pools of logical storage devices that may be virtualized to maintain the server's virtual storage devices). In various embodiments, server 120 may run one or more services or software applications that provide the functionality described below.
服务器120中的计算单元可以运行包括上述任何操作系统以及任何商业上可用的服务器操作系统的一个或多个操作系统。服务器120还可以运行各种附加服务器应用程序和/或中间层应用程序中的任何一个,包括HTTP服务器、FTP服务器、CGI服务器、JAVA服务器、数据库服务器等。Computing units in server 120 may run one or more operating systems, including any of the operating systems described above, as well as any commercially available server operating system. Server 120 may also run any of a variety of additional server applications and/or middle-tier applications, including HTTP servers, FTP servers, CGI servers, JAVA servers, database servers, and the like.
在一些实施方式中,服务器120可以包括一个或多个应用程序,以分析和合并从客户端设备101、102、103、104、105和106的用户接收的数据馈送和/或事件更新。服务器120还可以包括一个或多个应用程序,以经由客户端设备101、102、103、104、105和106的一个或多个显示设备来显示数据馈送和/或实时事件。In some implementations, server 120 may include one or more applications to analyze and incorporate data feeds and/or event updates received from users of client devices 101, 102, 103, 104, 105, and 106. Server 120 may also include one or more applications to display data feeds and/or real-time events via one or more display devices of client devices 101 , 102 , 103 , 104 , 105 , and 106 .
在一些实施方式中,服务器120可以为分布式系统的服务器,或者是结合了区块链的服务器。服务器120也可以是云服务器,或者是带人工智能技术的智能云计算服务器或智能云主机。云服务器是云计算服务体系中的一项主机产品,以解决传统物理主机与虚拟专用服务器(VPS,Virtual Private Server)服务中存在的管理难度大、业务扩展性弱的缺陷。In some implementations, the server 120 may be a server of a distributed system, or a server combined with a blockchain. The server 120 may also be a cloud server, or an intelligent cloud computing server or intelligent cloud host with artificial intelligence technology. Cloud server is a host product in the cloud computing service system to solve the shortcomings of difficult management and weak business scalability in traditional physical host and virtual private server (VPS) services.
系统100还可以包括一个或多个数据库130。在某些实施例中,这些数据库可以用于存储数据和其他信息。例如,数据库130中的一个或多个可用于存储诸如音频文件和视频文件的信息。数据库130可以驻留在各种位置。例如,由服务器120使用的数据存储库可以在服务器120本地,或者可以远离服务器120且可以经由基于网络或专用的连接与服务器120通信。数据库130可以是不同的类型。在某些实施例中,由服务器120使用的数据库可以 是数据库,例如关系数据库。这些数据库中的一个或多个可以响应于命令而存储、更新和检索到数据库以及来自数据库的数据。 System 100 may also include one or more databases 130. In some embodiments, these databases may be used to store data and other information. For example, one or more of databases 130 may be used to store information such as audio files and video files. Database 130 may reside in various locations. For example, a data repository used by server 120 may be local to server 120, or may be remote from server 120 and may communicate with server 120 via a network-based or dedicated connection. Database 130 may be of different types. In some embodiments, the database used by server 120 may be a database, such as a relational database. One or more of these databases may store, update, and retrieve data to and from the database in response to commands.
在某些实施例中,数据库130中的一个或多个还可以由应用程序使用来存储应用程序数据。由应用程序使用的数据库可以是不同类型的数据库,例如键值存储库,对象存储库或由文件系统支持的常规存储库。In some embodiments, one or more of databases 130 may also be used by applications to store application data. The database used by the application can be different types of databases such as key-value repositories, object repositories or regular repositories backed by a file system.
图1的系统100可以以各种方式配置和操作,以使得能够应用根据本公开所描述的各种方法和装置。The system 100 of Figure 1 may be configured and operated in various ways to enable the application of the various methods and apparatus described in accordance with the present disclosure.
根据本公开的一方面,提供了一种神经网络。如图2所示,神经网络200包括:第一卷积子网络204,被配置为对待识别图像202进行卷积处理,以输出第一特征图;局部融合子网络206,被配置为针对第一特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和第一特征图中的多个目标像素各自的特征向量,确定该像素的局部特征向量,以得到第二特征图,其中,多个目标像素包括第一特征图中位于该像素的邻域中的多个像素;第二卷积子网络208,被配置为对第二特征图进行卷积处理,以输出第三特征图;全局融合子网络210,被配置为针对第三特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和第三特征图中的每一个像素各自的特征向量,确定该像素的全局特征向量,以得到第四特征图;以及输出子网络212,被配置为基于第四特征图,输出文本识别结果214。According to one aspect of the present disclosure, a neural network is provided. As shown in Figure 2, the neural network 200 includes: a first convolution sub-network 204 configured to perform convolution processing on the image to be recognized 202 to output a first feature map; a local fusion sub-network 206 configured to perform convolution processing on the first feature map. For each pixel in the feature map, the self-attention mechanism is used to determine the local feature vector of the pixel based on the feature vector corresponding to the pixel and the feature vectors of multiple target pixels in the first feature map to obtain the second feature map. , wherein the plurality of target pixels include multiple pixels located in the neighborhood of the pixel in the first feature map; the second convolution subnetwork 208 is configured to perform convolution processing on the second feature map to output a third Feature map; the global fusion sub-network 210 is configured to use a self-attention mechanism for each pixel in the third feature map based on the feature vector corresponding to the pixel and the respective feature vector of each pixel in the third feature map, Determine the global feature vector of the pixel to obtain a fourth feature map; and the output sub-network 212 is configured to output the text recognition result 214 based on the fourth feature map.
由此,通过使用利用自注意力机制的网络模块,使得能够并行处理图像特征,从而提升训练速度和预测速度,而通过使用局部融合子网络和全局融合子网络,使得能够考虑文字字符之间的局部相关性和全局相关性,从而提升预测精度。此外,通过使用卷积子网络使得能够利用现有的深度学习加速库例如用于深度神经网络的数学内核库(Math Kernel Library for Deep Neural Networks,MKL-DNN)进行加速,从而进一步提升训练速度和推理阶段的预测速度。Therefore, by using the network module that utilizes the self-attention mechanism, it is possible to process image features in parallel, thereby improving the training speed and prediction speed, and by using the local fusion sub-network and the global fusion sub-network, it is possible to consider the differences between text characters. Local correlation and global correlation, thereby improving prediction accuracy. In addition, the use of convolutional subnetworks enables the use of existing deep learning acceleration libraries such as the Math Kernel Library for Deep Neural Networks (MKL-DNN) for acceleration, thereby further improving training speed and Prediction speed during the inference phase.
根据一些实施例,本公开的神经网络及其训练方法和文本识别方法可以适用于任意文本识别场景,包含中文、英文、多语言等等。According to some embodiments, the neural network and its training method and text recognition method of the present disclosure can be applied to any text recognition scenario, including Chinese, English, multi-language, and so on.
根据一些实施例,待识别图像可以是任意包含文本的图像。如上,待识别图像可以是由客户端设备的照相机拍摄的图像,也可以是客户端设备上已经存储的图像,或者以其他方式获取到的图像,在此不做限定。According to some embodiments, the image to be recognized may be any image containing text. As mentioned above, the image to be recognized may be an image captured by the camera of the client device, an image already stored on the client device, or an image obtained in other ways, which is not limited here.
在一些实施例中,由于文本通常为长条形,因此可以对输入神经网络的待识别图像的尺寸进行限定。在一个示例性实施例中,该尺寸为32×320。可以理解的是,可以根据实际的需求设置不同的输入尺寸。在一些实施例中,可以在第一卷积子网络之前设置预处理子网络以对接收到的原始图像进行预处理,从而能够得到满足输入尺寸和/或满足其他输入要求的待识别图像。In some embodiments, since text is usually in the shape of a long strip, the size of the image to be recognized that is input to the neural network can be limited. In an exemplary embodiment, the size is 32×320. It is understandable that different input sizes can be set according to actual needs. In some embodiments, a preprocessing subnetwork can be set before the first convolutional subnetwork to preprocess the received original image, so that an image to be recognized that meets the input size and/or meets other input requirements can be obtained.
根据一些实施例,第一卷积子网络和第二卷积子网络中的至少一者可以包括深度可分离卷积层。深度可分离卷积层对接收到的特征图的操作可以分为两步:第一步对原特征图的每个通道分别使用对应的N×N×1的卷积核进行处理,以得到和原特征图的尺寸相同的中间特征图;第二步使用k个1×1的卷积核对中间特征图进行处理,以得到和原特征图的宽高均相同,但深度为k的特征图。使用深度可分离卷积能够大幅降低乘法运算次数,从而显著降低计算成本,并且能够降低需要存储的参数量。According to some embodiments, at least one of the first convolutional subnetwork and the second convolutional subnetwork may include depthwise separable convolutional layers. The operation of the depthwise separable convolution layer on the received feature map can be divided into two steps: the first step is to use the corresponding N×N×1 convolution kernel to process each channel of the original feature map to obtain the sum The intermediate feature map has the same size as the original feature map; in the second step, k 1×1 convolution kernels are used to process the intermediate feature map to obtain a feature map with the same width and height as the original feature map, but with a depth of k. Using depthwise separable convolutions can significantly reduce the number of multiplication operations, thereby significantly reducing computational costs and reducing the amount of parameters that need to be stored.
根据一些实施例,第一卷积子网络还可以包括常规卷积层,从而更好地从待识别图像中提取图像特征信息。第一卷积子网络和第二卷积子网络中的至少一个可以包括第一深度可分离卷积层,第二卷积子网络可以包括第二深度可分离卷积层。第一深度可分离卷积层的卷积核的尺寸可以小于第二深度可分离卷积层的卷积核的尺寸。在一个示例性实施例中,第一深度可分离卷积层的卷积核的尺寸可以为3×3,第二深度可分离卷积层的卷积核可以为5×5。由此,通过逐步加大感受野的尺寸,能够充分学习到待识别图像的深层语义特征。According to some embodiments, the first convolutional sub-network may also include a conventional convolutional layer to better extract image feature information from the image to be recognized. At least one of the first convolutional subnetwork and the second convolutional subnetwork may include a first depthwise separable convolutional layer, and the second convolutional subnetwork may include a second depthwise separable convolutional layer. The size of the convolution kernel of the first depth-separable convolution layer may be smaller than the size of the convolution kernel of the second depth-separable convolution layer. In an exemplary embodiment, the size of the convolution kernel of the first depth-separable convolution layer may be 3×3, and the size of the convolution kernel of the second depth-separable convolution layer may be 5×5. As a result, by gradually increasing the size of the receptive field, the deep semantic features of the image to be recognized can be fully learned.
在一些实施例中,在部分层之后,还可以使用压缩和激发网络(Squeeze-and-Excitation Net,SENet)的方式对得到的特征图进行处理,以进一步强化特征。In some embodiments, after some layers, the obtained feature map can also be processed using a compression and excitation network (Squeeze-and-Excitation Net, SENet) to further enhance the features.
在一些实施例中,第一卷积子网络和第二卷积子网络各自可以为适用于中央处理器(Central Processing Unit,CPU)的飞桨超轻量卷积神经网络(PaddlePaddle based Lightweight CPU Convolutional Neural Network,PP- LCNet)的一部分。PP-LCNet是一种轻量化的网络,使用的参数较少,训练和推理阶段的计算量较小,并且可以使用MKL-DNN进行CPU运行层面的优化,因此可以用于对性能要求较高的任务场景。OCR任务通常需要快速得到准确的文本识别结果,因此使用PP-LCNet能充分发挥其上述优势。In some embodiments, each of the first convolutional subnetwork and the second convolutional subnetwork may be a PaddlePaddle based Lightweight CPU Convolutional Neural Network (PaddlePaddle based Lightweight CPU Convolutional) suitable for a Central Processing Unit (CPU). Neural Network, part of PP-LCNet). PP-LCNet is a lightweight network that uses fewer parameters and requires less calculation in the training and inference stages. MKL-DNN can be used for optimization at the CPU operation level, so it can be used for applications with higher performance requirements. Mission scenario. OCR tasks usually require rapid and accurate text recognition results, so using PP-LCNet can give full play to its above advantages.
PP-LCNet包括5个阶段(Stage),其中:PP-LCNet includes 5 stages (Stage), including:
阶段1包括一个常规卷积层,卷积核为3×3,步长为2;Stage 1 consists of a regular convolutional layer with a convolution kernel of 3×3 and a stride of 2;
阶段2包括两个深度可分离卷积层,卷积核为3×3,步长分别为1和2;Stage 2 includes two depthwise separable convolutional layers with a convolution kernel of 3×3 and strides of 1 and 2 respectively;
阶段3包括两个深度可分离卷积层,卷积核为3×3,步长分别为1和2;Stage 3 includes two depthwise separable convolutional layers with a convolution kernel of 3×3 and strides of 1 and 2 respectively;
阶段4包括两个深度可分离卷积层,卷积核为3×3,步长分别为1和2;Stage 4 includes two depthwise separable convolutional layers with a convolution kernel of 3×3 and strides of 1 and 2 respectively;
阶段5包括七个深度可分离卷积层,卷积核为5×5,前5个卷积层和第七个卷积层的步长为1,第六个卷积层的步长为2,第六个卷积层和第七个卷积层之后使用SENet(也可以称作SE模块)。Stage 5 consists of seven depthwise separable convolutional layers with a convolution kernel of 5 × 5. The first five convolutional layers and the seventh convolutional layer have a stride of 1, and the sixth convolutional layer has a stride of 2. , SENet (also called SE module) is used after the sixth and seventh convolutional layers.
在一些实施例中,可以在阶段1和2之间、阶段2和3之间、阶段3和4之间、以及阶段4和5之间四个位置中的一个或多个位置加入局部融合子网络。In some embodiments, local fusion agents may be added at one or more of the four positions between stages 1 and 2, between stages 2 and 3, between stages 3 and 4, and between stages 4 and 5. network.
局部融合子网络的数量越多,模型的推理速度越慢。经试验,放入一个局部融合子网络即能显著提升准确率。此外,局部融合子网络接近神经网络的输入端会使得计算量显著增加(相邻的两个卷积层/阶段输出的特征图的像素数成四倍甚至四的指数倍关系,并且越靠近输入端差值越大),而接近神经网络的输出端会一定程度降低准确率。经试验,在阶段3和4之间加入局部融合子网络能够达到两者间的最佳平衡,从而以较少的时间代价显著提升神经网络的推理精度。The larger the number of locally fused subnetworks, the slower the model's inference speed. After experiments, adding a local fusion sub-network can significantly improve the accuracy. In addition, the local fusion sub-network is close to the input end of the neural network, which will significantly increase the amount of calculation (the number of pixels in the feature map output by two adjacent convolutional layers/stages is four times or even an exponential multiple of four, and the closer it is to the input The greater the end difference), and being close to the output end of the neural network will reduce the accuracy to a certain extent. After testing, adding a local fusion sub-network between stages 3 and 4 can achieve the best balance between the two, thereby significantly improving the inference accuracy of the neural network at a reduced time cost.
根据一些实施例,针对第一特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和第一特征图中的多个目标像素各自的特征向量确定该像素的局部特征向量,以得到第二特征图可以包括:确定多个目标像素中的每一个目标像素对应的特征向量关于该像素对应的特征向量的注意力得分;以及基于多个目标像素中的每一个目标像素对应的特征向 量关于与该像素对应的特征向量的注意力得分,将多个目标像素各自对应的特征向量进行融合,以得到的该像素的局部特征向量。由此,实现了对第一特征图中的每一个像素的局部邻域中的像素利用自注意力机制进行融合,获取到了笔画间的局部特征,从而强化了该像素的特征向量。According to some embodiments, for each pixel in the first feature map, a self-attention mechanism is used to determine the local feature vector of the pixel based on the feature vector corresponding to the pixel and the respective feature vectors of multiple target pixels in the first feature map. , to obtain the second feature map may include: determining the attention score of the feature vector corresponding to each target pixel in the plurality of target pixels with respect to the feature vector corresponding to the pixel; and based on the corresponding feature vector of each target pixel in the plurality of target pixels. The feature vector of the feature vector corresponds to the attention score of the feature vector corresponding to the pixel, and the feature vectors corresponding to the multiple target pixels are fused to obtain the local feature vector of the pixel. As a result, the pixels in the local neighborhood of each pixel in the first feature map are fused using the self-attention mechanism, and the local features between strokes are obtained, thus strengthening the feature vector of the pixel.
上述对该像素的特征向量和多个目标像素各自对应的特征向量的处理方法可以参照现有技术中Transformer块对不同的输入特征的操作。通过使用利用自注意力机制的方法,一方面可以提升推理精度,另一方面可以对特征进行并行处理,以加快训练过程并提升推理速度。The above-mentioned processing method of the feature vector of the pixel and the feature vectors corresponding to the multiple target pixels can refer to the operation of the Transformer block on different input features in the prior art. By using methods that utilize the self-attention mechanism, on the one hand, the inference accuracy can be improved, and on the other hand, features can be processed in parallel to speed up the training process and improve the inference speed.
在一些实施例中,可以根据需求设置局部邻域的范围,例如以目标像素为中心的、具有预设宽度和预设高度的矩形区域。预设宽度和预设高度的具体取值也可以根据需求进行确定。可以理解的是,也可以设置其他形状或其他范围的局部邻域,在此不做限定。In some embodiments, the range of the local neighborhood can be set according to requirements, such as a rectangular area with a preset width and a preset height centered on the target pixel. The specific values of the preset width and preset height can also be determined according to needs. It can be understood that local neighborhoods of other shapes or other ranges can also be set, which are not limited here.
在一些实施例中,局部融合子网络不会改变特征图的尺寸。也就是说,第一特征图和第二特征图的尺寸相同。In some embodiments, the local fusion sub-network does not change the size of the feature map. That is, the first feature map and the second feature map have the same size.
在一些实施例中,得到第三特征图后可以直接使用全局融合子网络对其进行处理,也可以先使用一个卷积层对其尺寸进行变换后,再使用全局融合子网络对尺寸变换后的第三特征图进行处理。在一个示例性实施例中,待识别图像的尺寸为H×W,第二卷积子网络输出的第三特征图的的尺寸为H/32×W/4,进一步使用卷积层处理后的尺寸变换后的第三特征图的尺寸为H/32×W/8。In some embodiments, after obtaining the third feature map, you can directly use the global fusion sub-network to process it, or you can first use a convolution layer to transform its size, and then use the global fusion sub-network to transform the size of the third feature map. The third feature map is processed. In an exemplary embodiment, the size of the image to be recognized is H×W, the size of the third feature map output by the second convolution subnetwork is H/32×W/4, and the size of the third feature map output by the second convolution subnetwork is H/32×W/4, and the size after further processing using the convolution layer is The size of the third feature map after size transformation is H/32×W/8.
根据一些实施例,第三特征图的高度可以为待识别图像的高度的1/32。在待识别图像高度为32的实施例中,第三特征图的高度可以为1。可以理解的是,这里的第三特征图可以是由第二卷积子网络输出的第三特征图,也可以是经过尺寸变换后的第三特征图。这样进行设置是考虑到全局融合子网络的预测速度与其接收到的特征的形状/尺寸高度敏感,因此通过限定输入的特征形状能够提升其预测速度,进而提升整体的文本识别速度。实际上,高度为1的第三特征图本质上等同于特征向量序列,序列中的每一个特征向量对应待识别图像中的若干连续列的像素所构成的图像区域。According to some embodiments, the height of the third feature map may be 1/32 of the height of the image to be recognized. In an embodiment where the height of the image to be recognized is 32, the height of the third feature map may be 1. It can be understood that the third feature map here may be the third feature map output by the second convolution subnetwork, or it may be the third feature map after size transformation. This setting is based on the fact that the prediction speed of the global fusion subnetwork is highly sensitive to the shape/size of the features it receives. Therefore, by limiting the input feature shape, its prediction speed can be improved, thereby improving the overall text recognition speed. In fact, the third feature map with a height of 1 is essentially equivalent to a feature vector sequence, and each feature vector in the sequence corresponds to an image area composed of several consecutive columns of pixels in the image to be recognized.
在得到第三特征图后,可以使用同样基于自注意力机制的全局融合子网络对第三特征图进行处理。可以理解的是,全局融合子网络处理第三特 征图的方式与局部融合子网络处理第一特征图的方式类似,区别在于全局融合子网络针对第三特征图中的每一个目标像素,计算和第三特征图中的每个像素对应的注意力得分,并根据每个像素的注意力得分将所有像素的特征向量进行融合,以强化该目标像素的特征向量。全局融合子网络能够实现对全局特征的合并。After obtaining the third feature map, the global fusion sub-network also based on the self-attention mechanism can be used to process the third feature map. It can be understood that the way the global fusion sub-network processes the third feature map is similar to the way the local fusion sub-network processes the first feature map. The difference is that the global fusion sub-network calculates the sum for each target pixel in the third feature map. Each pixel in the third feature map corresponds to the attention score, and the feature vectors of all pixels are fused according to the attention score of each pixel to strengthen the feature vector of the target pixel. The global fusion sub-network can achieve the merging of global features.
在一些实施例中,全局融合子网络同样不会改变特征图的尺寸。也就是说,第三特征图和第四特征图的尺寸相同。在一个示例性实施例中,第三特征图和第四特征图的尺寸均为1×40。In some embodiments, the global fusion sub-network also does not change the size of the feature map. In other words, the third feature map and the fourth feature map have the same size. In an exemplary embodiment, the size of the third feature map and the fourth feature map are both 1×40.
根据一些实施例,神经网络还可以包括以下中的至少一者:第一融合层,被配置为融合第一特征图和第二特征图以更新第二特征图;以及第二融合层,被配置为融合第三特征图和第四特征图以更新第四特征图。由此,通过上述融合层(即,跳跃连接),进一步丰富了特征图的表征,使得其同时包括深层和浅层的语义信息,从而提升了推理结果的准确性。According to some embodiments, the neural network may further include at least one of the following: a first fusion layer configured to fuse the first feature map and the second feature map to update the second feature map; and a second fusion layer configured To fuse the third feature map and the fourth feature map to update the fourth feature map. As a result, through the above-mentioned fusion layer (i.e., skip connection), the representation of the feature map is further enriched so that it includes both deep and shallow semantic information, thereby improving the accuracy of the inference results.
根据一些实施例,输出子网络可以为任意能够基于特征图输出文本识别结果的网络结构。在一个示例性实施例中,输出子网络可以是全连接层或多层感知机。可以理解的是,也可以使用其他的网络结构作为输出子网络,在此不做限定。According to some embodiments, the output subnetwork can be any network structure capable of outputting text recognition results based on feature maps. In an exemplary embodiment, the output sub-network may be a fully connected layer or a multi-layer perceptron. It can be understood that other network structures can also be used as output subnetworks, which are not limited here.
根据本公开的另一方面,提供了一种利用神经网络进行文本识别的方法。神经网络包括第一卷积子网络、局部融合子网络、第二卷积子网络、全局融合子网络、以及输出子网络。如图3所示,该方法包括:步骤S301、将待识别图像输入第一卷积子网络,第一卷积子网络被配置为对待识别图像进行卷积处理,以输出第一特征图;步骤S302、将第一特征图输入局部融合子网络,局部融合子网络被配置为针对第一特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和第一特征图中的多个目标像素各自的特征向量,确定该像素的局部特征向量,以得到第二特征图,其中,多个目标像素包括第一特征图中位于该像素的邻域中的多个像素;步骤S303、将第二特征图输入第二卷积子网络,第二卷积子网络被配置为对第二特征图进行卷积处理,以输出第三特征图;步骤S304、将第三特征图输入全局融合子网络,全局融合子网络被配置为针对第三特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和第三特征图中 的每一个像素各自的特征向量,确定该像素的全局特征向量,以得到第四特征图;以及步骤S305、将第四特征图输入输出子网络,输出子网络被配置为基于第四特征图,输出文本识别结果。According to another aspect of the present disclosure, a method for text recognition using a neural network is provided. The neural network includes a first convolution subnetwork, a local fusion subnetwork, a second convolution subnetwork, a global fusion subnetwork, and an output subnetwork. As shown in Figure 3, the method includes: step S301, input the image to be recognized into the first convolution subnetwork, and the first convolution subnetwork is configured to perform convolution processing on the image to be recognized to output the first feature map; Step S302. Input the first feature map into the local fusion sub-network. The local fusion sub-network is configured to use the self-attention mechanism for each pixel in the first feature map based on the feature vector corresponding to the pixel and the first feature map. The respective feature vectors of multiple target pixels are used to determine the local feature vector of the pixel to obtain the second feature map, where the multiple target pixels include multiple pixels located in the neighborhood of the pixel in the first feature map; step S303 , input the second feature map into the second convolution sub-network, and the second convolution sub-network is configured to perform convolution processing on the second feature map to output the third feature map; Step S304, input the third feature map into the global Fusion sub-network, the global fusion sub-network is configured to use the self-attention mechanism for each pixel in the third feature map to determine based on the feature vector corresponding to the pixel and the respective feature vector of each pixel in the third feature map. The global feature vector of the pixel is used to obtain the fourth feature map; and step S305, input the fourth feature map into the output sub-network, and the output sub-network is configured to output the text recognition result based on the fourth feature map.
可以理解的是,图3中的步骤S301-步骤S305的操作分别和神经网络200中的子网络204-子网络212的操作类似,在此不做赘述。It can be understood that the operations of steps S301 to S305 in FIG. 3 are similar to the operations of subnetwork 204 to subnetwork 212 in the neural network 200, respectively, and will not be described again.
由此,通过使用利用自注意力机制的网络模块,使得能够并行处理图像特征,从而提升预测速度,而通过使用局部融合子网络和全局融合子网络,使得能够考虑文字字符之间的局部相关性和全局相关性,从而提升预测精度。此外,通过使用卷积子网络使得能够利用现有的深度学习加速库进行加速,从而进一步提升推理阶段的预测速度。Therefore, by using the network module that utilizes the self-attention mechanism, image features can be processed in parallel, thereby improving the prediction speed, and by using the local fusion sub-network and the global fusion sub-network, the local correlation between text characters can be considered and global correlation, thereby improving prediction accuracy. In addition, the use of convolutional subnetworks enables the use of existing deep learning acceleration libraries for acceleration, thereby further improving the prediction speed of the inference stage.
根据一些实施例,第一卷积子网络和第二卷积子网络中的至少一者可以包括深度可分离卷积层。According to some embodiments, at least one of the first convolutional subnetwork and the second convolutional subnetwork may include depthwise separable convolutional layers.
根据一些实施例,第一卷积子网络可以包括常规卷积层,第一卷积子网络和第二卷积子网络中的至少一者可以包括第一深度可分离卷积层,第二卷积子网络可以包括第二深度可分离卷积层。第一深度可分离卷积层所使用的卷积核的尺寸小于第二深度可分离卷积层所使用的卷积核的尺寸。According to some embodiments, the first convolutional subnetwork may include a regular convolutional layer, at least one of the first convolutional subnetwork and the second convolutional subnetwork may include a first depthwise separable convolutional layer, and the second convolutional subnetwork may The product subnetwork may include a second depthwise separable convolutional layer. The size of the convolution kernel used by the first depth-separable convolution layer is smaller than the size of the convolution kernel used by the second depth-separable convolution layer.
根据一些实施例,针对第一特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和第一特征图中的多个目标像素各自的特征向量确定该像素的局部特征向量,以得到第二特征图可以包括:确定多个目标像素中的每一个目标像素对应的特征向量关于该像素对应的特征向量的注意力得分;以及基于多个目标像素中的每一个目标像素对应的特征向量关于与该像素对应的特征向量的注意力得分,将多个目标像素各自对应的特征向量进行融合,以得到的该像素的局部特征向量。According to some embodiments, for each pixel in the first feature map, a self-attention mechanism is used to determine the local feature vector of the pixel based on the feature vector corresponding to the pixel and the respective feature vectors of multiple target pixels in the first feature map. , to obtain the second feature map may include: determining the attention score of the feature vector corresponding to each target pixel in the plurality of target pixels with respect to the feature vector corresponding to the pixel; and based on the corresponding feature vector of each target pixel in the plurality of target pixels. The feature vector of the feature vector corresponds to the attention score of the feature vector corresponding to the pixel, and the feature vectors corresponding to the multiple target pixels are fused to obtain the local feature vector of the pixel.
根据一些实施例,第三特征图的高度可以为待识别图像的高度的1/32。According to some embodiments, the height of the third feature map may be 1/32 of the height of the image to be recognized.
根据一些实施例,文本识别的方法还可以包括以下中的至少一者:融合第一特征图和第二特征图以更新第二特征图;以及融合第三特征图和第四特征图以更新第四特征图。According to some embodiments, the method of text recognition may further include at least one of the following: fusing the first feature map and the second feature map to update the second feature map; and fusing the third feature map and the fourth feature map to update the second feature map. Four feature maps.
根据本公开的另一方面,提供了一种神经网络的训练方法。神经网络包括第一卷积子网络、局部融合子网络、第二卷积子网络、全局融合子网络、以及输出子网络。如图4所示,训练方法包括:步骤S401、确定样本 图像和对应的真实结果;步骤S402、将样本图像输入第一卷积子网络,第一卷积子网络被配置为对样本图像进行卷积处理,以输出第一特征图;步骤S403、将第一特征图输入局部融合子网络,局部融合子网络被配置为针对第一特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和第一特征图中的多个相关像素各自的特征向量,确定该像素的局部特征向量,以得到第二特征图;步骤S404、将第二特征图输入第二卷积子网络,第二卷积子网络被配置为对第二特征图进行卷积处理,以输出第三特征图;步骤S405、将第三特征图输入全局融合子网络,全局融合子网络被配置为针对第三特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和第三特征图中的每一个像素各自的特征向量,确定该像素的全局特征向量,以得到第四特征图;步骤S406、将第四特征图输入输出子网络,输出子网络被配置为基于第四特征图,输出对样本图像进行文本识别的预测结果;步骤S407、基于真实结果和预测结果,计算损失值;以及步骤S408、基于损失值调整神经网络的参数,以得到训练后的神经网络。可以理解的是,图4中的步骤S402-步骤S406的操作和图3中的步骤S301-步骤S305的操作类似,在此不做赘述。According to another aspect of the present disclosure, a training method of a neural network is provided. The neural network includes a first convolution subnetwork, a local fusion subnetwork, a second convolution subnetwork, a global fusion subnetwork, and an output subnetwork. As shown in Figure 4, the training method includes: step S401, determine the sample image and the corresponding real result; step S402, input the sample image into the first convolution subnetwork, and the first convolution subnetwork is configured to convolve the sample image. product processing to output the first feature map; step S403, input the first feature map into the local fusion sub-network, and the local fusion sub-network is configured to use the self-attention mechanism based on the pixel for each pixel in the first feature map. The corresponding feature vector and the respective feature vectors of the multiple related pixels in the first feature map are used to determine the local feature vector of the pixel to obtain the second feature map; step S404, input the second feature map into the second convolution subnetwork , the second convolution sub-network is configured to perform convolution processing on the second feature map to output the third feature map; step S405, input the third feature map into the global fusion sub-network, and the global fusion sub-network is configured to target the third feature map. For each pixel in the three feature maps, the self-attention mechanism is used to determine the global feature vector of the pixel based on the feature vector corresponding to the pixel and the respective feature vectors of each pixel in the third feature map to obtain the fourth feature map. ; Step S406, input the fourth feature map into the output sub-network, and the output sub-network is configured to output the prediction result of text recognition on the sample image based on the fourth feature map; Step S407, calculate the loss value based on the real result and the prediction result ; and step S408, adjust the parameters of the neural network based on the loss value to obtain the trained neural network. It can be understood that the operations of steps S402 to S406 in FIG. 4 are similar to the operations of steps S301 to S305 in FIG. 3 and will not be described again.
由此,通过使用利用自注意力机制的网络模块,使得能够并行处理图像特征,从而提升训练速度和预测速度,而通过使用局部融合子网络和全局融合子网络,使得能够考虑文字字符之间的局部相关性和全局相关性,从而提升预测精度。此外,通过使用卷积子网络使得能够利用现有的深度学习加速库进行加速,从而进一步提升训练速度和推理阶段的预测速度。Therefore, by using the network module that utilizes the self-attention mechanism, it is possible to process image features in parallel, thereby improving the training speed and prediction speed, and by using the local fusion sub-network and the global fusion sub-network, it is possible to consider the differences between text characters. Local correlation and global correlation, thereby improving prediction accuracy. In addition, the use of convolutional subnetworks enables the use of existing deep learning acceleration libraries for acceleration, thereby further improving the training speed and prediction speed of the inference stage.
根据一些实施例,损失值可以包括连接时序分类(Connectionist temporal classification,CTC)损失值和中心损失值。CTC损失是常用的预测标签序列的损失值,而中心损失能够为每一个类别提供一个类别中心,最小化每一个批(batch)中每个样本与对应类别中心的距离,从而使得类内距离更小。因此,通过使用CTC损失和中心损失,一方面保证了模型预测速度,支持变长文本输入,另一方面进一步挖掘字符之间的相关性,解决了文本之间形近字难以辨别的问题。According to some embodiments, the loss value may include a connectionist temporal classification (CTC) loss value and a center loss value. CTC loss is a commonly used loss value for predicting label sequences, and center loss can provide a category center for each category, minimizing the distance between each sample in each batch and the corresponding category center, thereby making the intra-class distance closer. Small. Therefore, by using CTC loss and center loss, on the one hand, it ensures the model prediction speed and supports variable-length text input. On the other hand, it further explores the correlation between characters and solves the problem of difficulty in distinguishing similar characters between texts.
根据一些实施例,第一卷积子网络和第二卷积子网络中的至少一者可以包括深度可分离卷积层。According to some embodiments, at least one of the first convolutional subnetwork and the second convolutional subnetwork may include depthwise separable convolutional layers.
根据一些实施例,第一卷积子网络可以包括常规卷积层,第一卷积子网络和第二卷积子网络中的至少一者可以包括第一深度可分离卷积层,第二卷积子网络可以包括第二深度可分离卷积层。第一深度可分离卷积层所使用的卷积核的尺寸小于第二深度可分离卷积层所使用的卷积核的尺寸。According to some embodiments, the first convolutional subnetwork may include a regular convolutional layer, at least one of the first convolutional subnetwork and the second convolutional subnetwork may include a first depthwise separable convolutional layer, and the second convolutional subnetwork may The product subnetwork may include a second depthwise separable convolutional layer. The size of the convolution kernel used by the first depth-separable convolution layer is smaller than the size of the convolution kernel used by the second depth-separable convolution layer.
根据一些实施例,针对第一特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和第一特征图中的多个目标像素各自的特征向量确定该像素的局部特征向量,以得到第二特征图可以包括:确定多个目标像素中的每一个目标像素对应的特征向量关于该像素对应的特征向量的注意力得分;以及基于多个目标像素中的每一个目标像素对应的特征向量关于与该像素对应的特征向量的注意力得分,将多个目标像素各自对应的特征向量进行融合,以得到的该像素的局部特征向量。According to some embodiments, for each pixel in the first feature map, a self-attention mechanism is used to determine the local feature vector of the pixel based on the feature vector corresponding to the pixel and the respective feature vectors of multiple target pixels in the first feature map. , to obtain the second feature map may include: determining the attention score of the feature vector corresponding to each target pixel in the plurality of target pixels with respect to the feature vector corresponding to the pixel; and based on the corresponding feature vector of each target pixel in the plurality of target pixels. The feature vector of the feature vector corresponds to the attention score of the feature vector corresponding to the pixel, and the feature vectors corresponding to the multiple target pixels are fused to obtain the local feature vector of the pixel.
根据一些实施例,第三特征图的高度可以为待识别图像的高度的1/32。According to some embodiments, the height of the third feature map may be 1/32 of the height of the image to be recognized.
根据一些实施例,文本识别的方法还可以包括以下中的至少一者:融合第一特征图和第二特征图以更新第二特征图;以及融合第三特征图和第四特征图以更新第四特征图。According to some embodiments, the method of text recognition may further include at least one of the following: fusing the first feature map and the second feature map to update the second feature map; and fusing the third feature map and the fourth feature map to update the second feature map. Four feature maps.
本公开的技术方案中,所涉及的用户个人信息的收集、存储、使用、加工、传输、提供和公开等处理,均符合相关法律法规的规定,且不违背公序良俗。In the technical solution of this disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information are in compliance with relevant laws and regulations and do not violate public order and good customs.
根据本公开的实施例,还提供了一种电子设备、一种可读存储介质和一种计算机程序产品。According to embodiments of the present disclosure, an electronic device, a readable storage medium, and a computer program product are also provided.
参考图5,现将描述可以作为本公开的服务器或客户端的电子设备900的结构框图,其是可以应用于本公开的各方面的硬件设备的示例。电子设备旨在表示各种形式的数字电子的计算机设备,诸如,膝上型计算机、台式计算机、工作台、个人数字助理、服务器、刀片式服务器、大型计算机、和其它适合的计算机。电子设备还可以表示各种形式的移动装置,诸如,个人数字处理、蜂窝电话、智能电话、可穿戴设备和其它类似的计算装置。本文所示的部件、它们的连接和关系、以及它们的功能仅仅作为示例,并且不意在限制本文中描述的和/或者要求的本公开的实现。Referring to FIG. 5 , a structural block diagram of an electronic device 900 that may serve as a server or client of the present disclosure will now be described, which is an example of a hardware device that may be applied to aspects of the present disclosure. Electronic devices are intended to refer to various forms of digital electronic computing equipment, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. Electronic devices may also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are examples only and are not intended to limit implementations of the disclosure described and/or claimed herein.
如图5所示,设备500包括计算单元501,其可以根据存储在只读存储器(ROM)502中的计算机程序或者从存储单元508加载到随机访问存储器 (RAM)503中的计算机程序,来执行各种适当的动作和处理。在RAM503中,还可存储设备500操作所需的各种程序和数据。计算单元501、ROM 502以及RAM 503通过总线504彼此相连。输入/输出(I/O)接口505也连接至总线504。As shown in FIG. 5 , the device 500 includes a computing unit 501 that can execute according to a computer program stored in a read-only memory (ROM) 502 or loaded from a storage unit 508 into a random access memory (RAM) 503 Various appropriate actions and treatments. In the RAM 503, various programs and data required for the operation of the device 500 can also be stored. Computing unit 501, ROM 502 and RAM 503 are connected to each other via bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
设备500中的多个部件连接至I/O接口505,包括:输入单元506、输出单元507、存储单元508以及通信单元509。输入单元506可以是能向设备500输入信息的任何类型的设备,输入单元506可以接收输入的数字或字符信息,以及产生与电子设备的用户设置和/或功能控制有关的键信号输入,并且可以包括但不限于鼠标、键盘、触摸屏、轨迹板、轨迹球、操作杆、麦克风和/或遥控器。输出单元507可以是能呈现信息的任何类型的设备,并且可以包括但不限于显示器、扬声器、视频/音频输出终端、振动器和/或打印机。存储单元508可以包括但不限于磁盘、光盘。通信单元509允许设备500通过诸如因特网的计算机网络和/或各种电信网络与其他设备交换信息/数据,并且可以包括但不限于调制解调器、网卡、红外通信设备、无线通信收发机和/或芯片组,例如蓝牙TM设备、802.11设备、WiFi设备、WiMax设备、蜂窝通信设备和/或类似物。Multiple components in the device 500 are connected to the I/O interface 505, including: an input unit 506, an output unit 507, a storage unit 508, and a communication unit 509. The input unit 506 may be any type of device capable of inputting information to the device 500. The input unit 506 may receive input numeric or character information and generate key signal input related to user settings and/or function control of the electronic device, and may Including, but not limited to, mouse, keyboard, touch screen, trackpad, trackball, joystick, microphone and/or remote control. Output unit 507 may be any type of device capable of presenting information, and may include, but is not limited to, a display, speakers, video/audio output terminal, vibrator, and/or printer. The storage unit 508 may include, but is not limited to, magnetic disks and optical disks. The communication unit 509 allows the device 500 to exchange information/data with other devices over a computer network such as the Internet and/or various telecommunications networks, and may include, but is not limited to, a modem, a network card, an infrared communication device, a wireless communication transceiver, and/or a chipset , such as Bluetooth™ devices, 802.11 devices, WiFi devices, WiMax devices, cellular communication devices and/or the like.
计算单元501可以是各种具有处理和计算能力的通用和/或专用处理组件。计算单元501的一些示例包括但不限于中央处理单元(CPU)、图形处理单元(GPU)、各种专用的人工智能(AI)计算芯片、各种运行机器学习网络算法的计算单元、数字信号处理器(DSP)、以及任何适当的处理器、控制器、微控制器等。计算单元501执行上文所描述的各个方法和处理,例如文本识别的方法和/或神经网络的训练方法和机器学习模型的训练方法。例如,在一些实施例中,文本识别的方法和/或神经网络的训练方法和机器学习模型的训练方法可被实现为计算机软件程序,其被有形地包含于机器可读介质,例如存储单元508。在一些实施例中,计算机程序的部分或者全部可以经由ROM 502和/或通信单元509而被载入和/或安装到设备500上。当计算机程序加载到RAM 503并由计算单元501执行时,可以执行上文描述的文本识别的方法和/或神经网络的训练方法和机器学习模型的训练方法的一个或多个步骤。备选地,在其他实施例中,计算单元501可以通过其他 任何适当的方式(例如,借助于固件)而被配置为执行文本识别的方法和/或神经网络的训练方法和机器学习模型的训练方法。 Computing unit 501 may be a variety of general and/or special purpose processing components having processing and computing capabilities. Some examples of the computing unit 501 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning network algorithms, digital signal processing processor (DSP), and any appropriate processor, controller, microcontroller, etc. The computing unit 501 performs various methods and processes described above, such as text recognition methods and/or neural network training methods and machine learning model training methods. For example, in some embodiments, the text recognition method and/or the neural network training method and the machine learning model training method may be implemented as a computer software program, which is tangibly included in a machine-readable medium, such as the storage unit 508 . In some embodiments, part or all of the computer program may be loaded and/or installed onto device 500 via ROM 502 and/or communication unit 509. When the computer program is loaded into the RAM 503 and executed by the computing unit 501, one or more steps of the text recognition method and/or the neural network training method and the machine learning model training method described above may be performed. Alternatively, in other embodiments, the computing unit 501 may be configured to perform the method of text recognition and/or the training method of the neural network and the training of the machine learning model in any other suitable manner (for example, by means of firmware). method.
本文中以上描述的系统和技术的各种实施方式可以在数字电子电路系统、集成电路系统、场可编程门阵列(FPGA)、专用集成电路(ASIC)、专用标准产品(ASSP)、芯片上系统的系统(SOC)、负载可编程逻辑设备(CPLD)、计算机硬件、固件、软件、和/或它们的组合中实现。这些各种实施方式可以包括:实施在一个或者多个计算机程序中,该一个或者多个计算机程序可在包括至少一个可编程处理器的可编程系统上执行和/或解释,该可编程处理器可以是专用或者通用可编程处理器,可以从存储系统、至少一个输入装置、和至少一个输出装置接收数据和指令,并且将数据和指令传输至该存储系统、该至少一个输入装置、和该至少一个输出装置。Various implementations of the systems and techniques described above may be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on a chip implemented in a system (SOC), load programmable logic device (CPLD), computer hardware, firmware, software, and/or a combination thereof. These various embodiments may include implementation in one or more computer programs executable and/or interpreted on a programmable system including at least one programmable processor, the programmable processor The processor, which may be a special purpose or general purpose programmable processor, may receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device. An output device.
用于实施本公开的方法的程序代码可以采用一个或多个编程语言的任何组合来编写。这些程序代码可以提供给通用计算机、专用计算机或其他可编程数据处理装置的处理器或控制器,使得程序代码当由处理器或控制器执行时使流程图和/或框图中所规定的功能/操作被实施。程序代码可以完全在机器上执行、部分地在机器上执行,作为独立软件包部分地在机器上执行且部分地在远程机器上执行或完全在远程机器或服务器上执行。Program code for implementing the methods of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing device, such that the program codes, when executed by the processor or controller, cause the functions specified in the flowcharts and/or block diagrams/ The operation is implemented. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package, partly on the machine and partly on a remote machine or entirely on the remote machine or server.
在本公开的上下文中,机器可读介质可以是有形的介质,其可以包含或存储以供指令执行系统、装置或设备使用或与指令执行系统、装置或设备结合地使用的程序。机器可读介质可以是机器可读信号介质或机器可读储存介质。机器可读介质可以包括但不限于电子的、磁性的、光学的、电磁的、红外的、或半导体系统、装置或设备,或者上述内容的任何合适组合。机器可读存储介质的更具体示例会包括基于一个或多个线的电气连接、便携式计算机盘、硬盘、随机存取存储器(RAM)、只读存储器(ROM)、可擦除可编程只读存储器(EPROM或快闪存储器)、光纤、便捷式紧凑盘只读存储器(CD-ROM)、光学储存设备、磁储存设备、或上述内容的任何合适组合。In the context of this disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media may include, but are not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media would include one or more wire-based electrical connections, laptop disks, hard drives, random access memory (RAM), read only memory (ROM), erasable programmable read only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination of the above.
为了提供与用户的交互,可以在计算机上实施此处描述的系统和技术,该计算机具有:用于向用户显示信息的显示装置(例如,CRT(阴极射线 管)或者LCD(液晶显示器)监视器);以及键盘和指向装置(例如,鼠标或者轨迹球),用户可以通过该键盘和该指向装置来将输入提供给计算机。其它种类的装置还可以用于提供与用户的交互;例如,提供给用户的反馈可以是任何形式的传感反馈(例如,视觉反馈、听觉反馈、或者触觉反馈);并且可以用任何形式(包括声输入、语音输入或者、触觉输入)来接收来自用户的输入。To provide interaction with a user, the systems and techniques described herein may be implemented on a computer having a display device (eg, a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user ); and a keyboard and pointing device (eg, a mouse or a trackball) through which a user can provide input to the computer. Other kinds of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and may be provided in any form, including Acoustic input, voice input or tactile input) to receive input from the user.
可以将此处描述的系统和技术实施在包括后台部件的计算系统(例如,作为数据服务器)、或者包括中间件部件的计算系统(例如,应用服务器)、或者包括前端部件的计算系统(例如,具有图形用户界面或者网络浏览器的用户计算机,用户可以通过该图形用户界面或者该网络浏览器来与此处描述的系统和技术的实施方式交互)、或者包括这种后台部件、中间件部件、或者前端部件的任何组合的计算系统中。可以通过任何形式或者介质的数字数据通信(例如,通信网络)来将系统的部件相互连接。通信网络的示例包括:局域网(LAN)、广域网(WAN)和互联网。The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., A user's computer having a graphical user interface or web browser through which the user can interact with implementations of the systems and technologies described herein), or including such backend components, middleware components, or any combination of front-end components in a computing system. The components of the system may be interconnected by any form or medium of digital data communication (eg, a communications network). Examples of communication networks include: local area network (LAN), wide area network (WAN), and the Internet.
计算机系统可以包括客户端和服务器。客户端和服务器一般远离彼此并且通常通过通信网络进行交互。通过在相应的计算机上运行并且彼此具有客户端-服务器关系的计算机程序来产生客户端和服务器的关系。服务器可以是云服务器,又称为云计算服务器或云主机,是云计算服务体系中的一项主机产品,以解决了传统物理主机与VPS服务("Virtual Private Server",或简称"VPS")中,存在的管理难度大,业务扩展性弱的缺陷。服务器也可以为分布式系统的服务器,或者是结合了区块链的服务器。Computer systems may include clients and servers. Clients and servers are generally remote from each other and typically interact over a communications network. The relationship of client and server is created by computer programs running on corresponding computers and having a client-server relationship with each other. The server can be a cloud server, also known as cloud computing server or cloud host. It is a host product in the cloud computing service system to solve the problem of traditional physical host and VPS service ("Virtual Private Server", or "VPS" for short) Among them, there are defects such as difficult management and weak business scalability. The server can also be a distributed system server or a server combined with a blockchain.
应该理解,可以使用上面所示的各种形式的流程,重新排序、增加或删除步骤。例如,本公开中记载的各步骤可以并行地执行、也可以顺序地或以不同的次序执行,只要能够实现本公开公开的技术方案所期望的结果,本文在此不进行限制。It should be understood that various forms of the process shown above may be used, with steps reordered, added or deleted. For example, each step described in the present disclosure can be executed in parallel, sequentially, or in a different order. As long as the desired results of the technical solution disclosed in the present disclosure can be achieved, there is no limitation here.
虽然已经参照附图描述了本公开的实施例或示例,但应理解,上述的方法、系统和设备仅仅是示例性的实施例或示例,本发明的范围并不由这些实施例或示例限制,而是仅由授权后的权利要求书及其等同范围来限定。实施例或示例中的各种要素可以被省略或者可由其等同要素替代。此外,可以通过不同于本公开中描述的次序来执行各步骤。进一步地,可以以各 种方式组合实施例或示例中的各种要素。重要的是随着技术的演进,在此描述的很多要素可以由本公开之后出现的等同要素进行替换。Although the embodiments or examples of the present disclosure have been described with reference to the accompanying drawings, it should be understood that the above-mentioned methods, systems and devices are only exemplary embodiments or examples, and the scope of the present invention is not limited by these embodiments or examples. It is limited only by the granted claims and their equivalent scope. Various elements in the embodiments or examples may be omitted or replaced by equivalent elements thereof. Furthermore, the steps may be performed in a different order than described in this disclosure. Further, various elements in the embodiments or examples may be combined in various ways. Importantly, as technology evolves, many elements described herein may be replaced by equivalent elements appearing after this disclosure.

Claims (22)

  1. 一种用于文本识别的神经网络,包括:A neural network for text recognition, including:
    第一卷积子网络,被配置为对待识别图像进行卷积处理,以输出第一特征图;The first convolution subnetwork is configured to perform convolution processing on the image to be recognized to output the first feature map;
    局部融合子网络,被配置为针对所述第一特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和所述第一特征图中的多个目标像素各自的特征向量,确定该像素的局部特征向量,以得到第二特征图,其中,所述多个目标像素包括所述第一特征图中位于该像素的邻域中的多个像素;The local fusion sub-network is configured to use a self-attention mechanism for each pixel in the first feature map based on the feature vector corresponding to the pixel and the respective feature vectors of multiple target pixels in the first feature map. , determine the local feature vector of the pixel to obtain the second feature map, wherein the plurality of target pixels include multiple pixels located in the neighborhood of the pixel in the first feature map;
    第二卷积子网络,被配置为对所述第二特征图进行卷积处理,以输出第三特征图;a second convolution subnetwork configured to perform convolution processing on the second feature map to output a third feature map;
    全局融合子网络,被配置为针对所述第三特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和所述第三特征图中的每一个像素各自的特征向量,确定该像素的全局特征向量,以得到第四特征图;以及The global fusion sub-network is configured to use a self-attention mechanism for each pixel in the third feature map based on the feature vector corresponding to the pixel and the respective feature vector of each pixel in the third feature map, Determine the global feature vector of the pixel to obtain a fourth feature map; and
    输出子网络,被配置为基于所述第四特征图,输出文本识别结果。The output sub-network is configured to output text recognition results based on the fourth feature map.
  2. 根据权利要求1所述的神经网络,其中,所述第一卷积子网络和所述第二卷积子网络中的至少一者包括深度可分离卷积层。The neural network of claim 1, wherein at least one of the first convolutional subnetwork and the second convolutional subnetwork includes a depthwise separable convolutional layer.
  3. 根据权利要求2所述的神经网络,其中,所述第一卷积子网络包括常规卷积层,所述第一卷积子网络和所述第二卷积子网络中的至少一者包括第一深度可分离卷积层,所述第二卷积子网络包括第二深度可分离卷积层,其中,所述第一深度可分离卷积层所使用的卷积核的尺寸小于所述第二深度可分离卷积层所使用的卷积核的尺寸。The neural network of claim 2, wherein the first convolutional subnetwork includes a conventional convolutional layer, and at least one of the first convolutional subnetwork and the second convolutional subnetwork includes a A depthwise separable convolution layer, the second convolution sub-network includes a second depthwise separable convolution layer, wherein the size of the convolution kernel used by the first depthwise separable convolution layer is smaller than that of the third depthwise separable convolution layer. The size of the convolution kernel used in the two-depth separable convolutional layer.
  4. 根据权利要求1-3中任一项所述的神经网络,其中,所述第三特征图的高度为所述待识别图像的高度的1/32。The neural network according to any one of claims 1-3, wherein the height of the third feature map is 1/32 of the height of the image to be recognized.
  5. 根据权利要求1-3中任一项所述的神经网络,还包括以下中的至少一者:The neural network according to any one of claims 1-3, further comprising at least one of the following:
    第一融合层,被配置为融合所述第一特征图和所述第二特征图以更新所述第二特征图;以及a first fusion layer configured to fuse the first feature map and the second feature map to update the second feature map; and
    第二融合层,被配置为融合所述第三特征图和所述第四特征图以更新所述第四特征图。The second fusion layer is configured to fuse the third feature map and the fourth feature map to update the fourth feature map.
  6. 根据权利要求1-3中任一项所述的神经网络,其中,针对所述第一特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和所述第一特征图中的多个相关像素各自的特征向量确定该像素的局部特征向量,以得到第二特征图包括:The neural network according to any one of claims 1 to 3, wherein for each pixel in the first feature map, a self-attention mechanism is used based on the feature vector corresponding to the pixel and the first feature map. The respective feature vectors of multiple related pixels in determine the local feature vector of the pixel to obtain the second feature map including:
    确定所述多个目标像素中的每一个目标像素对应的特征向量关于该像素对应的特征向量的注意力得分;以及Determine the attention score of the feature vector corresponding to each target pixel in the plurality of target pixels with respect to the feature vector corresponding to the pixel; and
    基于所述多个目标像素中的每一个目标像素对应的特征向量关于该像素对应的特征向量的注意力得分,将所述多个目标像素各自对应的特征向量进行融合,以得到该像素的局部特征向量。Based on the attention score of the feature vector corresponding to each target pixel in the plurality of target pixels with respect to the feature vector corresponding to the pixel, the feature vectors corresponding to the plurality of target pixels are fused to obtain the local feature vector of the pixel. Feature vector.
  7. 一种利用神经网络进行文本识别的方法,所述神经网络包括第一卷积子网络、局部融合子网络、第二卷积子网络、全局融合子网络、以及输出子网络,所述方法包括:A method for text recognition using a neural network. The neural network includes a first convolution subnetwork, a local fusion subnetwork, a second convolution subnetwork, a global fusion subnetwork, and an output subnetwork. The method includes:
    将待识别图像输入所述第一卷积子网络,所述第一卷积子网络被配置为对待识别图像进行卷积处理,以输出第一特征图;Input the image to be recognized into the first convolution subnetwork, and the first convolution subnetwork is configured to perform convolution processing on the image to be recognized to output a first feature map;
    将所述第一特征图输入所述局部融合子网络,所述局部融合子网络被配置为针对所述第一特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和所述第一特征图中的多个目标像素各自的特征向量,确定该像素的局部特征向量,以得到第二特征图,其中,所述多个目标像素包括所述第一特征图中位于该像素的邻域中的多个像素;The first feature map is input into the local fusion sub-network. The local fusion sub-network is configured to use a self-attention mechanism for each pixel in the first feature map based on the sum of the feature vectors corresponding to the pixel. The respective feature vectors of the plurality of target pixels in the first feature map are determined to determine the local feature vector of the pixel to obtain the second feature map, wherein the plurality of target pixels include the locations located in the first feature map. Multiple pixels in the neighborhood of a pixel;
    将所述第二特征图输入所述第二卷积子网络,所述第二卷积子网络被配置为对所述第二特征图进行卷积处理,以输出第三特征图;Input the second feature map into the second convolution subnetwork, and the second convolution subnetwork is configured to perform convolution processing on the second feature map to output a third feature map;
    将所述第三特征图输入所述全局融合子网络,所述全局融合子网络被配置为针对所述第三特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和所述第三特征图中的每一个像素各自的特征向量,确定该像素的全局特征向量,以得到第四特征图;以及The third feature map is input to the global fusion sub-network, and the global fusion sub-network is configured to use a self-attention mechanism for each pixel in the third feature map based on the sum of the feature vectors corresponding to the pixel. The respective feature vector of each pixel in the third feature map is determined to determine the global feature vector of the pixel to obtain the fourth feature map; and
    将所述第四特征图输入所述输出子网络,所述输出子网络被配置为基于所述第四特征图,输出文本识别结果。The fourth feature map is input to the output sub-network, and the output sub-network is configured to output a text recognition result based on the fourth feature map.
  8. 根据权利要求7所述的方法,其中,所述第一卷积子网络和所述第二卷积子网络中的至少一者包括深度可分离卷积层。The method of claim 7, wherein at least one of the first convolutional subnetwork and the second convolutional subnetwork includes a depthwise separable convolutional layer.
  9. 根据权利要求8所述的方法,其中,所述第一卷积子网络包括常规卷积层,所述第一卷积子网络和所述第二卷积子网络中的至少一者包括第一深度可分离卷积层,所述第二卷积子网络包括第二深度可分离卷积层,其中,所述第一深度可分离卷积层所使用的卷积核的尺寸小于所述第二深度可分离卷积层所使用的卷积核的尺寸。The method of claim 8, wherein the first convolutional subnetwork includes a regular convolutional layer, and at least one of the first convolutional subnetwork and the second convolutional subnetwork includes a first a depthwise separable convolution layer, the second convolution sub-network includes a second depthwise separable convolution layer, wherein the size of the convolution kernel used by the first depthwise separable convolution layer is smaller than that of the second depthwise separable convolution layer. The size of the convolution kernel used in depth-separable convolutional layers.
  10. 根据权利要求7-9中任一项所述的方法,其中,所述第三特征图的高度为所述待识别图像的高度的1/32。The method according to any one of claims 7-9, wherein the height of the third feature map is 1/32 of the height of the image to be recognized.
  11. 根据权利要求7-9中任一项所述的方法,还包括以下中的至少一者:The method according to any one of claims 7-9, further comprising at least one of the following:
    融合所述第一特征图和所述第二特征图以更新所述第二特征图;以及fusing the first feature map and the second feature map to update the second feature map; and
    融合所述第三特征图和所述第四特征图以更新所述第四特征图。The third feature map and the fourth feature map are fused to update the fourth feature map.
  12. 根据权利要求7-9中任一项所述的方法,其中,针对所述第一特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和所述第一特征图中的多个目标像素各自的特征向量确定该像素的局部特征向量,以得到第二特征图包括:The method according to any one of claims 7-9, wherein, for each pixel in the first feature map, a self-attention mechanism is used based on the feature vector corresponding to the pixel and the first feature map. The respective feature vectors of the multiple target pixels determine the local feature vector of the pixel to obtain the second feature map including:
    确定所述多个目标像素中的每一个目标像素对应的特征向量关于该像素对应的特征向量的注意力得分;以及Determine the attention score of the feature vector corresponding to each target pixel in the plurality of target pixels with respect to the feature vector corresponding to the pixel; and
    基于所述多个目标像素中的每一个目标像素对应的特征向量关于与该像素对应的特征向量的注意力得分,将所述多个目标像素各自对应的特征向量进行融合,以得到该像素的局部特征向量。Based on the attention score of the feature vector corresponding to each target pixel in the plurality of target pixels with respect to the feature vector corresponding to the pixel, the feature vectors corresponding to the plurality of target pixels are fused to obtain the feature vector of the pixel. local feature vector.
  13. 一种神经网络的训练方法,所述神经网络包括第一卷积子网络、局部融合子网络、第二卷积子网络、全局融合子网络、以及输出子网络,所述方法包括:A training method for a neural network. The neural network includes a first convolution subnetwork, a local fusion subnetwork, a second convolution subnetwork, a global fusion subnetwork, and an output subnetwork. The method includes:
    确定样本图像和对应的真实结果;Determine sample images and corresponding real results;
    将所述样本图像输入所述第一卷积子网络,所述第一卷积子网络被配置为对所述样本图像进行卷积处理,以输出第一特征图;Input the sample image into the first convolution subnetwork, and the first convolution subnetwork is configured to perform convolution processing on the sample image to output a first feature map;
    将所述第一特征图输入所述局部融合子网络,所述局部融合子网络被配置为针对所述第一特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和所述第一特征图中的多个目标像素各自的特征向量,确定该像素的局部特征向量,以得到第二特征图,其中,所述多个目标像素包括所述第一特征图中位于该像素的邻域中的多个像素;The first feature map is input into the local fusion sub-network. The local fusion sub-network is configured to use a self-attention mechanism for each pixel in the first feature map based on the sum of the feature vectors corresponding to the pixel. The respective feature vectors of the plurality of target pixels in the first feature map are determined to determine the local feature vector of the pixel to obtain the second feature map, wherein the plurality of target pixels include the locations located in the first feature map. Multiple pixels in the neighborhood of a pixel;
    将所述第二特征图输入所述第二卷积子网络,所述第二卷积子网络被配置为对所述第二特征图进行卷积处理,以输出第三特征图;Input the second feature map into the second convolution subnetwork, and the second convolution subnetwork is configured to perform convolution processing on the second feature map to output a third feature map;
    将所述第三特征图输入所述全局融合子网络,所述全局融合子网络被配置为针对所述第三特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和所述第三特征图中的每一个像素各自的特征向量,确定该像素的全局特征向量,以得到第四特征图;The third feature map is input to the global fusion sub-network, and the global fusion sub-network is configured to use a self-attention mechanism for each pixel in the third feature map based on the sum of the feature vectors corresponding to the pixel. The respective feature vector of each pixel in the third feature map is determined to determine the global feature vector of the pixel to obtain the fourth feature map;
    将所述第四特征图输入所述输出子网络,所述输出子网络被配置为基于所述第四特征图,输出对所述样本图像进行文本识别的预测结果;Input the fourth feature map into the output sub-network, and the output sub-network is configured to output a prediction result of text recognition on the sample image based on the fourth feature map;
    基于所述真实结果和所述预测结果,计算损失值;以及Calculate a loss value based on the actual results and the predicted results; and
    基于所述损失值调整所述神经网络的参数,以得到训练后的神经网络。Adjust the parameters of the neural network based on the loss value to obtain a trained neural network.
  14. 根据权利要求13所述的方法,其中,所述损失值包括连接时序分类(CTC)损失值和中心损失值。The method of claim 13, wherein the loss value includes a connection temporal classification (CTC) loss value and a center loss value.
  15. 根据权利要求13所述的方法,其中,所述第一卷积子网络和所述第二卷积子网络中的至少一者包括深度可分离卷积层。The method of claim 13, wherein at least one of the first convolutional subnetwork and the second convolutional subnetwork includes a depthwise separable convolutional layer.
  16. 根据权利要求15所述的方法,其中,所述第一卷积子网络包括常规卷积层,所述第一卷积子网络和所述第二卷积子网络中的至少一者包括第一深度可分离卷积层,所述第二卷积子网络包括第二深度可分离卷积层,其中,所述第一深度可分离卷积层所使用的卷积核的尺寸小于所述第二深度可分离卷积层所使用的卷积核的尺寸。The method of claim 15, wherein the first convolutional subnetwork includes a regular convolutional layer, and at least one of the first convolutional subnetwork and the second convolutional subnetwork includes a first a depthwise separable convolution layer, the second convolution sub-network includes a second depthwise separable convolution layer, wherein the size of the convolution kernel used by the first depthwise separable convolution layer is smaller than that of the second depthwise separable convolution layer. The size of the convolution kernel used in depth-separable convolutional layers.
  17. 根据权利要求13-16中任一项所述的方法,其中,所述第三特征图的高度为所述待识别图像的高度的1/32。The method according to any one of claims 13-16, wherein the height of the third feature map is 1/32 of the height of the image to be recognized.
  18. 根据权利要求13-16中任一项所述的方法,还包括以下中的至少一者:The method according to any one of claims 13-16, further comprising at least one of the following:
    融合所述第一特征图和所述第二特征图以更新所述第二特征图;以及fusing the first feature map and the second feature map to update the second feature map; and
    融合所述第三特征图和所述第四特征图以更新所述第四特征图。The third feature map and the fourth feature map are fused to update the fourth feature map.
  19. 根据权利要求13-16中任一项所述的方法,其中,针对所述第一特征图中的每一个像素,利用自注意力机制基于该像素对应的特征向量和所述第一特征图中的多个相关像素各自的特征向量确定该像素的局部特征向量,以得到第二特征图包括:The method according to any one of claims 13-16, wherein, for each pixel in the first feature map, a self-attention mechanism is used based on the feature vector corresponding to the pixel and the first feature map. The respective feature vectors of multiple related pixels determine the local feature vector of the pixel to obtain the second feature map including:
    确定所述多个目标像素中的每一个目标像素对应的特征向量关于该像素对应的特征向量的注意力得分;以及Determine the attention score of the feature vector corresponding to each target pixel in the plurality of target pixels with respect to the feature vector corresponding to the pixel; and
    基于所述多个目标像素中的每一个目标像素对应的特征向量关于该像素对应的特征向量的注意力得分,将所述多个目标像素各自对应的特征向量进行融合,以得到该像素的局部特征向量。Based on the attention score of the feature vector corresponding to each target pixel in the plurality of target pixels with respect to the feature vector corresponding to the pixel, the feature vectors corresponding to the plurality of target pixels are fused to obtain the local feature vector of the pixel. Feature vector.
  20. 一种电子设备,包括:An electronic device including:
    至少一个处理器;以及at least one processor; and
    与所述至少一个处理器通信连接的存储器;其中a memory communicatively connected to the at least one processor; wherein
    所述存储器存储有可被所述至少一个处理器执行的指令,所述指令被所述至少一个处理器执行,以使所述至少一个处理器能够执行权利要求1-19中任一项所述的方法。The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform any one of claims 1-19 Methods.
  21. 一种存储有计算机指令的非瞬时计算机可读存储介质,其中,所述计算机指令用于使所述计算机执行根据权利要求1-19中任一项所述的方法。A non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause the computer to execute the method according to any one of claims 1-19.
  22. 一种计算机程序产品,包括计算机程序,其中,所述计算机程序在被处理器执行时实现权利要求1-19中任一项所述的方法。A computer program product comprising a computer program, wherein the computer program implements the method of any one of claims 1-19 when executed by a processor.
PCT/CN2022/131189 2022-05-18 2022-11-10 Neural network used for text recognition, training method thereof and text recognition method WO2023221422A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210548237.8 2022-05-18
CN202210548237.8A CN114743196B (en) 2022-05-18 2022-05-18 Text recognition method and device and neural network training method

Publications (1)

Publication Number Publication Date
WO2023221422A1 true WO2023221422A1 (en) 2023-11-23

Family

ID=82287497

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/131189 WO2023221422A1 (en) 2022-05-18 2022-11-10 Neural network used for text recognition, training method thereof and text recognition method

Country Status (2)

Country Link
CN (1) CN114743196B (en)
WO (1) WO2023221422A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117437490A (en) * 2023-12-04 2024-01-23 深圳咔咔可洛信息技术有限公司 Clothing information processing method and device, electronic equipment and storage medium

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114743196B (en) * 2022-05-18 2023-04-18 北京百度网讯科技有限公司 Text recognition method and device and neural network training method
CN115331048B (en) * 2022-07-29 2023-06-27 北京百度网讯科技有限公司 Image classification method, device, equipment and storage medium
CN115438214B (en) * 2022-11-07 2023-04-07 北京百度网讯科技有限公司 Method and device for processing text image and training method of neural network

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112149619A (en) * 2020-10-14 2020-12-29 南昌慧亦臣科技有限公司 Natural scene character recognition method based on Transformer model
CN114495119A (en) * 2021-12-01 2022-05-13 浙江大学 Real-time irregular text recognition method under complex scene
CN114743196A (en) * 2022-05-18 2022-07-12 北京百度网讯科技有限公司 Neural network for text recognition, training method thereof and text recognition method

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112215223B (en) * 2020-10-16 2024-03-19 清华大学 Multidirectional scene character recognition method and system based on multi-element attention mechanism
CN113221874A (en) * 2021-06-09 2021-08-06 上海交通大学 Character recognition system based on Gabor convolution and linear sparse attention
CN113326833B (en) * 2021-08-04 2021-11-16 浩鲸云计算科技股份有限公司 Character recognition improved training method based on center loss
CN113705713B (en) * 2021-09-03 2023-08-22 华南理工大学 Text recognition method based on global and local attention mechanisms

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112149619A (en) * 2020-10-14 2020-12-29 南昌慧亦臣科技有限公司 Natural scene character recognition method based on Transformer model
CN114495119A (en) * 2021-12-01 2022-05-13 浙江大学 Real-time irregular text recognition method under complex scene
CN114743196A (en) * 2022-05-18 2022-07-12 北京百度网讯科技有限公司 Neural network for text recognition, training method thereof and text recognition method

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
CAO YANG: "Text Detection and Recognition for Curved Targets", CHINESE MASTER'S THESES FULL-TEXT DATABASE, 1 April 2020 (2020-04-01), pages 1 - 78, XP055924975, ISSN: 1673-0246, DOI: 10.27005/d.cnki.gdzku.2020.001249 *
YONGKUN DU; ZHINENG CHEN; CAIYAN JIA; XIAOTING YIN; TIANLUN ZHENG; CHENXIA LI; YUNING DU; YU-GANG JIANG: "SVTR: Scene Text Recognition with a Single Visual Model", ARXIV.ORG, 30 April 2022 (2022-04-30), XP091211184 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117437490A (en) * 2023-12-04 2024-01-23 深圳咔咔可洛信息技术有限公司 Clothing information processing method and device, electronic equipment and storage medium
CN117437490B (en) * 2023-12-04 2024-03-22 深圳咔咔可洛信息技术有限公司 Clothing information processing method and device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN114743196B (en) 2023-04-18
CN114743196A (en) 2022-07-12

Similar Documents

Publication Publication Date Title
US20230005284A1 (en) Method for training image-text matching model, computing device, and storage medium
WO2023221422A1 (en) Neural network used for text recognition, training method thereof and text recognition method
CN113807440B (en) Method, apparatus, and medium for processing multimodal data using neural networks
CN114648638A (en) Training method of semantic segmentation model, semantic segmentation method and device
US20230052389A1 (en) Human-object interaction detection
US20230051232A1 (en) Human-object interaction detection
WO2023231350A1 (en) Task processing method implemented by using integer programming solver, device, and medium
US20230047628A1 (en) Human-object interaction detection
WO2023142406A1 (en) Ranking method and apparatus, ranking model training method and apparatus, and electronic device and medium
JP2024509014A (en) Sorting method, sorting model training method, device, electronic device and storage medium
CN115082740A (en) Target detection model training method, target detection method, device and electronic equipment
CN115114424A (en) Response method and device for query request
CN114550313A (en) Image processing method, neural network, and training method, device, and medium thereof
CN114723949A (en) Three-dimensional scene segmentation method and method for training segmentation model
CN116541536B (en) Knowledge-enhanced content generation system, data generation method, device, and medium
CN116152607A (en) Target detection method, method and device for training target detection model
EP4184349A1 (en) Object recommendation method and device
US20220004801A1 (en) Image processing and training for a neural network
CN114429678A (en) Model training method and device, electronic device and medium
EP4155983A2 (en) Data processing method, apparatus, storage medium, and computer program product
CN115511779B (en) Image detection method, device, electronic equipment and storage medium
CN112765975B (en) Word segmentation disambiguation processing method, device, equipment and medium
CN116361399B (en) Knowledge reasoning method, device, equipment and medium
CN115512131B (en) Image detection method and training method of image detection model
US20230097986A1 (en) Data processing method

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22942443

Country of ref document: EP

Kind code of ref document: A1