技术领域Technical field
本申请实施例涉及人工智能(artificial intelligence,AI)领域,尤其涉及一种文本获取方法及其相关设备。Embodiments of the present application relate to the field of artificial intelligence (AI), and in particular, to a text acquisition method and related equipment.
背景技术Background technique
随着AI技术的快速发展,越来越多的用户使用预训练的神经网络模型(也可以称为预训练模型),来完成针对呈现有多个文本的图像的分析处理,也就是说,预训练的神经网络模型可以对图像进行充分理解,以从图像所呈现的多个文本中,提取出目标文本。With the rapid development of AI technology, more and more users use pre-trained neural network models (also called pre-trained models) to complete the analysis and processing of images presenting multiple texts. In other words, pre-trained neural network models The trained neural network model can fully understand the image to extract the target text from the multiple texts presented in the image.
相关技术中,预训练的神经网络模型可以包含编码器和解码器。当需要从图像所呈现的多个文本中提取目标文本时时,可将图像输入至神经网络模型中。那么,编码器可对图像进行编码,从而得到图像的特征,并将图像的特征提供给解码器。然后,解码器可基于图像的特征进行解码,从而得到目标文本。In related art, a pre-trained neural network model may include an encoder and a decoder. When it is necessary to extract target text from multiple texts presented in the image, the image can be input into the neural network model. Then, the encoder can encode the image to obtain the features of the image and provide the features of the image to the decoder. The decoder can then perform decoding based on the features of the image to obtain the target text.
上述过程中,神经网络模型是基于图像的特征,来对图像的内容进行理解,以从图像所呈现的多个文本中提取出目标文本。但是,神经网络模型在对图像进行理解时,所考虑的因素较为单一,导致模型最终得到的目标文本可能不是准确的文本。In the above process, the neural network model understands the content of the image based on the characteristics of the image to extract the target text from the multiple texts presented in the image. However, when the neural network model understands images, the factors it considers are relatively single, so the target text finally obtained by the model may not be accurate text.
发明内容Contents of the invention
本申请实施例提供了一种文本获取方法及其相关设备,可从目标图像中获取准确的目标文本。The embodiment of the present application provides a text acquisition method and related equipment, which can obtain accurate target text from a target image.
本申请实施例的第一方面提供了一种文本获取方法,该方法通过目标模型实现,该方法包括:The first aspect of the embodiment of the present application provides a text acquisition method, which is implemented through a target model. The method includes:
当需要从包含目标图像中获取目标文本时,可先获取目标图像。需要说明的是,目标图像所呈现的内容包含多个文本,多个文本包含所需获取的目标文本。When you need to obtain the target text from the containing target image, you can first obtain the target image. It should be noted that the content presented by the target image includes multiple texts, and the multiple texts include the target text that needs to be obtained.
得到目标图像后,可将目标图像输入至目标模型,故目标模型可先对目标图像进行编码,从而得到目标图像的特征。得到目标图像的特征后,目标模型可对目标图像的特征进行处理,从而得到目标文本在目标图像中的位置信息。得到目标文本在目标图像中的位置信息后,解码器可对目标图像的特征以及目标文本在目标图像中的位置信息做进一步的处理,从而得到目标文本。After obtaining the target image, the target image can be input to the target model, so the target model can first encode the target image to obtain the characteristics of the target image. After obtaining the characteristics of the target image, the target model can process the characteristics of the target image to obtain the position information of the target text in the target image. After obtaining the position information of the target text in the target image, the decoder can further process the characteristics of the target image and the position information of the target text in the target image, thereby obtaining the target text.
需要说明的是,目标模型的输入不仅包含外部输入的目标图像,还包含自身得到的目标文本在目标图像中的位置信息,目标模型对外的输出不仅包含目标文本,还包含目标文本在目标图像中的位置信息,也就是说,目标文本和目标文本在目标图像中的位置信息为目标模型的两个输出。至此,则成功从目标图像中获取到了目标文本。It should be noted that the input of the target model not only includes the externally input target image, but also includes the position information of the target text in the target image obtained by itself. The external output of the target model not only includes the target text, but also includes the target text in the target image. The position information, that is, the target text and the position information of the target text in the target image are the two outputs of the target model. At this point, the target text has been successfully obtained from the target image.
从上述方法可以看出:当需要从目标图像中提取目标文本时,可先获取包含多个文本的目标图像,并将目标图像输入至目标模型。接着,目标模型可对目标图像进行编码,从而得到目标图像的特征。然后,目标模型可对目标图像的特征进行处理,从而得到多个文本中的目标文本在目标图像中的位置信息。最后,目标模型可对目标图像的特征以及目标文本在目标图像中的位置信息做进一步的处理,从而得到目标文本。至此,则成功从目标图像中提取出了目标文本。前述过程中,目标模型在对目标图像的内容进行理解时,不仅考虑了目标图像的特征,还考虑了目标文本在目标图像中的位置信息,这样考虑的因素较为全面,可以对目标图像的内容进行充分且准确的理解,由此可见,目标模型按照这种方式从目标图像所呈现的多个文本中提取出的目标文本,通常是正确的文本。It can be seen from the above method: when it is necessary to extract target text from a target image, a target image containing multiple texts can be obtained first, and the target image can be input to the target model. Then, the target model can encode the target image to obtain the characteristics of the target image. Then, the target model can process the features of the target image to obtain the position information of the target text in the target image among the multiple texts. Finally, the target model can further process the characteristics of the target image and the position information of the target text in the target image to obtain the target text. At this point, the target text has been successfully extracted from the target image. In the aforementioned process, when the target model understands the content of the target image, it not only considers the characteristics of the target image, but also considers the position information of the target text in the target image. In this way, the factors considered are more comprehensive and the content of the target image can be understood. With a full and accurate understanding, it can be seen that the target text extracted by the target model in this way from the multiple texts presented by the target image is usually the correct text.
在一种可能实现的方式中,基于特征,获取目标文本在目标图像中的位置信息包括:基于特征,对目标文本在目标图像中的位置信息的第1个向量表示至位置信息的第i个向量表示进行解码,得到位置信息的第i+1个向量表示,i=1,...,X-1,X≥1,位置信息的第1个向量表示基于特征对预置的向量表示进行解码得到。前述实现方式中,若目标文本的数量为一个,在得到目标图像的特征后,目标模型可先基于目标图像的特征,对预置的向量表示进行解码,从而得到目标文本在目标图像中的位置信息的第1个向量表示。接着,目标模型可基于目标图像的特征,对目标文本在目标图像中的位置信息的第1个向量表示进行解码,从而得到目标文本在目标图像中的位置信息的第2个向量表示,...,最后,目标模型可基于目标图像的特征,对目标文本在目标图像中的位置信息的第1个向量表示至目标文本在目标图像中的位置信息的第X-1个向量表示进行解码,从而得到目标文本在目标图像中的位置信息的第X个向量表示。如此一来,目标模型可以准确得到以向量表示形式呈现的目标文本在目标图像中的位置信息。In a possible implementation manner, obtaining the position information of the target text in the target image based on the features includes: based on the features, representing the first vector of the position information of the target text in the target image to the i-th position information The vector representation is decoded to obtain the i+1th vector representation of the position information, i=1,...,X-1,X≥1. The first vector representation of the position information is performed on the preset vector representation based on features decoded. In the aforementioned implementation, if the number of target texts is one, after obtaining the characteristics of the target image, the target model can first decode the preset vector representation based on the characteristics of the target image, thereby obtaining the position of the target text in the target image. The first vector representation of information. Then, the target model can decode the first vector representation of the position information of the target text in the target image based on the characteristics of the target image, thereby obtaining the second vector representation of the position information of the target text in the target image,... ., Finally, the target model can decode the 1st vector representation of the position information of the target text in the target image to the X-1th vector representation of the position information of the target text in the target image based on the characteristics of the target image, Thus, the Xth vector representation of the position information of the target text in the target image is obtained. In this way, the target model can accurately obtain the position information of the target text presented in the form of vector representation in the target image.
在一种可能实现的方式中,基于特征以及位置信息,获取目标文本包括:基于特征,对位置信息,目标文本的第1个向量表示至目标文本的第j个向量表示进行解码,得到目标文本的第j+1个向量表示,j=1,...,Y-1,Y≥1,目标文本的第1个向量表示基于特征对位置信息进行解码得到。前述实现方式中,若目标文本的数量为一个,在得到目标文本在目标图像中的位置信息后,目标模型可先基于目标图像的特征,对目标文本在目标图像中的位置信息进行解码,从而得到目标文本的第1个向量表示。接着,目标模型可基于目标图像的特征,对目标文本在目标图像中的位置信息以及目标文本的第1个向量表示进行解码,从而得到目标文本的第2个向量表示,...,最后,目标模型可基于目标图像的特征,对目标文本在目标图像中的位置信息,目标文本的第1个向量表示至目标文本的第Y-1个向量表示进行解码,从而得到目标文本的第Y个向量表示。如此一来,目标模型可以准确得到以向量表示形式呈现的目标文本。In one possible implementation, obtaining the target text based on features and location information includes: based on the features, decoding the location information, the first vector representation of the target text to the j-th vector representation of the target text, and obtaining the target text. The j+1th vector representation of , j=1,...,Y-1, Y≥1, the first vector representation of the target text is obtained by decoding the position information based on the features. In the aforementioned implementation, if the number of target texts is one, after obtaining the position information of the target text in the target image, the target model can first decode the position information of the target text in the target image based on the characteristics of the target image, so as to Get the first vector representation of the target text. Then, the target model can decode the position information of the target text in the target image and the first vector representation of the target text based on the characteristics of the target image, thereby obtaining the second vector representation of the target text,..., Finally, Based on the characteristics of the target image, the target model can decode the position information of the target text in the target image, the first vector representation of the target text to the Y-1th vector representation of the target text, thereby obtaining the Y-th vector representation of the target text. vector representation. In this way, the target model can accurately obtain the target text presented in the form of vector representation.
在一种可能实现的方式中,目标文本包含第一文本以及第二文本,位置信息包含第一文本在目标图像中的第一位置信息以及第二文本在目标图像中的第二位置信息,基于特征,获取目标文本在目标图像中的位置信息包括:基于特征,对第一位置信息的第1个向量表示至第一位置信息的第i个向量表示进行解码,得到第一位置信息的第i+1个向量表示,i=1,...,X-1,X≥1,第一位置信息的第1个向量表示基于特征对预置的向量表示进行解码得到;基于特征,对第一位置信息,第一文本,第二位置信息的第1个向量表示至第二位置信息的第k个向量表示进行解码,得到第一位置信息的第k+1个向量表示,k=1,...,Z-1,Z≥1,第二位置信息的第1个向量表示基于特征对第一位置信息以及第一文本进行解码得到。前述实现方式中,若目标文本的数量为两个,可将这两个目标文本分别称为第一文本以及第二文本。在得到目标图像的特征后,目标模型可先基于目标图像的特征,对预置的向量表示进行解码,从而得到第一文本在目标图像中的第一位置信息的第1个向量表示。接着,目标模型可基于目标图像的特征,对第一位置信息的第1个向量表示进行解码,从而得到第一位置信息的第2个向量表示,...,最后,目标模型可基于目标图像的特征,对第一位置信息的第1个向量表示至第一位置信息的第X-1个向量表示进行解码,从而得到第一位置信息的第X个向量表示。如此一来,目标模型可得到完整的以向量表示形式呈现的第一位置信息。得到第一位置信息后,目标模型可基于目标图像的特征,对第一位置信息进行处理,从而得到第一文本。得到第一文本后,目标模型可先基于目标图像的特征,对第一位置信息以及第一文本进行解码,从而得到第二文本在目标图像中的第二位置信息的第1个向量表示。接着,目标模型可基于目标图像的特征,对第一位置信息、第一文本以及第二位置信息的第1个向量表示进行解码,从而得到第二位置信息的第2个向量表示,...,最后,目标模型可基于目标图像的特征,对第一位置信息、第一文本、第二位置信息的第1个向量表示至第二位置信息的第Z-1个向量表示进行解码,从而得到第二位置信息的第Z个向量表示。如此一来,目标模型可以准确得到以向量表示形式呈现的第二位置信息。In a possible implementation manner, the target text includes a first text and a second text, and the position information includes first position information of the first text in the target image and second position information of the second text in the target image, based on Features, obtaining the position information of the target text in the target image includes: based on the features, decoding the first vector representation of the first position information to the i-th vector representation of the first position information, and obtaining the i-th vector representation of the first position information. +1 vector representation, i=1,...,X-1,X≥1, the first vector representation of the first position information is obtained by decoding the preset vector representation based on the feature; based on the feature, the first vector representation Position information, the first text, the first vector representation of the second position information are decoded to the k-th vector representation of the second position information, and the k+1-th vector representation of the first position information is obtained, k=1,. .., Z-1, Z≥1, the first vector representation of the second position information is obtained by decoding the first position information and the first text based on the features. In the foregoing implementation manner, if the number of target texts is two, the two target texts may be called the first text and the second text respectively. After obtaining the characteristics of the target image, the target model may first decode the preset vector representation based on the characteristics of the target image, thereby obtaining the first vector representation of the first position information of the first text in the target image. Then, the target model can decode the first vector representation of the first position information based on the characteristics of the target image, thereby obtaining the second vector representation of the first position information,... Finally, the target model can be based on the target image. features, decoding the 1st vector representation of the first position information to the X-1th vector representation of the first position information, thereby obtaining the X-th vector representation of the first position information. In this way, the target model can obtain complete first position information in the form of vector representation. After obtaining the first position information, the target model can process the first position information based on the characteristics of the target image, thereby obtaining the first text. After obtaining the first text, the target model can first decode the first position information and the first text based on the characteristics of the target image, thereby obtaining the first vector representation of the second position information of the second text in the target image. Then, the target model can decode the first vector representation of the first position information, the first text and the second position information based on the characteristics of the target image, thereby obtaining the second vector representation of the second position information,... , finally, the target model can decode the first vector representation of the first location information, the first text, and the second location information to the Z-1th vector representation of the second location information based on the characteristics of the target image, thereby obtaining The Z-th vector representation of the second position information. In this way, the target model can accurately obtain the second position information presented in the form of vector representation.
在一种可能实现的方式中,基于特征以及位置信息,获取目标文本包括:基于特征,对第一位置信息,第一文本的第1个向量表示至第一文本的第j个向量表示进行解码,得到第一文本的第j+1个向量表示,j=1,...,Y-1,Y≥1,第一文本的第1个向量表示基于特征对位置信息进行解码得到;基于特征,对第一位置信息,第一文本,第二位置信息,第二文本的第1个向量表示至第二文本的第t个向量表示进行解码,得到第二文本的第t+1个向量表示,t=1,...,U-1,U≥1,第二文本的第1个向量表示基于特征对第一位置信息,第一文本以及第二位置信息进行解码得到。前述实现方式中,若目标文本的数量为两个,可将这两个目标文本分别称为第一文本以及第二文本。在得到第一文本在目标图像中的第一位置信息后,目标模型可先基于目标图像的特征,对第一位置信息进行解码,从而得到第一文本的第1个向量表示。接着,目标模型可基于目标图像的特征,对第一位置信息以及第一文本的第1个向量表示进行解码,从而得到第一文本的第2个向量表示,...,最后,目标模型可基于目标图像的特征,对第一位置信息,第一文本的第1个向量表示至第一文本的第Y-1个向量表示进行解码,从而得到第一文本的第Y个向量表示。如此一来,目标模型可以得到以向量表示形式呈现的第一文本。得到第一文本后,目标模型可基于目标图像的特征,对第一位置信息以及第一文本进行处理,从而得到第二文本在目标图像中的第二位置信息。得到第二文本在目标图像中的第二位置信息后,目标模型可先基于目标图像的特征,对第一位置信息、第一文本以及第二位置信息进行解码,从而得到第二文本的第1个向量表示。接着,目标模型可基于目标图像的特征,对第一位置信息、第一文本、第二位置信息以及第二文本的第1个向量表示进行解码,从而得到第二文本的第2个向量表示,...,最后,目标模型可基于目标图像的特征,对第一位置信息、第一文本、第二位置信息、第二文本的第1个向量表示至第二文本的第U-1个向量表示进行解码,从而得到第二文本的第U个向量表示。如此一来,目标模型可以准确得到以向量表示形式呈现的第二文本。In a possible implementation manner, obtaining the target text based on the features and position information includes: based on the features, decoding the first position information, the first vector representation of the first text to the j-th vector representation of the first text. , get the j+1th vector representation of the first text, j=1,...,Y-1, Y≥1, the first vector representation of the first text is obtained by decoding the position information based on the feature; based on the feature , decode the first position information, the first text, the second position information, the first vector representation of the second text to the t-th vector representation of the second text, and obtain the t+1-th vector representation of the second text. , t=1,...,U-1, U≥1, the first vector representation of the second text is obtained by decoding the first position information, the first text and the second position information based on the features. In the foregoing implementation manner, if the number of target texts is two, the two target texts may be called the first text and the second text respectively. After obtaining the first position information of the first text in the target image, the target model may first decode the first position information based on the characteristics of the target image, thereby obtaining the first vector representation of the first text. Then, the target model can decode the first position information and the first vector representation of the first text based on the characteristics of the target image, thereby obtaining the second vector representation of the first text,... Finally, the target model can Based on the characteristics of the target image, decode the first position information, the first vector representation of the first text to the Y-1th vector representation of the first text, thereby obtaining the Y-th vector representation of the first text. In this way, the target model can obtain the first text presented in the form of vector representation. After obtaining the first text, the target model can process the first position information and the first text based on the characteristics of the target image, thereby obtaining the second position information of the second text in the target image. After obtaining the second position information of the second text in the target image, the target model can first decode the first position information, the first text and the second position information based on the characteristics of the target image, thereby obtaining the first position information of the second text. vector representation. Then, the target model can decode the first position information, the first text, the second position information and the first vector representation of the second text based on the characteristics of the target image, thereby obtaining the second vector representation of the second text, ..., finally, the target model can represent the first position information, the first text, the second position information, the first vector of the second text to the U-1th vector of the second text based on the characteristics of the target image. The representation is decoded to obtain the U-th vector representation of the second text. In this way, the target model can accurately obtain the second text presented in the form of vector representation.
在一种可能实现的方式中,该方法还包括:对位置信息的所有向量表示进行转换,得到目标文本在目标图像中所占据的区域的坐标。前述实现方式中,目标模型可将以向量表示形式呈现的目标文本(在目标图像中)的位置信息转换为以坐标形式呈现的目标文本的位置信息,以为用户提供目标文本在目标图像中的可视化效果。In a possible implementation manner, the method further includes: converting all vector representations of the position information to obtain the coordinates of the area occupied by the target text in the target image. In the foregoing implementation, the target model can convert the position information of the target text (in the target image) presented in the form of a vector representation into the position information of the target text presented in the form of coordinates, so as to provide the user with visualization of the target text in the target image. Effect.
在一种可能实现的方式中,该方法还包括:对目标文本的所有向量表示进行转换,得到目标文本的所有字符。前述实现方式中,目标模型还可将以向量表示形式呈现的目标文本转换为以字符(文字)形式呈现的目标文本,进一步为用户提供目标文本在目标图像中的可视化效果。In a possible implementation manner, the method further includes: converting all vector representations of the target text to obtain all characters of the target text. In the aforementioned implementation, the target model can also convert the target text presented in the form of vector representation into the target text presented in the form of characters (text), further providing the user with the visualization effect of the target text in the target image.
在一种可能实现的方式中,目标模型对目标文本以及位置信息所执行的转换可以为以下至少一种:基于循环神经网络的特征提取、基于多层感知机的特征提取以及基于时间卷积网络的特征提取。In a possible implementation manner, the conversion performed by the target model on the target text and location information can be at least one of the following: feature extraction based on recurrent neural networks, feature extraction based on multi-layer perceptrons, and temporal convolutional networks. feature extraction.
在一种可能实现的方式中,区域的坐标为以下至少一种:区域的左上角的顶点坐标以及区域的右下角的顶点坐标;或,区域的右上角的顶点坐标以及区域的左下角的顶点坐标;或,区域的四个角的顶点坐标;或,区域的左上角的顶点坐标、区域的左下角的顶点坐标以及区域的中心点坐标;或,区域的右上角的顶点坐标、区域的右下角的顶点坐标以及区域的中心点坐标;或,区域的右上角的顶点坐标、区域的左上角的顶点坐标以及区域的中心点坐标;或,区域的右下角的顶点坐标、区域的左下角的顶点坐标以及区域的中心点坐标;或,区域的右上角的顶点坐标、区域的右下角的顶点坐标、区域的左上角的顶点坐标、区域的左下角的顶点坐标以及区域的中心点坐标。In a possible implementation manner, the coordinates of the area are at least one of the following: the vertex coordinates of the upper left corner of the area and the vertex coordinates of the lower right corner of the area; or, the vertex coordinates of the upper right corner of the area and the vertex of the lower left corner of the area coordinates; or, the vertex coordinates of the four corners of the area; or, the vertex coordinates of the upper left corner of the area, the vertex coordinates of the lower left corner of the area, and the center point coordinates of the area; or, the vertex coordinates of the upper right corner of the area, the right corner of the area The vertex coordinates of the lower corner and the center point coordinates of the area; or, the vertex coordinates of the upper right corner of the area, the vertex coordinates of the upper left corner of the area, and the center point coordinates of the area; or, the vertex coordinates of the lower right corner of the area, the lower left corner of the area The vertex coordinates and the center point coordinates of the region; or, the vertex coordinates of the upper right corner of the region, the vertex coordinates of the lower right corner of the region, the vertex coordinates of the upper left corner of the region, the vertex coordinates of the lower left corner of the region, and the center point coordinates of the region.
本申请实施例的第二方面提供了一种模型训练方法,该方法包括:获取目标图像,目标图像包含多个文本;通过待训练模型对目标图像进行处理,得到目标文本在目标图像中的位置信息以及目标文本,多个文本包含目标文本,待训练模型用于:对目标图像进行编码,得到目标图像的特征;基于特征,获取位置信息;基于特征以及位置信息,获取目标文本;基于目标文本,对待训练模型进行训练,得到目标模型。The second aspect of the embodiment of the present application provides a model training method. The method includes: acquiring a target image, which contains multiple texts; processing the target image through the model to be trained, and obtaining the position of the target text in the target image. information and target text. Multiple texts contain target text. The model to be trained is used to: encode the target image to obtain the characteristics of the target image; obtain location information based on the characteristics; obtain the target text based on the characteristics and location information; based on the target text , train the model to be trained and obtain the target model.
上述方法训练得到的目标文本,具备文本获取功能。具体地,当需要从目标图像中提取目标文本时,可先获取包含多个文本的目标图像,并将目标图像输入至目标模型。接着,目标模型可对目标图像进行编码,从而得到目标图像的特征。然后,目标模型可对目标图像的特征进行处理,从而得到多个文本中的目标文本在目标图像中的位置信息。最后,目标模型可对目标图像的特征以及目标文本在目标图像中的位置信息做进一步的处理,从而得到目标文本。至此,则成功从目标图像中提取出了目标文本。前述过程中,目标模型在对目标图像的内容进行理解时,不仅考虑了目标图像的特征,还考虑了目标文本在目标图像中的位置信息,这样考虑的因素较为全面,可以对目标图像的内容进行充分且准确的理解,由此可见,目标模型按照这种方式从目标图像所呈现的多个文本中提取出的目标文本,通常是正确的文本。The target text trained by the above method has the text acquisition function. Specifically, when the target text needs to be extracted from the target image, a target image containing multiple texts can be obtained first, and the target image can be input to the target model. Then, the target model can encode the target image to obtain the characteristics of the target image. Then, the target model can process the features of the target image to obtain the position information of the target text in the target image among the multiple texts. Finally, the target model can further process the characteristics of the target image and the position information of the target text in the target image to obtain the target text. At this point, the target text has been successfully extracted from the target image. In the aforementioned process, when the target model understands the content of the target image, it not only considers the characteristics of the target image, but also considers the position information of the target text in the target image. In this way, the factors considered are more comprehensive and the content of the target image can be understood. With a full and accurate understanding, it can be seen that the target text extracted by the target model in this way from the multiple texts presented by the target image is usually the correct text.
在一种可能实现的方式中,待训练模型,用于基于特征,对目标文本在目标图像中的位置信息的第1个向量表示至位置信息的第i个向量表示进行解码,得到位置信息的第i+1个向量表示,i=1,...,X-1,X≥1,位置信息的第1个向量表示基于特征对预置的向量表示进行解码得到。In one possible implementation, the model to be trained is used to decode the first vector representation of the position information of the target text in the target image to the i-th vector representation of the position information based on the features, and obtain the position information. The i+1th vector representation, i=1,...,X-1,X≥1, is obtained by decoding the preset vector representation based on features.
在一种可能实现的方式中,待训练模型,用于基于特征,对位置信息,目标文本的第1个向量表示至目标文本的第j个向量表示进行解码,得到目标文本的第j+1个向量表示,j=1,...,Y-1,Y≥1,目标文本的第1个向量表示基于特征对位置信息进行解码得到。In one possible implementation, the model to be trained is used to decode the position information, the first vector representation of the target text to the jth vector representation of the target text based on the features, and obtain the j+1th vector representation of the target text. vector representation, j=1,...,Y-1, Y≥1, the first vector representation of the target text is obtained by decoding the position information based on the features.
在一种可能实现的方式中,目标文本包含第一文本以及第二文本,位置信息包含第一文本在目标图像中的第一位置信息以及第二文本在目标图像中的第二位置信息,待训练模型,用于:基于特征,对第一位置信息的第1个向量表示至第一位置信息的第i个向量表示进行解码,得到第一位置信息的第i+1个向量表示,i=1,...,X-1,X≥1,第一位置信息的第1个向量表示基于特征对预置的向量表示进行解码得到;基于特征,对第一位置信息,第一文本,第二位置信息的第1个向量表示至第二位置信息的第k个向量表示进行解码,得到第一位置信息的第k+1个向量表示,k=1,...,Z-1,Z≥1,第二位置信息的第1个向量表示基于特征对第一位置信息以及第一文本进行解码得到。In a possible implementation manner, the target text includes a first text and a second text, and the position information includes first position information of the first text in the target image and second position information of the second text in the target image. The training model is used to: decode the first vector representation of the first position information to the i-th vector representation of the first position information based on the features, and obtain the i+1-th vector representation of the first position information, i= 1,...,X-1, Decode the first vector representation of the second position information to the k-th vector representation of the second position information to obtain the k+1-th vector representation of the first position information, k=1,...,Z-1,Z ≥1, the first vector representation of the second position information is obtained by decoding the first position information and the first text based on the features.
在一种可能实现的方式中,待训练模型,用于:基于特征,对第一位置信息,第一文本的第1个向量表示至第一文本的第j个向量表示进行解码,得到第一文本的第j+1个向量表示,j=1,...,Y-1,Y≥1,第一文本的第1个向量表示基于特征对位置信息进行解码得到;基于特征,对第一位置信息,第一文本,第二位置信息,第二文本的第1个向量表示至第二文本的第t个向量表示进行解码,得到第二文本的第t+1个向量表示,t=1,...,U-1,U≥1,第二文本的第1个向量表示基于特征对第一位置信息,第一文本以及第二位置信息进行解码得到。In a possible implementation manner, the model to be trained is used to: decode the first position information, the first vector representation of the first text to the jth vector representation of the first text based on the features, and obtain the first The j+1th vector representation of the text, j=1,...,Y-1, Y≥1, the first vector representation of the first text is obtained by decoding the position information based on the feature; based on the feature, the first Decode the position information, the first text, the second position information, the first vector representation of the second text to the t-th vector representation of the second text, and obtain the t+1-th vector representation of the second text, t=1 ,...,U-1, U≥1, the first vector representation of the second text is obtained by decoding the first position information, the first text and the second position information based on the features.
在一种可能实现的方式中,待训练模型,还用于对位置信息的所有向量表示进行转换,得到目标文本在目标图像中所占据的区域的坐标。In one possible implementation, the model to be trained is also used to convert all vector representations of position information to obtain the coordinates of the area occupied by the target text in the target image.
在一种可能实现的方式中,待训练模型,还用于对目标文本的所有向量表示进行转换,得到目标文本的所有字符。基于目标文本,对待训练模型进行训练,得到目标模型包括:基于字符以及坐标,对待训练模型进行训练,得到目标模型。In one possible implementation, the model to be trained is also used to convert all vector representations of the target text to obtain all characters of the target text. Based on the target text, the to-be-trained model is trained to obtain the target model, including: based on characters and coordinates, the to-be-trained model is trained to obtain the target model.
在一种可能实现的方式中,待训练模型对目标文本以及位置信息所执行的转换可以为以下至少一种:基于循环神经网络的特征提取、基于多层感知机的特征提取以及基于时间卷积网络的特征提取。In a possible implementation manner, the conversion performed by the model to be trained on the target text and location information can be at least one of the following: feature extraction based on recurrent neural networks, feature extraction based on multi-layer perceptrons, and temporal convolution based Feature extraction of networks.
在一种可能实现的方式中,区域的坐标为以下至少一种:区域的左上角的顶点坐标以及区域的右下角的顶点坐标;或,区域的右上角的顶点坐标以及区域的左下角的顶点坐标;或,区域的四个角的顶点坐标;或,区域的左上角的顶点坐标、区域的左下角的顶点坐标以及区域的中心点坐标;或,区域的右上角的顶点坐标、区域的右下角的顶点坐标以及区域的中心点坐标;或,区域的右上角的顶点坐标、区域的左上角的顶点坐标以及区域的中心点坐标;或,区域的右下角的顶点坐标、区域的左下角的顶点坐标以及区域的中心点坐标;或,区域的右上角的顶点坐标、区域的右下角的顶点坐标、区域的左上角的顶点坐标、区域的左下角的顶点坐标以及区域的中心点坐标。In a possible implementation manner, the coordinates of the area are at least one of the following: the vertex coordinates of the upper left corner of the area and the vertex coordinates of the lower right corner of the area; or, the vertex coordinates of the upper right corner of the area and the vertex of the lower left corner of the area coordinates; or, the vertex coordinates of the four corners of the area; or, the vertex coordinates of the upper left corner of the area, the vertex coordinates of the lower left corner of the area, and the center point coordinates of the area; or, the vertex coordinates of the upper right corner of the area, the right corner of the area The vertex coordinates of the lower corner and the center point coordinates of the area; or, the vertex coordinates of the upper right corner of the area, the vertex coordinates of the upper left corner of the area, and the center point coordinates of the area; or, the vertex coordinates of the lower right corner of the area, the lower left corner of the area The vertex coordinates and the center point coordinates of the region; or, the vertex coordinates of the upper right corner of the region, the vertex coordinates of the lower right corner of the region, the vertex coordinates of the upper left corner of the region, the vertex coordinates of the lower left corner of the region, and the center point coordinates of the region.
本申请实施例的第三方面提供了一种文本获取装置,该装置包含目标模型,该装置包括:第一获取模块,用于获取目标图像,目标图像包含多个文本;编码模块,用于对目标图像进行编码,得到目标图像的特征;第二获取模块,用于基于特征,获取目标文本在目标图像中的位置信息,多个文本包含目标文本;第三获取模块,用于基于特征以及位置信息,获取目标文本。A third aspect of the embodiment of the present application provides a text acquisition device, which includes a target model. The device includes: a first acquisition module, used to acquire a target image, where the target image contains multiple texts; and an encoding module, used to The target image is encoded to obtain the characteristics of the target image; the second acquisition module is used to obtain the position information of the target text in the target image based on the characteristics, and multiple texts contain the target text; the third acquisition module is used to obtain the position information of the target text in the target image based on the characteristics and position; Information to get the target text.
从上述装置可以看出:当需要从目标图像中提取目标文本时,可先获取包含多个文本的目标图像,并将目标图像输入至目标模型。接着,目标模型可对目标图像进行编码,从而得到目标图像的特征。然后,目标模型可对目标图像的特征进行处理,从而得到多个文本中的目标文本在目标图像中的位置信息。最后,目标模型可对目标图像的特征以及目标文本在目标图像中的位置信息做进一步的处理,从而得到目标文本。至此,则成功从目标图像中提取出了目标文本。前述过程中,目标模型在对目标图像的内容进行理解时,不仅考虑了目标图像的特征,还考虑了目标文本在目标图像中的位置信息,这样考虑的因素较为全面,可以对目标图像的内容进行充分且准确的理解,由此可见,目标模型按照这种方式从目标图像所呈现的多个文本中提取出的目标文本,通常是正确的文本。It can be seen from the above device that when it is necessary to extract target text from a target image, a target image containing multiple texts can be obtained first, and the target image can be input to the target model. Then, the target model can encode the target image to obtain the characteristics of the target image. Then, the target model can process the features of the target image to obtain the position information of the target text in the target image among the multiple texts. Finally, the target model can further process the characteristics of the target image and the position information of the target text in the target image to obtain the target text. At this point, the target text has been successfully extracted from the target image. In the aforementioned process, when the target model understands the content of the target image, it not only considers the characteristics of the target image, but also considers the position information of the target text in the target image. In this way, the factors considered are more comprehensive and the content of the target image can be understood. With a full and accurate understanding, it can be seen that the target text extracted by the target model in this way from the multiple texts presented by the target image is usually the correct text.
在一种可能实现的方式中,第二获取模块,用于基于特征,对目标文本在目标图像中的位置信息的第1个向量表示至位置信息的第i个向量表示进行解码,得到位置信息的第i+1个向量表示,i=1,...,X-1,X≥1,位置信息的第1个向量表示基于特征对预置的向量表示进行解码得到。In a possible implementation manner, the second acquisition module is used to decode the first vector representation of the position information of the target text in the target image to the i-th vector representation of the position information based on the features to obtain the position information. The i+1th vector representation of i=1,...,X-1,X≥1, the first vector representation of the position information is obtained by decoding the preset vector representation based on the features.
在一种可能实现的方式中,第三获取模块,用于基于特征,对位置信息,目标文本的第1个向量表示至目标文本的第j个向量表示进行解码,得到目标文本的第j+1个向量表示,j=1,...,Y-1,Y≥1,目标文本的第1个向量表示基于特征对位置信息进行解码得到。In a possible implementation manner, the third acquisition module is used to decode the position information, the first vector representation of the target text to the jth vector representation of the target text based on the features, and obtain the j+th vector representation of the target text. 1 vector representation, j=1,...,Y-1, Y≥1, the first vector representation of the target text is obtained by decoding the position information based on the features.
在一种可能实现的方式中,目标文本包含第一文本以及第二文本,位置信息包含第一文本在目标图像中的第一位置信息以及第二文本在目标图像中的第二位置信息,第二获取模块,用于基于特征,对第一位置信息的第1个向量表示至第一位置信息的第i个向量表示进行解码,得到第一位置信息的第i+1个向量表示,i=1,...,X-1,X≥1,第一位置信息的第1个向量表示基于特征对预置的向量表示进行解码得到;基于特征,对第一位置信息,第一文本,第二位置信息的第1个向量表示至第二位置信息的第k个向量表示进行解码,得到第一位置信息的第k+1个向量表示,k=1,...,Z-1,Z≥1,第二位置信息的第1个向量表示基于特征对第一位置信息以及第一文本进行解码得到。In a possible implementation manner, the target text includes a first text and a second text, and the position information includes first position information of the first text in the target image and second position information of the second text in the target image. The second acquisition module is used to decode the first vector representation of the first position information to the i-th vector representation of the first position information based on the feature, and obtain the i+1-th vector representation of the first position information, i= 1,...,X-1, Decode the first vector representation of the second position information to the k-th vector representation of the second position information to obtain the k+1-th vector representation of the first position information, k=1,...,Z-1,Z ≥1, the first vector representation of the second position information is obtained by decoding the first position information and the first text based on the features.
在一种可能实现的方式中,第三获取模块,用于基于特征,对第一位置信息,第一文本的第1个向量表示至第一文本的第j个向量表示进行解码,得到第一文本的第j+1个向量表示,j=1,...,Y-1,Y≥1,第一文本的第1个向量表示基于特征对位置信息进行解码得到;基于特征,对第一位置信息,第一文本,第二位置信息,第二文本的第1个向量表示至第二文本的第t个向量表示进行解码,得到第二文本的第t+1个向量表示,t=1,...,U-1,U≥1,第二文本的第1个向量表示基于特征对第一位置信息,第一文本以及第二位置信息进行解码得到。In a possible implementation manner, the third acquisition module is used to decode the first position information, the first vector representation of the first text to the jth vector representation of the first text based on the feature, and obtain the first The j+1th vector representation of the text, j=1,...,Y-1, Y≥1, the first vector representation of the first text is obtained by decoding the position information based on the feature; based on the feature, the first Decode the position information, the first text, the second position information, the first vector representation of the second text to the t-th vector representation of the second text, and obtain the t+1-th vector representation of the second text, t=1 ,...,U-1, U≥1, the first vector representation of the second text is obtained by decoding the first position information, the first text and the second position information based on the features.
在一种可能实现的方式中,该装置还包括:第一转换模块,用于对位置信息的所有向量表示进行转换,得到目标文本在目标图像中所占据的区域的坐标。In a possible implementation manner, the device further includes: a first conversion module, configured to convert all vector representations of the position information to obtain the coordinates of the area occupied by the target text in the target image.
在一种可能实现的方式中,该装置还包括:第二转换模块,用于对目标文本的所有向量表示进行转换,得到目标文本的所有字符。In a possible implementation manner, the device further includes: a second conversion module, configured to convert all vector representations of the target text to obtain all characters of the target text.
在一种可能实现的方式中,目标模型对目标文本以及位置信息所执行的转换可以为以下至少一种:基于循环神经网络的特征提取、基于多层感知机的特征提取以及基于时间卷积网络的特征提取。In a possible implementation manner, the conversion performed by the target model on the target text and location information can be at least one of the following: feature extraction based on recurrent neural networks, feature extraction based on multi-layer perceptrons, and temporal convolutional networks. feature extraction.
在一种可能实现的方式中,区域的坐标为以下至少一种:区域的左上角的顶点坐标以及区域的右下角的顶点坐标;或,区域的右上角的顶点坐标以及区域的左下角的顶点坐标;或,区域的四个角的顶点坐标;或,区域的左上角的顶点坐标、区域的左下角的顶点坐标以及区域的中心点坐标;或,区域的右上角的顶点坐标、区域的右下角的顶点坐标以及区域的中心点坐标;或,区域的右上角的顶点坐标、区域的左上角的顶点坐标以及区域的中心点坐标;或,区域的右下角的顶点坐标、区域的左下角的顶点坐标以及区域的中心点坐标;或,区域的右上角的顶点坐标、区域的右下角的顶点坐标、区域的左上角的顶点坐标、区域的左下角的顶点坐标以及区域的中心点坐标。In a possible implementation manner, the coordinates of the area are at least one of the following: the vertex coordinates of the upper left corner of the area and the vertex coordinates of the lower right corner of the area; or, the vertex coordinates of the upper right corner of the area and the vertex of the lower left corner of the area coordinates; or, the vertex coordinates of the four corners of the area; or, the vertex coordinates of the upper left corner of the area, the vertex coordinates of the lower left corner of the area, and the center point coordinates of the area; or, the vertex coordinates of the upper right corner of the area, the right corner of the area The vertex coordinates of the lower corner and the center point coordinates of the area; or, the vertex coordinates of the upper right corner of the area, the vertex coordinates of the upper left corner of the area, and the center point coordinates of the area; or, the vertex coordinates of the lower right corner of the area, the lower left corner of the area The vertex coordinates and the center point coordinates of the region; or, the vertex coordinates of the upper right corner of the region, the vertex coordinates of the lower right corner of the region, the vertex coordinates of the upper left corner of the region, the vertex coordinates of the lower left corner of the region, and the center point coordinates of the region.
本申请实施例的第四方面提供了一种模型训练装置,该装置包括:获取模块,用于获取目标图像,目标图像包含多个文本;处理模块,用于通过待训练模型对目标图像进行处理,得到目标文本在目标图像中的位置信息以及目标文本,多个文本包含目标文本,待训练模型用于:对目标图像进行编码,得到目标图像的特征;基于特征,获取位置信息;基于特征以及位置信息,获取目标文本;训练模块,用于基于目标文本,对待训练模型进行训练,得到目标模型。The fourth aspect of the embodiment of the present application provides a model training device. The device includes: an acquisition module, used to acquire a target image, where the target image contains multiple texts; and a processing module, used to process the target image through the model to be trained. , obtain the position information of the target text in the target image and the target text. Multiple texts contain the target text. The model to be trained is used to: encode the target image to obtain the characteristics of the target image; obtain the position information based on the characteristics; based on the characteristics and Location information is used to obtain the target text; the training module is used to train the model to be trained based on the target text to obtain the target model.
上述装置训练得到的目标文本,具备文本获取功能。具体地,当需要从目标图像中提取目标文本时,可先获取包含多个文本的目标图像,并将目标图像输入至目标模型。接着,目标模型可对目标图像进行编码,从而得到目标图像的特征。然后,目标模型可对目标图像的特征进行处理,从而得到多个文本中的目标文本在目标图像中的位置信息。最后,目标模型可对目标图像的特征以及目标文本在目标图像中的位置信息做进一步的处理,从而得到目标文本。至此,则成功从目标图像中提取出了目标文本。前述过程中,目标模型在对目标图像的内容进行理解时,不仅考虑了目标图像的特征,还考虑了目标文本在目标图像中的位置信息,这样考虑的因素较为全面,可以对目标图像的内容进行充分且准确的理解,由此可见,目标模型按照这种方式从目标图像所呈现的多个文本中提取出的目标文本,通常是正确的文本。The target text obtained by training with the above device has a text acquisition function. Specifically, when the target text needs to be extracted from the target image, a target image containing multiple texts can be obtained first, and the target image can be input to the target model. Then, the target model can encode the target image to obtain the characteristics of the target image. Then, the target model can process the features of the target image to obtain the position information of the target text in the target image among the multiple texts. Finally, the target model can further process the characteristics of the target image and the position information of the target text in the target image to obtain the target text. At this point, the target text has been successfully extracted from the target image. In the aforementioned process, when the target model understands the content of the target image, it not only considers the characteristics of the target image, but also considers the position information of the target text in the target image. In this way, the factors considered are more comprehensive and the content of the target image can be understood. With a full and accurate understanding, it can be seen that the target text extracted by the target model in this way from the multiple texts presented by the target image is usually the correct text.
在一种可能实现的方式中,待训练模型,用于基于特征,对目标文本在目标图像中的位置信息的第1个向量表示至位置信息的第i个向量表示进行解码,得到位置信息的第i+1个向量表示,i=1,...,X-1,X≥1,位置信息的第1个向量表示基于特征对预置的向量表示进行解码得到。In one possible implementation, the model to be trained is used to decode the first vector representation of the position information of the target text in the target image to the i-th vector representation of the position information based on the features, and obtain the position information. The i+1th vector representation, i=1,...,X-1,X≥1, is obtained by decoding the preset vector representation based on features.
在一种可能实现的方式中,待训练模型,用于基于特征,对位置信息,目标文本的第1个向量表示至目标文本的第j个向量表示进行解码,得到目标文本的第j+1个向量表示,j=1,...,Y-1,Y≥1,目标文本的第1个向量表示基于特征对位置信息进行解码得到。In one possible implementation, the model to be trained is used to decode the position information, the first vector representation of the target text to the jth vector representation of the target text based on the features, and obtain the j+1th vector representation of the target text. vector representation, j=1,...,Y-1, Y≥1, the first vector representation of the target text is obtained by decoding the position information based on the features.
在一种可能实现的方式中,目标文本包含第一文本以及第二文本,位置信息包含第一文本在目标图像中的第一位置信息以及第二文本在目标图像中的第二位置信息,待训练模型,用于:基于特征,对第一位置信息的第1个向量表示至第一位置信息的第i个向量表示进行解码,得到第一位置信息的第i+1个向量表示,i=1,...,X-1,X≥1,第一位置信息的第1个向量表示基于特征对预置的向量表示进行解码得到;基于特征,对第一位置信息,第一文本,第二位置信息的第1个向量表示至第二位置信息的第k个向量表示进行解码,得到第一位置信息的第k+1个向量表示,k=1,...,Z-1,Z≥1,第二位置信息的第1个向量表示基于特征对第一位置信息以及第一文本进行解码得到。In a possible implementation manner, the target text includes a first text and a second text, and the position information includes first position information of the first text in the target image and second position information of the second text in the target image. The training model is used to: decode the first vector representation of the first position information to the i-th vector representation of the first position information based on the features, and obtain the i+1-th vector representation of the first position information, i= 1,...,X-1, Decode the first vector representation of the second position information to the k-th vector representation of the second position information to obtain the k+1-th vector representation of the first position information, k=1,...,Z-1,Z ≥1, the first vector representation of the second position information is obtained by decoding the first position information and the first text based on the features.
在一种可能实现的方式中,待训练模型,用于:基于特征,对第一位置信息,第一文本的第1个向量表示至第一文本的第j个向量表示进行解码,得到第一文本的第j+1个向量表示,j=1,...,Y-1,Y≥1,第一文本的第1个向量表示基于特征对位置信息进行解码得到;基于特征,对第一位置信息,第一文本,第二位置信息,第二文本的第1个向量表示至第二文本的第t个向量表示进行解码,得到第二文本的第t+1个向量表示,t=1,...,U-1,U≥1,第二文本的第1个向量表示基于特征对第一位置信息,第一文本以及第二位置信息进行解码得到。In a possible implementation manner, the model to be trained is used to: decode the first position information, the first vector representation of the first text to the jth vector representation of the first text based on the features, and obtain the first The j+1th vector representation of the text, j=1,...,Y-1, Y≥1, the first vector representation of the first text is obtained by decoding the position information based on the feature; based on the feature, the first Decode the position information, the first text, the second position information, the first vector representation of the second text to the t-th vector representation of the second text, and obtain the t+1-th vector representation of the second text, t=1 ,...,U-1, U≥1, the first vector representation of the second text is obtained by decoding the first position information, the first text and the second position information based on the features.
在一种可能实现的方式中,待训练模型,还用于对位置信息的所有向量表示进行转换,得到目标文本在目标图像中所占据的区域的坐标。In one possible implementation, the model to be trained is also used to convert all vector representations of position information to obtain the coordinates of the area occupied by the target text in the target image.
在一种可能实现的方式中,待训练模型,还用于对目标文本的所有向量表示进行转换,得到目标文本的所有字符。训练模块,用于基于字符以及坐标,对待训练模型进行训练,得到目标模型。In one possible implementation, the model to be trained is also used to convert all vector representations of the target text to obtain all characters of the target text. The training module is used to train the model to be trained based on characters and coordinates to obtain the target model.
在一种可能实现的方式中,待训练模型对目标文本以及位置信息所执行的转换可以为以下至少一种:基于循环神经网络的特征提取、基于多层感知机的特征提取以及基于时间卷积网络的特征提取。In a possible implementation manner, the conversion performed by the model to be trained on the target text and location information can be at least one of the following: feature extraction based on recurrent neural networks, feature extraction based on multi-layer perceptrons, and temporal convolution based Feature extraction of networks.
在一种可能实现的方式中,区域的坐标为以下至少一种:区域的左上角的顶点坐标以及区域的右下角的顶点坐标;或,区域的右上角的顶点坐标以及区域的左下角的顶点坐标;或,区域的四个角的顶点坐标;或,区域的左上角的顶点坐标、区域的左下角的顶点坐标以及区域的中心点坐标;或,区域的右上角的顶点坐标、区域的右下角的顶点坐标以及区域的中心点坐标;或,区域的右上角的顶点坐标、区域的左上角的顶点坐标以及区域的中心点坐标;或,区域的右下角的顶点坐标、区域的左下角的顶点坐标以及区域的中心点坐标;或,区域的右上角的顶点坐标、区域的右下角的顶点坐标、区域的左上角的顶点坐标、区域的左下角的顶点坐标以及区域的中心点坐标。In a possible implementation manner, the coordinates of the area are at least one of the following: the vertex coordinates of the upper left corner of the area and the vertex coordinates of the lower right corner of the area; or, the vertex coordinates of the upper right corner of the area and the vertex of the lower left corner of the area coordinates; or, the vertex coordinates of the four corners of the area; or, the vertex coordinates of the upper left corner of the area, the vertex coordinates of the lower left corner of the area, and the center point coordinates of the area; or, the vertex coordinates of the upper right corner of the area, the right corner of the area The vertex coordinates of the lower corner and the center point coordinates of the area; or, the vertex coordinates of the upper right corner of the area, the vertex coordinates of the upper left corner of the area, and the center point coordinates of the area; or, the vertex coordinates of the lower right corner of the area, the lower left corner of the area The vertex coordinates and the center point coordinates of the region; or, the vertex coordinates of the upper right corner of the region, the vertex coordinates of the lower right corner of the region, the vertex coordinates of the upper left corner of the region, the vertex coordinates of the lower left corner of the region, and the center point coordinates of the region.
本申请实施例的第五方面提供了一种故障预测装置,该装置包括存储器和处理器;存储器存储有代码,处理器被配置为执行代码,当代码被执行时,故障预测装置执行如第一方面或第一方面中任意一种可能的实现方式所述的方法。The fifth aspect of the embodiment of the present application provides a fault prediction device, which includes a memory and a processor; the memory stores codes, and the processor is configured to execute the code. When the code is executed, the fault prediction device performs the first step The method described in any possible implementation manner of the aspect or the first aspect.
本申请实施例的第六方面提供了一种模型训练装置,该装置包括存储器和处理器;存储器存储有代码,处理器被配置为执行代码,当代码被执行时,模型训练装置执行如第二方面或第二方面中任意一种可能的实现方式所述的方法。A sixth aspect of the embodiment of the present application provides a model training device, which includes a memory and a processor; the memory stores code, and the processor is configured to execute the code. When the code is executed, the model training device executes the second step. The method described in any possible implementation manner of the aspect or the second aspect.
本申请实施例的第七方面提供了一种电路系统,该电路系统包括处理电路,该处理电路配置为执行如第一方面、第一方面中任意一种可能的实现方式、第二方面或第二方面中任意一种可能的实现方式所述的方法。The seventh aspect of the embodiment of the present application provides a circuit system. The circuit system includes a processing circuit configured to perform the first aspect, any possible implementation of the first aspect, the second aspect, or the third aspect. The method described in any one of the possible implementation methods in the two aspects.
本申请实施例的第八方面提供了一种芯片系统,该芯片系统包括处理器,用于调用存储器中存储的计算机程序或计算机指令,以使得该处理器执行如第一方面、第一方面中任意一种可能的实现方式、第二方面或第二方面中任意一种可能的实现方式所述的方法。An eighth aspect of the embodiments of the present application provides a chip system. The chip system includes a processor for calling a computer program or computer instructions stored in a memory, so that the processor executes the steps described in the first aspect and the first aspect. Any possible implementation manner, the second aspect, or the method described in any possible implementation manner in the second aspect.
在一种可能的实现方式中,该处理器通过接口与存储器耦合。In one possible implementation, the processor is coupled to the memory through an interface.
在一种可能的实现方式中,该芯片系统还包括存储器,该存储器中存储有计算机程序或计算机指令。In a possible implementation, the chip system further includes a memory, and computer programs or computer instructions are stored in the memory.
本申请实施例的第九方面提供了一种计算机存储介质,该计算机存储介质存储有计算机程序,该程序在由计算机执行时,使得计算机实施如第一方面、第一方面中任意一种可能的实现方式、第二方面或第二方面中任意一种可能的实现方式所述的方法。A ninth aspect of the embodiments of the present application provides a computer storage medium. The computer storage medium stores a computer program. When the program is executed by a computer, the computer implements any one of the possible methods in the first aspect and the first aspect. The method described in the implementation, the second aspect, or any possible implementation of the second aspect.
本申请实施例的第十方面提供了一种计算机程序产品,该计算机程序产品存储有指令,该指令在由计算机执行时,使得计算机实施如第一方面、第一方面中任意一种可能的实现方式、第二方面或第二方面中任意一种可能的实现方式所述的方法。A tenth aspect of the embodiments of the present application provides a computer program product. The computer program product stores instructions. When the instructions are executed by a computer, the computer implements any one of the possible implementations of the first aspect and the first aspect. method, the second aspect, or any possible implementation manner of the second aspect.
本申请实施例中,当需要从目标图像中提取目标文本时,可先获取包含多个文本的目标图像,并将目标图像输入至目标模型。接着,目标模型可对目标图像进行编码,从而得到目标图像的特征。然后,目标模型可对目标图像的特征进行处理,从而得到多个文本中的目标文本在目标图像中的位置信息。最后,目标模型可对目标图像的特征以及目标文本在目标图像中的位置信息做进一步的处理,从而得到目标文本。至此,则成功从目标图像中提取出了目标文本。前述过程中,目标模型在对目标图像的内容进行理解时,不仅考虑了目标图像的特征,还考虑了目标文本在目标图像中的位置信息,这样考虑的因素较为全面,可以对目标图像的内容进行充分且准确的理解,由此可见,目标模型按照这种方式从目标图像所呈现的多个文本中提取出的目标文本,通常是正确的文本。In the embodiment of the present application, when it is necessary to extract target text from a target image, a target image containing multiple texts can be obtained first, and the target image can be input into the target model. Then, the target model can encode the target image to obtain the characteristics of the target image. Then, the target model can process the features of the target image to obtain the position information of the target text in the target image among the multiple texts. Finally, the target model can further process the characteristics of the target image and the position information of the target text in the target image to obtain the target text. At this point, the target text has been successfully extracted from the target image. In the aforementioned process, when the target model understands the content of the target image, it not only considers the characteristics of the target image, but also considers the position information of the target text in the target image. In this way, the factors considered are more comprehensive and the content of the target image can be understood. With a full and accurate understanding, it can be seen that the target text extracted by the target model in this way from the multiple texts presented by the target image is usually the correct text.
附图说明Description of the drawings
图1为人工智能主体框架的一种结构示意图;Figure 1 is a structural schematic diagram of the main framework of artificial intelligence;
图2a为本申请实施例提供的文本获取系统的一个结构示意图;Figure 2a is a schematic structural diagram of a text acquisition system provided by an embodiment of the present application;
图2b为本申请实施例提供的文本获取系统的另一结构示意图;Figure 2b is another structural schematic diagram of the text acquisition system provided by the embodiment of the present application;
图2c为本申请实施例提供的文本获取的相关设备的一个示意图;Figure 2c is a schematic diagram of related equipment for text acquisition provided by the embodiment of the present application;
图3为本申请实施例提供的系统100架构的一个示意图;Figure 3 is a schematic diagram of the architecture of the system 100 provided by the embodiment of the present application;
图4为本申请实施例提供的目标模型的一个结构示意图;Figure 4 is a schematic structural diagram of the target model provided by the embodiment of the present application;
图5为本申请实施例提供的文本获取方法的一个流程示意图;Figure 5 is a schematic flow chart of the text acquisition method provided by the embodiment of the present application;
图6为本申请实施例提供的目标模型的另一结构示意图;Figure 6 is another structural schematic diagram of the target model provided by the embodiment of the present application;
图7为本申请实施例提供的目标模型的另一结构示意图;Figure 7 is another structural schematic diagram of the target model provided by the embodiment of the present application;
图8为本申请实施例提供的目标模型的另一结构示意图;Figure 8 is another structural schematic diagram of the target model provided by the embodiment of the present application;
图9为本申请实施例提供的文档问答的一个示意图;Figure 9 is a schematic diagram of document question and answer provided by the embodiment of the present application;
图10为本申请实施例提供的目标模型的另一结构示意图;Figure 10 is another structural schematic diagram of the target model provided by the embodiment of the present application;
图11为本申请实施例提供的信息抽取的一个示意图;Figure 11 is a schematic diagram of information extraction provided by the embodiment of the present application;
图12为本申请实施例提供的模型训练方法的一个流程示意图;Figure 12 is a schematic flow chart of the model training method provided by the embodiment of the present application;
图13为本申请实施例提供的文本获取装置的一个结构示意图;Figure 13 is a schematic structural diagram of a text acquisition device provided by an embodiment of the present application;
图14为本申请实施例提供的模型训练装置的一个结构示意图;Figure 14 is a schematic structural diagram of the model training device provided by the embodiment of the present application;
图15为本申请实施例提供的执行设备的一个结构示意图;Figure 15 is a schematic structural diagram of an execution device provided by an embodiment of the present application;
图16为本申请实施例提供的训练设备的一个结构示意图;Figure 16 is a schematic structural diagram of the training equipment provided by the embodiment of the present application;
图17为本申请实施例提供的芯片的一个结构示意图。Figure 17 is a schematic structural diagram of a chip provided by an embodiment of the present application.
具体实施方式Detailed ways
本申请实施例提供了一种文本获取方法及其相关设备,可从目标图像中获取准确的目标文本。The embodiment of the present application provides a text acquisition method and related equipment, which can obtain accurate target text from a target image.
本申请的说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的术语在适当情况下可以互换,这仅仅是描述本申请的实施例中对相同属性的对象在描述时所采用的区分方式。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,以便包含一系列单元的过程、方法、系统、产品或设备不必限于那些单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它单元。The terms "first", "second", etc. in the description and claims of this application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the terms so used are interchangeable under appropriate circumstances, and are merely a way of distinguishing objects with the same attributes in describing the embodiments of the present application. Furthermore, the terms "include" and "having" and any variations thereof, are intended to cover non-exclusive inclusions, such that a process, method, system, product or apparatus comprising a series of elements need not be limited to those elements, but may include not explicitly other elements specifically listed or inherent to such processes, methods, products or equipment.
随着AI技术的快速发展,越来越多的用户使用预训练的神经网络模型(也可以称为预训练模型),来完成针对呈现有多个文本的图像的分析处理,也就是说,预训练的神经网络模型可以对图像进行充分理解,以从图像所呈现的多个文本中,提取出目标文本。With the rapid development of AI technology, more and more users use pre-trained neural network models (also called pre-trained models) to complete the analysis and processing of images presenting multiple texts. In other words, pre-trained neural network models The trained neural network model can fully understand the image to extract the target text from the multiple texts presented in the image.
相关技术中,预训练的神经网络模型可以包含编码器和解码器。当用户需要从图像所呈现的多个文本中提取目标文本时时,可将图像输入至神经网络模型中。那么,编码器可对图像进行编码,从而得到图像的特征,并将图像的特征提供给解码器。然后,解码器可基于图像的特征进行解码,从而得到并给用户返回目标文本。例如,当用户需要从火车票的图像中提取出乘车人的姓名,可将该图像输入至预训练模型中,预训练模型可提取该图像的特征,并基于该图像的特征,从该图像所呈现的“乘车人的姓名”、“班次”、“时间”、“出发地”以及“目的地”等多个文本中,提取出“乘车人的姓名”这一文本,并返回给用户。In related art, a pre-trained neural network model may include an encoder and a decoder. When the user needs to extract target text from multiple texts presented in the image, the image can be input into the neural network model. Then, the encoder can encode the image to obtain the features of the image and provide the features of the image to the decoder. The decoder can then decode based on the characteristics of the image to obtain and return the target text to the user. For example, when a user needs to extract the name of a passenger from an image of a train ticket, the image can be input into the pre-trained model. The pre-trained model can extract the features of the image and based on the features of the image, extract the name of the passenger from the image. From the presented multiple texts such as "Passenger's Name", "Flight", "Time", "Departure Place" and "Destination", the text "Passenger's Name" is extracted and returned to user.
上述过程中,神经网络模型是基于图像的特征,来对图像的内容进行理解,以从图像所呈现的多个文本中提取出目标文本。但是,神经网络模型在对图像进行理解时,所考虑的因素较为单一,导致模型最终得到的目标文本可能不是准确的文本。In the above process, the neural network model understands the content of the image based on the characteristics of the image to extract the target text from the multiple texts presented in the image. However, when the neural network model understands images, the factors it considers are relatively single, so the target text finally obtained by the model may not be accurate text.
进一步地,上述过程中,神经网络模型通常仅输出纯文字的目标文本给用户,无法为用户提供合理的输出解释(也就是无法解释模型会提取出目标文本)和可视化交互(也就是无法额外提供除文字之外的一些跟目标文本相关的其余内容),降低了用户体验,Furthermore, in the above process, the neural network model usually only outputs pure text target text to the user, and cannot provide the user with reasonable output explanation (that is, it cannot explain that the model will extract the target text) and visual interaction (that is, it cannot provide additional In addition to text, some other content related to the target text), which reduces the user experience.
更进一步地,上述过程中,神经网络模型的输出长度是有限制的,而且在一些特殊场景中,用户往往需要获取较长的文本,而模型无法满足该需求,进一步降低了用户体验。Furthermore, in the above process, the output length of the neural network model is limited, and in some special scenarios, users often need to obtain longer text, and the model cannot meet this demand, further reducing the user experience.
为了解决上述问题,本申请实施例提供一种文本获取方法,该方法该方法可结合人工智能(artificial intelligence,AI)技术实现。AI技术是利用数字计算机或者数字计算机控制的机器模拟、延伸和扩展人的智能的技术学科,AI技术通过感知环境、获取知识并使用知识获得最佳结果。换句话说,人工智能技术是计算机科学的一个分支,它企图了解智能的实质,并生产出一种新的能以人类智能相似的方式做出反应的智能机器。利用人工智能进行数据处理是人工智能常见的一个应用方式。In order to solve the above problem, embodiments of the present application provide a text acquisition method, which method can be implemented in combination with artificial intelligence (AI) technology. AI technology is a technical discipline that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence. AI technology obtains the best results by perceiving the environment, acquiring knowledge and using knowledge. In other words, artificial intelligence technology is a branch of computer science that attempts to understand the nature of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Using artificial intelligence for data processing is a common application method of artificial intelligence.
首先对人工智能系统总体工作流程进行描述,请参见图1,图1为人工智能主体框架的一种结构示意图,下面从“智能信息链”(水平轴)和“IT价值链”(垂直轴)两个维度对上述人工智能主题框架进行阐述。其中,“智能信息链”反映从数据的获取到处理的一列过程。举例来说,可以是智能信息感知、智能信息表示与形成、智能推理、智能决策、智能执行与输出的一般过程。在这个过程中,数据经历了“数据—信息—知识—智慧”的凝练过程。“IT价值链”从人智能的底层基础设施、信息(提供和处理技术实现)到系统的产业生态过程,反映人工智能为信息技术产业带来的价值。First, the overall workflow of the artificial intelligence system is described. Please refer to Figure 1. Figure 1 is a structural schematic diagram of the main framework of artificial intelligence. The following is from the "intelligent information chain" (horizontal axis) and "IT value chain" (vertical axis) The above artificial intelligence theme framework is elaborated on in two dimensions. Among them, the "intelligent information chain" reflects a series of processes from data acquisition to processing. For example, it can be the general process of intelligent information perception, intelligent information representation and formation, intelligent reasoning, intelligent decision-making, intelligent execution and output. In this process, the data has gone through the condensation process of "data-information-knowledge-wisdom". The "IT value chain" reflects the value that artificial intelligence brings to the information technology industry, from the underlying infrastructure of human intelligence and information (providing and processing technology implementation) to the systematic industrial ecological process.
(1)基础设施(1)Infrastructure
基础设施为人工智能系统提供计算能力支持,实现与外部世界的沟通,并通过基础平台实现支撑。通过传感器与外部沟通;计算能力由智能芯片(CPU、NPU、GPU、ASIC、FPGA等硬件加速芯片)提供;基础平台包括分布式计算框架及网络等相关的平台保障和支持,可以包括云存储和计算、互联互通网络等。举例来说,传感器和外部沟通获取数据,这些数据提供给基础平台提供的分布式计算系统中的智能芯片进行计算。Infrastructure provides computing power support for artificial intelligence systems, enables communication with the external world, and supports it through basic platforms. Communicate with the outside through sensors; computing power is provided by smart chips (hardware acceleration chips such as CPU, NPU, GPU, ASIC, FPGA, etc.); the basic platform includes distributed computing framework and network and other related platform guarantees and support, which can include cloud storage and Computing, interconnection networks, etc. For example, sensors communicate with the outside world to obtain data, which are provided to smart chips in the distributed computing system provided by the basic platform for calculation.
(2)数据(2)Data
基础设施的上一层的数据用于表示人工智能领域的数据来源。数据涉及到图形、图像、语音、文本,还涉及到传统设备的物联网数据,包括已有系统的业务数据以及力、位移、液位、温度、湿度等感知数据。Data from the upper layer of the infrastructure is used to represent data sources in the field of artificial intelligence. The data involves graphics, images, voice, and text, as well as IoT data of traditional devices, including business data of existing systems and sensory data such as force, displacement, liquid level, temperature, and humidity.
(3)数据处理(3)Data processing
数据处理通常包括数据训练,机器学习,深度学习,搜索,推理,决策等方式。Data processing usually includes data training, machine learning, deep learning, search, reasoning, decision-making and other methods.
其中,机器学习和深度学习可以对数据进行符号化和形式化的智能信息建模、抽取、预处理、训练等。Among them, machine learning and deep learning can perform symbolic and formal intelligent information modeling, extraction, preprocessing, training, etc. on data.
推理是指在计算机或智能系统中,模拟人类的智能推理方式,依据推理控制策略,利用形式化的信息进行机器思维和求解问题的过程,典型的功能是搜索与匹配。Reasoning refers to the process of simulating human intelligent reasoning in computers or intelligent systems, using formal information to perform machine thinking and problem solving based on reasoning control strategies. Typical functions are search and matching.
决策是指智能信息经过推理后进行决策的过程,通常提供分类、排序、预测等功能。Decision-making refers to the process of decision-making after intelligent information is reasoned, and usually provides functions such as classification, sorting, and prediction.
(4)通用能力(4) General ability
对数据经过上面提到的数据处理后,进一步基于数据处理的结果可以形成一些通用的能力,比如可以是算法或者一个通用系统,例如,翻译,文本的分析,计算机视觉的处理,语音识别,图像的识别等等。After the data is processed as mentioned above, some general capabilities can be formed based on the results of further data processing, such as algorithms or a general system, such as translation, text analysis, computer vision processing, speech recognition, and image processing. identification, etc.
(5)智能产品及行业应用(5) Intelligent products and industry applications
智能产品及行业应用指人工智能系统在各领域的产品和应用,是对人工智能整体解决方案的封装,将智能信息决策产品化、实现落地应用,其应用领域主要包括:智能终端、智能交通、智能医疗、自动驾驶、智慧城市等。Intelligent products and industry applications refer to the products and applications of artificial intelligence systems in various fields. They are the encapsulation of overall artificial intelligence solutions, productizing intelligent information decision-making and realizing practical applications. Its application fields mainly include: intelligent terminals, intelligent transportation, Smart healthcare, autonomous driving, smart cities, etc.
接下来介绍几种本申请的应用场景。Next, several application scenarios of this application will be introduced.
图2a为本申请实施例提供的文本获取系统的一个结构示意图,该文本获取系统包括用户设备以及数据处理设备。其中,用户设备包括手机、个人电脑或者信息处理中心等智能终端。用户设备为文本获取的发起端,作为文本获取请求的发起方,通常由用户通过用户设备发起请求。Figure 2a is a schematic structural diagram of a text acquisition system provided by an embodiment of the present application. The text acquisition system includes user equipment and data processing equipment. Among them, user equipment includes smart terminals such as mobile phones, personal computers, or information processing centers. The user device is the initiator of text acquisition. As the initiator of the text acquisition request, the user usually initiates the request through the user device.
上述数据处理设备可以是云服务器、网络服务器、应用服务器以及管理服务器等具有数据处理功能的设备或服务器。数据处理设备通过交互接口接收来自智能终端的文本处理请求,再通过存储数据的存储器以及数据处理的处理器环节进行机器学习,深度学习,搜索,推理,决策等方式的文本处理。数据处理设备中的存储器可以是一个统称,包括本地存储以及存储历史数据的数据库,数据库可以在数据处理设备上,也可以在其它网络服务器上。The above-mentioned data processing equipment may be a cloud server, a network server, an application server, a management server, and other equipment or servers with data processing functions. The data processing device receives text processing requests from smart terminals through interactive interfaces, and then performs text processing in machine learning, deep learning, search, reasoning, decision-making, etc. through the memory that stores data and the processor that processes data. The memory in the data processing device can be a general term, including local storage and a database that stores historical data. The database can be on the data processing device or on other network servers.
在图2a所示的文本获取系统中,用户设备可以接收用户的指令,例如用户设备可以获取用户输入/选择的一个包含多个文本的目标图像,然后向数据处理设备发起请求,使得数据处理设备针对用户设备得到的目标图像执行图像处理应用,从而得到针对该图像的对应的处理结果。示例性的,用户设备可以获取用户输入的一个目标图像(目标图像所呈现的内容包含多个文本),然后向数据处理设备发起目标图像的处理请求,使得数据处理设备对目标图像进行一系列的处理,从而得到目标图像的处理结果,即目标图像所包含的多个文本中的目标文本以及目标文本在目标图像中的位置信息。In the text acquisition system shown in Figure 2a, the user device can receive the user's instructions. For example, the user device can acquire a target image containing multiple texts input/selected by the user, and then initiate a request to the data processing device, so that the data processing device The image processing application is executed on the target image obtained by the user device, thereby obtaining a corresponding processing result for the image. For example, the user device can obtain a target image input by the user (the content presented by the target image includes multiple texts), and then initiate a processing request for the target image to the data processing device, so that the data processing device performs a series of processing on the target image. Processing, thereby obtaining the processing result of the target image, that is, the target text among the multiple texts contained in the target image and the position information of the target text in the target image.
在图2a中,数据处理设备可以执行本申请实施例的文本获取方法。In Figure 2a, the data processing device can execute the text acquisition method according to the embodiment of the present application.
图2b为本申请实施例提供的文本获取系统的另一结构示意图,在图2b中,用户设备直接作为数据处理设备,该用户设备能够直接获取来自用户的输入并直接由用户设备本身的硬件进行处理,具体过程与图2a相似,可参考上面的描述,在此不再赘述。Figure 2b is another structural schematic diagram of a text acquisition system provided by an embodiment of the present application. In Figure 2b, the user equipment directly serves as a data processing device. The user equipment can directly obtain input from the user and directly process it by the hardware of the user equipment itself. Processing, the specific process is similar to Figure 2a, please refer to the above description, and will not be repeated here.
在图2b所示的文本获取系统中,用户设备可以接收用户的指令,例如用户设备可以获取用户输入的一个目标图像(目标图像所呈现的内容包含多个文本),然后对目标图像进行一系列的处理,从而得到目标图像的处理结果,即目标图像所包含的多个文本中的目标文本以及目标文本在目标图像中的位置信息。In the text acquisition system shown in Figure 2b, the user device can receive the user's instructions. For example, the user device can acquire a target image input by the user (the content presented by the target image contains multiple texts), and then perform a series of operations on the target image. processing, thereby obtaining the processing result of the target image, that is, the target text among the multiple texts contained in the target image and the position information of the target text in the target image.
在图2b中,用户设备自身就可以执行本申请实施例的文本获取方法。In Figure 2b, the user equipment itself can execute the text acquisition method according to the embodiment of the present application.
图2c为本申请实施例提供的文本获取的相关设备的一个示意图。Figure 2c is a schematic diagram of related equipment for text acquisition provided by an embodiment of the present application.
上述图2a和图2b中的用户设备具体可以是图2c中的本地设备301或者本地设备302,图2a中的数据处理设备具体可以是图2c中的执行设备210,其中,数据存储系统250可以存储执行设备210的待处理数据,数据存储系统250可以集成在执行设备210上,也可以设置在云上或其它网络服务器上。The user equipment in Figure 2a and Figure 2b can be the local device 301 or the local device 302 in Figure 2c, and the data processing device in Figure 2a can be the execution device 210 in Figure 2c, where the data storage system 250 can To store the data to be processed by the execution device 210, the data storage system 250 can be integrated on the execution device 210, or can be set up on the cloud or other network servers.
图2a和图2b中的处理器可以通过神经网络模型或者其它模型(例如,基于支持向量机的模型)进行数据训练/机器学习/深度学习,并利用数据最终训练或者学习得到的模型针对图像执行图像处理应用,从而得到相应的处理结果。The processors in Figure 2a and Figure 2b can perform data training/machine learning/deep learning through neural network models or other models (for example, models based on support vector machines), and use the final trained or learned model to execute on the image using the data Image processing applications to obtain corresponding processing results.
图3为本申请实施例提供的系统100架构的一个示意图,在图3中,执行设备110配置输入/输出(input/output,I/O)接口112,用于与外部设备进行数据交互,用户可以通过客户设备140向I/O接口112输入数据,所述输入数据在本申请实施例中可以包括:各个待调度任务、可调用资源以及其他参数。Figure 3 is a schematic diagram of the architecture of the system 100 provided by the embodiment of the present application. In Figure 3, the execution device 110 is configured with an input/output (I/O) interface 112 for data interaction with external devices. The user Data can be input to the I/O interface 112 through the client device 140. In this embodiment of the present application, the input data may include: various to-be-scheduled tasks, callable resources, and other parameters.
在执行设备110对输入数据进行预处理,或者在执行设备110的计算模块111执行计算等相关的处理(比如进行本申请中神经网络的功能实现)过程中,执行设备110可以调用数据存储系统150中的数据、代码等以用于相应的处理,也可以将相应处理得到的数据、指令等存入数据存储系统150中。When the execution device 110 preprocesses the input data, or when the calculation module 111 of the execution device 110 performs calculation and other related processing (such as implementing the function of the neural network in this application), the execution device 110 can call the data storage system 150 The data, codes, etc. in the system can be used for corresponding processing, and the data, instructions, etc. obtained by corresponding processing can also be stored in the data storage system 150 .
最后,I/O接口112将处理结果返回给客户设备140,从而提供给用户。Finally, the I/O interface 112 returns the processing results to the client device 140, thereby providing them to the user.
值得说明的是,训练设备120可以针对不同的目标或称不同的任务,基于不同的训练数据生成相应的目标模型/规则,该相应的目标模型/规则即可以用于实现上述目标或完成上述任务,从而为用户提供所需的结果。其中,训练数据可以存储在数据库130中,且来自于数据采集设备160采集的训练样本。It is worth mentioning that the training device 120 can generate corresponding target models/rules based on different training data for different goals or different tasks, and the corresponding target models/rules can be used to achieve the above goals or complete the above tasks. , thereby providing users with the desired results. The training data may be stored in the database 130 and come from training samples collected by the data collection device 160 .
在图3中所示情况下,用户可以手动给定输入数据,该手动给定可以通过I/O接口112提供的界面进行操作。另一种情况下,客户设备140可以自动地向I/O接口112发送输入数据,如果要求客户设备140自动发送输入数据需要获得用户的授权,则用户可以在客户设备140中设置相应权限。用户可以在客户设备140查看执行设备110输出的结果,具体的呈现形式可以是显示、声音、动作等具体方式。客户设备140也可以作为数据采集端,采集如图所示输入I/O接口112的输入数据及输出I/O接口112的输出结果作为新的样本数据,并存入数据库130。当然,也可以不经过客户设备140进行采集,而是由I/O接口112直接将如图所示输入I/O接口112的输入数据及输出I/O接口112的输出结果,作为新的样本数据存入数据库130。In the case shown in FIG. 3 , the user can manually enter the input data, and the manual input can be operated through the interface provided by the I/O interface 112 . In another case, the client device 140 can automatically send input data to the I/O interface 112. If requiring the client device 140 to automatically send input data requires the user's authorization, the user can set corresponding permissions in the client device 140. The user can view the results output by the execution device 110 on the client device 140, and the specific presentation form may be display, sound, action, etc. The client device 140 can also be used as a data collection terminal to collect input data from the input I/O interface 112 and output results from the output I/O interface 112 as new sample data, and store them in the database 130 . Of course, it is also possible to collect without going through the client device 140. Instead, the I/O interface 112 directly uses the input data input to the I/O interface 112 and the output result of the output I/O interface 112 as a new sample as shown in the figure. The data is stored in database 130.
值得注意的是,图3仅是本申请实施例提供的一种系统架构的示意图,图中所示设备、器件、模块等之间的位置关系不构成任何限制,例如,在图3中,数据存储系统150相对执行设备110是外部存储器,在其它情况下,也可以将数据存储系统150置于执行设备110中。如图3所示,可以根据训练设备120训练得到神经网络。It is worth noting that Figure 3 is only a schematic diagram of a system architecture provided by an embodiment of the present application. The positional relationship between the devices, devices, modules, etc. shown in the figure does not constitute any limitation. For example, in Figure 3, the data The storage system 150 is an external memory relative to the execution device 110. In other cases, the data storage system 150 can also be placed in the execution device 110. As shown in Figure 3, the neural network can be trained according to the training device 120.
本申请实施例还提供的一种芯片,该芯片包括神经网络处理器NPU。该芯片可以被设置在如图3所示的执行设备110中,用以完成计算模块111的计算工作。该芯片也可以被设置在如图3所示的训练设备120中,用以完成训练设备120的训练工作并输出目标模型/规则。An embodiment of the present application also provides a chip, which includes a neural network processor NPU. The chip can be disposed in the execution device 110 as shown in FIG. 3 to complete the calculation work of the calculation module 111. The chip can also be installed in the training device 120 as shown in Figure 3 to complete the training work of the training device 120 and output the target model/rules.
神经网络处理器NPU,NPU作为协处理器挂载到主中央处理器(centralprocessing unit,CPU)(host CPU)上,由主CPU分配任务。NPU的核心部分为运算电路,控制器控制运算电路提取存储器(权重存储器或输入存储器)中的数据并进行运算。Neural network processor NPU, NPU is mounted on the main central processing unit (CPU) (host CPU) as a co-processor, and the main CPU allocates tasks. The core part of the NPU is the arithmetic circuit. The controller controls the arithmetic circuit to extract the data in the memory (weight memory or input memory) and perform operations.
在一些实现中,运算电路内部包括多个处理单元(process engine,PE)。在一些实现中,运算电路是二维脉动阵列。运算电路还可以是一维脉动阵列或者能够执行例如乘法和加法这样的数学运算的其它电子线路。在一些实现中,运算电路是通用的矩阵处理器。In some implementations, the computing circuit includes multiple processing units (PE). In some implementations, the arithmetic circuit is a two-dimensional systolic array. The arithmetic circuit may also be a one-dimensional systolic array or other electronic circuit capable of performing mathematical operations such as multiplication and addition. In some implementations, the arithmetic circuit is a general-purpose matrix processor.
举例来说,假设有输入矩阵A,权重矩阵B,输出矩阵C。运算电路从权重存储器中取矩阵B相应的数据,并缓存在运算电路中每一个PE上。运算电路从输入存储器中取矩阵A数据与矩阵B进行矩阵运算,得到的矩阵的部分结果或最终结果,保存在累加器(accumulator)中。For example, assume there is an input matrix A, a weight matrix B, and an output matrix C. The arithmetic circuit fetches the corresponding data of matrix B from the weight memory and caches it on each PE in the arithmetic circuit. The operation circuit takes matrix A data and matrix B from the input memory to perform matrix operations, and the partial result or final result of the obtained matrix is stored in the accumulator (accumulator).
向量计算单元可以对运算电路的输出做进一步处理,如向量乘,向量加,指数运算,对数运算,大小比较等等。例如,向量计算单元可以用于神经网络中非卷积/非FC层的网络计算,如池化(pooling),批归一化(batch normalization),局部响应归一化(localresponse normalization)等。The vector calculation unit can further process the output of the arithmetic circuit, such as vector multiplication, vector addition, exponential operation, logarithmic operation, size comparison, etc. For example, the vector computing unit can be used for network calculations in non-convolutional/non-FC layers in neural networks, such as pooling, batch normalization, local response normalization, etc.
在一些实现种,向量计算单元能将经处理的输出的向量存储到统一缓存器。例如,向量计算单元可以将非线性函数应用到运算电路的输出,例如累加值的向量,用以生成激活值。在一些实现中,向量计算单元生成归一化的值、合并值,或二者均有。在一些实现中,处理过的输出的向量能够用作到运算电路的激活输入,例如用于在神经网络中的后续层中的使用。In some implementations, the vector computation unit can store the processed output vector into a unified buffer. For example, the vector calculation unit may apply a nonlinear function to the output of the arithmetic circuit, such as a vector of accumulated values, to generate activation values. In some implementations, the vector computation unit generates normalized values, merged values, or both. In some implementations, the processed output vector can be used as an activation input to an arithmetic circuit, such as for use in a subsequent layer in a neural network.
统一存储器用于存放输入数据以及输出数据。Unified memory is used to store input data and output data.
权重数据直接通过存储单元访问控制器(direct memory access controller,DMAC)将外部存储器中的输入数据搬运到输入存储器和/或统一存储器、将外部存储器中的权重数据存入权重存储器,以及将统一存储器中的数据存入外部存储器。The weight data directly transfers the input data in the external memory to the input memory and/or the unified memory through the storage unit access controller (direct memory access controller, DMAC), stores the weight data in the external memory into the weight memory, and transfers the weight data to the unified memory. The data in is stored in external memory.
总线接口单元(bus interface unit,BIU),用于通过总线实现主CPU、DMAC和取指存储器之间进行交互。The bus interface unit (BIU) is used to realize the interaction between the main CPU, DMAC and instruction memory through the bus.
与控制器连接的取指存储器(instruction fetch buffer),用于存储控制器使用的指令;The instruction fetch buffer connected to the controller is used to store instructions used by the controller;
控制器,用于调用指存储器中缓存的指令,实现控制该运算加速器的工作过程。The controller is used to call instructions cached in the memory to control the working process of the computing accelerator.
一般地,统一存储器,输入存储器,权重存储器以及取指存储器均为片上(On-Chip)存储器,外部存储器为该NPU外部的存储器,该外部存储器可以为双倍数据率同步动态随机存储器(double data rate synchronous dynamic random access memory,DDRSDRAM)、高带宽存储器(high bandwidth memory,HBM)或其他可读可写的存储器。Generally, the unified memory, input memory, weight memory and instruction memory are all on-chip memories, and the external memory is a memory outside the NPU. The external memory can be a double data rate synchronous dynamic random access memory (double data rate). rate synchronous dynamic random access memory (DDRSDRAM), high bandwidth memory (high bandwidth memory, HBM) or other readable and writable memory.
由于本申请实施例涉及大量神经网络的应用,为了便于理解,下面先对本申请实施例涉及的相关术语及神经网络等相关概念进行介绍。Since the embodiments of the present application involve the application of a large number of neural networks, in order to facilitate understanding, the relevant terms involved in the embodiments of the present application and related concepts such as neural networks are first introduced below.
(1)神经网络(1)Neural network
神经网络可以是由神经单元组成的,神经单元可以是指以xs和截距1为输入的运算单元,该运算单元的输出可以为:The neural network can be composed of neural units. The neural unit can refer to an arithmetic unit that takes xs and intercept 1 as input. The output of the arithmetic unit can be:
其中,s=1、2、……n,n为大于1的自然数,Ws为xs的权重,b为神经单元的偏置。f为神经单元的激活函数(activation functions),用于将非线性特性引入神经网络中,来将神经单元中的输入信号转换为输出信号。该激活函数的输出信号可以作为下一层卷积层的输入。激活函数可以是sigmoid函数。神经网络是将许多个上述单一的神经单元联结在一起形成的网络,即一个神经单元的输出可以是另一个神经单元的输入。每个神经单元的输入可以与前一层的局部接受域相连,来提取局部接受域的特征,局部接受域可以是由若干个神经单元组成的区域。Among them, s=1, 2,...n, n is a natural number greater than 1, Ws is the weight of xs, and b is the bias of the neural unit. f is the activation function of the neural unit, which is used to introduce nonlinear characteristics into the neural network to convert the input signal in the neural unit into an output signal. The output signal of this activation function can be used as the input of the next convolutional layer. The activation function can be a sigmoid function. A neural network is a network formed by connecting many of the above-mentioned single neural units together, that is, the output of one neural unit can be the input of another neural unit. The input of each neural unit can be connected to the local receptive field of the previous layer to extract the features of the local receptive field. The local receptive field can be an area composed of several neural units.
神经网络中的每一层的工作可以用数学表达式y=a(Wx+b)来描述:从物理层面神经网络中的每一层的工作可以理解为通过五种对输入空间(输入向量的集合)的操作,完成输入空间到输出空间的变换(即矩阵的行空间到列空间),这五种操作包括:1、升维/降维;2、放大/缩小;3、旋转;4、平移;5、“弯曲”。其中1、2、3的操作由Wx完成,4的操作由+b完成,5的操作则由a()来实现。这里之所以用“空间”二字来表述是因为被分类的对象并不是单个事物,而是一类事物,空间是指这类事物所有个体的集合。其中,W是权重向量,该向量中的每一个值表示该层神经网络中的一个神经元的权重值。该向量W决定着上文所述的输入空间到输出空间的空间变换,即每一层的权重W控制着如何变换空间。训练神经网络的目的,也就是最终得到训练好的神经网络的所有层的权重矩阵(由很多层的向量W形成的权重矩阵)。因此,神经网络的训练过程本质上就是学习控制空间变换的方式,更具体的就是学习权重矩阵。The work of each layer in the neural network can be described by the mathematical expression y=a(Wx+b): From the physical level, the work of each layer in the neural network can be understood as five pairs of input spaces (input vectors) Set) operations to complete the transformation from input space to output space (i.e., row space to column space of matrix). These five operations include: 1. Dimension raising/reducing; 2. Enlarging/reducing; 3. Rotation; 4. Translation; 5. "Bend". Among them, the operations of 1, 2, and 3 are completed by Wx, the operation of 4 is completed by +b, and the operation of 5 is implemented by a(). The reason why the word "space" is used here is because the object to be classified is not a single thing, but a class of things. Space refers to the collection of all individuals of this type of thing. Among them, W is a weight vector, and each value in the vector represents the weight value of a neuron in the neural network of this layer. This vector W determines the spatial transformation from the input space to the output space described above, that is, the weight W of each layer controls how to transform the space. The purpose of training a neural network is to finally obtain the weight matrix of all layers of the trained neural network (a weight matrix formed by the vector W of many layers). Therefore, the training process of neural network is essentially to learn how to control spatial transformation, and more specifically, to learn the weight matrix.
因为希望神经网络的输出尽可能的接近真正想要预测的值,所以可以通过比较当前网络的预测值和真正想要的目标值,再根据两者之间的差异情况来更新每一层神经网络的权重向量(当然,在第一次更新之前通常会有初始化的过程,即为神经网络中的各层预先配置参数),比如,如果网络的预测值高了,就调整权重向量让它预测低一些,不断的调整,直到神经网络能够预测出真正想要的目标值。因此,就需要预先定义“如何比较预测值和目标值之间的差异”,这便是损失函数(loss function)或目标函数(objective function),它们是用于衡量预测值和目标值的差异的重要方程。其中,以损失函数举例,损失函数的输出值(loss)越高表示差异越大,那么神经网络的训练就变成了尽可能缩小这个loss的过程。Because you want the output of the neural network to be as close as possible to the value you really want to predict, you can compare the predicted value of the current network with the really desired target value, and then update each layer of the neural network based on the difference between the two. weight vector (of course, there is usually an initialization process before the first update, that is, pre-configuring parameters for each layer in the neural network). For example, if the predicted value of the network is high, adjust the weight vector to make it predict lower Some, constant adjustments are made until the neural network can predict the truly desired target value. Therefore, it is necessary to define in advance "how to compare the difference between the predicted value and the target value". This is the loss function (loss function) or objective function (objective function), which is used to measure the difference between the predicted value and the target value. Important equations. Among them, taking the loss function as an example, the higher the output value (loss) of the loss function, the greater the difference. Then the training of the neural network becomes a process of reducing this loss as much as possible.
(2)反向传播算法(2)Back propagation algorithm
神经网络可以采用误差反向传播(back propagation,BP)算法在训练过程中修正初始的神经网络模型中参数的大小,使得神经网络模型的重建误差损失越来越小。具体地,前向传递输入信号直至输出会产生误差损失,通过反向传播误差损失信息来更新初始的神经网络模型中参数,从而使误差损失收敛。反向传播算法是以误差损失为主导的反向传播运动,旨在得到最优的神经网络模型的参数,例如权重矩阵。The neural network can use the error back propagation (BP) algorithm to modify the size of the parameters in the initial neural network model during the training process, so that the reconstruction error loss of the neural network model becomes smaller and smaller. Specifically, forward propagation of the input signal until the output will produce an error loss, and the parameters in the initial neural network model are updated by backpropagating the error loss information, so that the error loss converges. The backpropagation algorithm is a backpropagation movement dominated by error loss, aiming to obtain the optimal parameters of the neural network model, such as the weight matrix.
下面从神经网络的训练侧和神经网络的应用侧对本申请提供的方法进行描述。The method provided by this application is described below from the training side of the neural network and the application side of the neural network.
本申请实施例提供的模型训练方法,涉及数据序列的处理,具体可以应用于数据训练、机器学习、深度学习等方法,对训练数据(例如,本申请实施例的模型训练方法中的目标图像)进行符号化和形式化的智能信息建模、抽取、预处理、训练等,最终得到训练好的神经网络(如本申请中的目标模型);并且,本申请实施例提供的文本获取方法可以运用上述训练好的神经网络,将输入数据(例如,本申请实施例的文本获取方法中的目标图像)输入到所述训练好的神经网络中,得到输出数据(例如,本申请实施例的文本获取方法中的目标文本以及目标文本在目标图像中的位置信息)。需要说明的是,本申请实施例提供的模型训练方法和文本获取方法是基于同一个构思产生的发明,也可以理解为一个系统中的两个部分,或一个整体流程的两个阶段:如模型训练阶段和模型应用阶段。The model training method provided by the embodiment of the present application involves the processing of data sequences, and can be specifically applied to data training, machine learning, deep learning and other methods to train the training data (for example, the target image in the model training method of the embodiment of the present application). Carry out symbolic and formalized intelligent information modeling, extraction, preprocessing, training, etc., and finally obtain a trained neural network (such as the target model in this application); and, the text acquisition method provided by the embodiment of this application can be used The above-trained neural network inputs input data (for example, the target image in the text acquisition method of the embodiment of the present application) into the trained neural network to obtain output data (for example, the text acquisition method of the embodiment of the present application). The target text in the method and the position information of the target text in the target image). It should be noted that the model training method and text acquisition method provided in the embodiments of this application are inventions based on the same concept, and can also be understood as two parts in a system, or two stages of an overall process: such as model training phase and model application phase.
本申请实施例提供的文本获取方法可通过目标模型(也可以称为预训练的文本(文档)模型)实现,下文先对目标模型的结构进行简单的介绍。图4为本申请实施例提供的目标模型的一个结构示意图,如图4所示,目标模型的输入端可用于接收来自外部的目标图像以及来自自身的目标文本在目标图像中的位置信息,目标模型的输出端可对外输出目标文本以及目标文本在目标图像中的位置信息。为了了解图4所示的目标模型的工作流程,下文结合图5对该工作流程进行介绍,图5为本申请实施例提供的文本获取方法的一个流程示意图,如图5所示,该方法包括:The text acquisition method provided by the embodiments of this application can be implemented through a target model (which can also be called a pre-trained text (document) model). The structure of the target model is briefly introduced below. Figure 4 is a schematic structural diagram of the target model provided by the embodiment of the present application. As shown in Figure 4, the input end of the target model can be used to receive the target image from the outside and the position information of the target text in the target image from itself. The target The output end of the model can output the target text and the position information of the target text in the target image. In order to understand the workflow of the target model shown in Figure 4, the workflow is introduced below in conjunction with Figure 5. Figure 5 is a schematic flow chart of the text acquisition method provided by the embodiment of the present application. As shown in Figure 5, the method includes :
501、获取目标图像,目标图像包含多个文本。501. Obtain the target image. The target image contains multiple texts.
本实施例中,当需要从包含目标图像中获取目标文本时,可先获取目标图像。需要说明的是,目标图像所呈现的内容包含多个文本,例如,当目标图像为收入申报单的图像时,该图像包含“申报人名称:张XX”、“申报时间:20XX年10月02日”、“收入金额:200XXX元”、“申报人的性别:男”以及“申报人的联系方式:130XXXXXXXX”等多个文本,又如,当目标图像为糖尿病统计报表的图像时,该图像包含“糖尿病的介绍:糖尿病是常见的一种疾病...”、“糖尿病的患病率:0.X”、“不同性别的患病率:男为4.X%且女为3.X%”、“糖尿病所造成的年经济损失:6X亿元”以及“糖尿病的可预防概率:6X%”等多个文本。In this embodiment, when it is necessary to obtain the target text from the target image, the target image can be obtained first. It should be noted that the content presented by the target image contains multiple texts. For example, when the target image is an image of an income declaration form, the image contains "Name of declarer: Zhang XX", "Declaration time: October 2, 20XX" "Day", "Amount of income: 200 Includes "Introduction to diabetes: Diabetes is a common disease...", "Prevalence of diabetes: 0.X", "Prevalence of different genders: 4.X% for men and 3.X for women %", "Annual economic losses caused by diabetes: 6X billion yuan" and "Probability of preventable diabetes: 6X%" and other texts.
可以理解的是,所需获取的目标文本的数量可以为一个或多个,也就是说,需要获取目标图像所包含的多个文本中的一个文本或多个文本。依旧如上述例子,比如,当目标图像为收入申报单的图像时,所需获取的目标文本为“申报人名称:张XX”以及“申报时间:20XX年10月02日”这两个文本。又如,当目标图像为糖尿病统计报表的图像时,所需获取的目标文本为“糖尿病的可预防概率:6X%”这一个文本。It can be understood that the number of target texts that need to be obtained may be one or more, that is, one or more texts among the multiple texts included in the target image need to be obtained. Still the same as the above example, for example, when the target image is an image of an income declaration form, the target text that needs to be obtained is the two texts "Name of declarer: Zhang XX" and "Declaration time: October 2, 20XX". For another example, when the target image is an image of a diabetes statistical report, the target text to be obtained is the text "Preventable probability of diabetes: 6X%".
502、对目标图像进行编码,得到目标图像的特征。502. Encode the target image to obtain the characteristics of the target image.
得到目标图像后,可将目标图像输入至目标模型,目标模型可先对目标图像进行编码,从而得到目标图像的特征。After obtaining the target image, the target image can be input to the target model, and the target model can first encode the target image to obtain the characteristics of the target image.
具体地,如图4所示,目标模型可包含编码器以及解码器。那么,目标模型可通过以下方式获取目标图像的特征:Specifically, as shown in Figure 4, the target model may include an encoder and a decoder. Then, the target model can obtain the characteristics of the target image in the following ways:
在将目标图像输入至目标模型后,目标模型的编码器可对目标图像进行编码,从而得到目标图像的特征,并将目标图像的特征发送至目标模型的解码器。After the target image is input to the target model, the encoder of the target model can encode the target image to obtain features of the target image, and send the features of the target image to the decoder of the target model.
例如,如图6所示(图6为本申请实施例提供的目标模型的另一结构示意图),设某个图像所呈现的内容包含文本1、文本2、文本3、...、文本n(n为大于或等于2的正整数),且目标模型包含编码器(encoder)以及解码器(decoder)。当需要获取该图像中的文本1、文本2、...文本m时(m小于或等于n,且m为大于或等于1的正整数),可将包含该图像输入至目标模型中。那么,目标模型的编码器在接收到该图像后,可对该图像进行编码,以得到该图像的视觉特征。其中,编码的过程如以下公式所示:For example, as shown in Figure 6 (Figure 6 is another structural schematic diagram of the target model provided by the embodiment of the present application), assume that the content presented by a certain image includes text 1, text 2, text 3,..., text n (n is a positive integer greater than or equal to 2), and the target model includes an encoder and a decoder. When you need to obtain text 1, text 2, ... text m in the image (m is less than or equal to n, and m is a positive integer greater than or equal to 1), you can input the image into the target model. Then, after receiving the image, the encoder of the target model can encode the image to obtain the visual features of the image. Among them, the encoding process is shown in the following formula:
H=Encoder(image) (2)H=Encoder(image) (2)
上式中,image为该图像,H为该图像的视觉特征。那么,编码器得到该图像的视觉特征后,可将该图像的视觉特征提供给解码器。In the above formula, image is the image, and H is the visual feature of the image. Then, after the encoder obtains the visual features of the image, it can provide the visual features of the image to the decoder.
503、基于特征,获取目标文本在目标图像中的位置信息,多个文本包含目标文本。503. Based on the features, obtain the position information of the target text in the target image. Multiple texts contain the target text.
得到目标图像的特征后,目标模型可对目标图像的特征进行处理,从而得到目标文本在目标图像中的位置信息,并对外输出目标文本在目标图像中的位置信息,也就是说,目标文本在目标图像中的位置信息为目标模型的其中一个输出。After obtaining the characteristics of the target image, the target model can process the characteristics of the target image to obtain the position information of the target text in the target image, and output the position information of the target text in the target image. In other words, the target text is in the target image. The position information in the target image is one of the outputs of the target model.
具体地,目标模型可通过以下多种方式获取目标文本在目标图像中的位置信息:Specifically, the target model can obtain the position information of the target text in the target image through the following methods:
(1)若目标文本的数量为一个,在得到目标图像的特征后,解码器可先基于目标图像的特征,对预置的向量表示(也可以称为序列的起始向量表示,该向量表示的内容通常无意义)进行解码,从而得到目标文本在目标图像中的位置信息的第1个向量表示(token)。接着,解码器可基于目标图像的特征,对目标文本在目标图像中的位置信息的第1个向量表示进行解码,从而得到目标文本在目标图像中的位置信息的第2个向量表示。随后,解码器可基于目标图像的特征,对目标文本在目标图像中的位置信息的第1个向量表示以及目标文本在目标图像中的位置信息的第2个向量表示进行解码,从而得到目标文本在目标图像中的位置信息的第3个向量表示,...,最后,解码器可基于目标图像的特征,对目标文本在目标图像中的位置信息的第1个向量表示至目标文本在目标图像中的位置信息的第X-1个向量表示进行解码,从而得到目标文本在目标图像中的位置信息的第X个向量表示(X为大于或等于1的正整数)。如此一来,解码器可以得到以向量表示形式呈现的目标文本在目标图像中的位置信息。(1) If the number of target texts is one, after obtaining the characteristics of the target image, the decoder can first represent the preset vector (which can also be called the starting vector representation of the sequence) based on the characteristics of the target image. This vector represents (The content is usually meaningless) is decoded to obtain the first vector representation (token) of the position information of the target text in the target image. Then, the decoder can decode the first vector representation of the position information of the target text in the target image based on the characteristics of the target image, thereby obtaining the second vector representation of the position information of the target text in the target image. Subsequently, the decoder can decode the first vector representation of the position information of the target text in the target image and the second vector representation of the position information of the target text in the target image based on the characteristics of the target image, thereby obtaining the target text. The third vector representation of the position information in the target image,... Finally, the decoder can, based on the characteristics of the target image, represent the first vector representation of the position information of the target text in the target image to the position of the target text in the target image. The X-1th vector representation of the position information in the image is decoded, thereby obtaining the X-th vector representation of the position information of the target text in the target image (X is a positive integer greater than or equal to 1). In this way, the decoder can obtain the position information of the target text in the target image in the form of vector representation.
依旧如上述例子,设仅需从该图像中获取文本1。那么,在得到该图像的视觉特征后,解码器可基于该图像的视觉特征,对序列的起始向量表示(beginning of sequence,BOS)进行解码,从而得到文本1(在该图像中)的位置信息1的向量表示1,也就相当于得到了以向量表示形式呈现的位置信息1。Still as in the above example, assume that we only need to obtain text 1 from the image. Then, after obtaining the visual features of the image, the decoder can decode the beginning vector representation (BOS) of the sequence based on the visual features of the image, thereby obtaining the position of text 1 (in the image) The vector representation of information 1 is 1, which is equivalent to obtaining the position information 1 presented in the form of a vector representation.
(2)若目标文本的数量为两个,可将这两个目标文本分别称为第一文本以及第二文本。在得到目标图像的特征后,解码器可先基于目标图像的特征,对预置的向量表示进行解码,从而得到第一文本在目标图像中的第一位置信息的第1个向量表示。接着,解码器可基于目标图像的特征,对第一位置信息的第1个向量表示进行解码,从而得到第一位置信息的第2个向量表示。随后,解码器可基于目标图像的特征,对第一位置信息的第1个向量表示以及第一位置信息的第2个向量表示进行解码,从而得到第一位置信息的第3个向量表示,...,最后,解码器可基于目标图像的特征,对第一位置信息的第1个向量表示至第一位置信息的第X-1个向量表示进行解码,从而得到第一位置信息的第X个向量表示。如此一来,解码器可得到完整的以向量表示形式呈现的第一位置信息。(2) If the number of target texts is two, the two target texts can be called the first text and the second text respectively. After obtaining the characteristics of the target image, the decoder may first decode the preset vector representation based on the characteristics of the target image, thereby obtaining the first vector representation of the first position information of the first text in the target image. Then, the decoder may decode the first vector representation of the first position information based on the characteristics of the target image, thereby obtaining the second vector representation of the first position information. Subsequently, the decoder can decode the first vector representation of the first position information and the second vector representation of the first position information based on the characteristics of the target image, thereby obtaining the third vector representation of the first position information. .., finally, the decoder can decode the 1st vector representation of the first position information to the X-1th vector representation of the first position information based on the characteristics of the target image, thereby obtaining the X-th vector representation of the first position information. vector representation. In this way, the decoder can obtain the complete first position information in the form of vector representation.
得到第一位置信息后,解码器可基于目标图像的特征,对第一位置信息进行处理,从而得到第一文本,该过程先不展开。After obtaining the first position information, the decoder can process the first position information based on the characteristics of the target image to obtain the first text. This process will not be carried out yet.
得到第一文本后,解码器可先基于目标图像的特征,对第一位置信息以及第一文本进行解码,从而得到第二文本在目标图像中的第二位置信息的第1个向量表示。接着,解码器可基于目标图像的特征,对第一位置信息、第一文本以及第二位置信息的第1个向量表示进行解码,从而得到第二位置信息的第2个向量表示。随后,解码器可基于目标图像的特征,对第一位置信息、第一文本、第二位置信息的第1个向量表示以及第二位置信息的第2个向量表示进行解码,从而得到第二位置信息的第3个向量表示,...,最后,解码器可基于目标图像的特征,对第一位置信息、第一文本、第二位置信息的第1个向量表示至第二位置信息的第Z-1个向量表示进行解码,从而得到第二位置信息的第Z个向量表示(Z为大于或等于1的正整数)。如此一来,解码器可以得到以向量表示形式呈现的第二位置信息。After obtaining the first text, the decoder can first decode the first position information and the first text based on the characteristics of the target image, thereby obtaining the first vector representation of the second position information of the second text in the target image. Then, the decoder may decode the first vector representation of the first location information, the first text, and the second location information based on the characteristics of the target image, thereby obtaining a second vector representation of the second location information. Subsequently, the decoder may decode the first position information, the first text, the first vector representation of the second position information and the second vector representation of the second position information based on the characteristics of the target image, thereby obtaining the second position The third vector representation of the information,... Finally, the decoder can, based on the characteristics of the target image, represent the first vector representation of the first location information, the first text, and the second location information to the third vector representation of the second location information. Z-1 vector representations are decoded, thereby obtaining the Z-th vector representation of the second position information (Z is a positive integer greater than or equal to 1). In this way, the decoder can obtain the second position information in the form of a vector representation.
依旧如上述例子,设仅需从该图像中获取文本1和文本2。那么,在得到该图像的视觉特征后,解码器可基于该图像的视觉特征,对序列的起始向量表示进行解码,从而得到文本1(在该图像中)的位置信息1的向量表示1,也就相当于得到了以向量表示形式呈现的位置信息1。Still as in the above example, assume that we only need to obtain text 1 and text 2 from the image. Then, after obtaining the visual features of the image, the decoder can decode the starting vector representation of the sequence based on the visual features of the image, thereby obtaining the vector representation 1 of the position information 1 of text 1 (in the image), It is equivalent to obtaining the position information 1 presented in the form of vector representation.
接着,解码器还可基于该图像的视觉特征,对位置信息1进行处理,从而得到文本1,此处先不展开。Then, the decoder can also process the position information 1 based on the visual characteristics of the image to obtain the text 1, which will not be expanded here.
然后,解码器还可基于该图像的视觉特征,对位置信息1的向量表示1、文本1的向量表示2、文本1的向量表示3以及文本1的向量表示4进行解码,从而得到文本2(在该图像中)的位置信息2的向量表示5,也就相当于得到了以向量表示形式呈现的位置信息2。Then, the decoder can also decode vector representation 1 of position information 1, vector representation 2 of text 1, vector representation 3 of text 1, and vector representation 4 of text 1 based on the visual characteristics of the image, thereby obtaining text 2 ( In this image), the vector representation 5 of the position information 2 is equivalent to obtaining the position information 2 presented in the form of a vector representation.
(3)若目标文本的数量为三个或者更多,也就是存在第一文本、第二文本以及第三文本等等,在这种情况下,解码器获取第一文本在目标图像中的第一位置信息、第二文本在目标图像中的第二位置信息以及第三文本在目标图像中的第三位置信息等等的过程,与上述(2)所描述的过程是类似的,此处不做赘述。(3) If the number of target texts is three or more, that is, there are first text, second text, third text, etc., in this case, the decoder obtains the first text in the target image. The process of obtaining the first position information, the second position information of the second text in the target image, the third position information of the third text in the target image, etc. is similar to the process described in (2) above, and will not be used here. To elaborate.
504、基于特征以及位置信息,获取目标文本。504. Obtain the target text based on features and location information.
得到目标文本在目标图像中的位置信息后,解码器可对目标图像的特征以及目标文本在目标图像中的位置信息做进一步的处理,从而得到目标文本,并对外输出目标文本,也就是说,目标文本为目标模型的另一个输出。After obtaining the position information of the target text in the target image, the decoder can further process the characteristics of the target image and the position information of the target text in the target image, thereby obtaining the target text and outputting the target text, that is, The target text is another output of the target model.
具体地,目标模型可通过以下多种方式来获取目标文本:Specifically, the target model can obtain the target text through the following methods:
(1)若目标文本的数量为一个,在得到目标文本在目标图像中的位置信息后,解码器可先基于目标图像的特征,对目标文本在目标图像中的位置信息进行解码,从而得到目标文本的第1个向量表示。接着,解码器可基于目标图像的特征,对目标文本在目标图像中的位置信息以及目标文本的第1个向量表示进行解码,从而得到目标文本的第2个向量表示。随后,解码器可基于目标图像的特征,对目标文本在目标图像中的位置信息,目标文本的第1个向量表示至目标文本的第2个向量表示进行解码,从而得到目标文本的第3个向量表示,...,最后,解码器可基于目标图像的特征,对目标文本在目标图像中的位置信息,目标文本的第1个向量表示至目标文本的第Y-1个向量表示进行解码,从而得到目标文本的第Y个向量表示(Y为大于或等于1的正整数)。如此一来,解码器可以得到以向量表示形式呈现的目标文本。(1) If the number of target texts is one, after obtaining the position information of the target text in the target image, the decoder can first decode the position information of the target text in the target image based on the characteristics of the target image, thereby obtaining the target The first vector representation of text. Then, the decoder can decode the position information of the target text in the target image and the first vector representation of the target text based on the characteristics of the target image, thereby obtaining the second vector representation of the target text. Then, based on the characteristics of the target image, the decoder can decode the position information of the target text in the target image, the first vector representation of the target text to the second vector representation of the target text, thereby obtaining the third vector representation of the target text. Vector representation,..., finally, the decoder can decode the position information of the target text in the target image based on the characteristics of the target image, from the 1st vector representation of the target text to the Y-1th vector representation of the target text. , thereby obtaining the Y-th vector representation of the target text (Y is a positive integer greater than or equal to 1). In this way, the decoder can obtain the target text in the form of a vector representation.
依旧如上述例子,设仅需从该图像中获取文本1。在得到文本1的位置信息1后,解码器可基于该图像的视觉特征,对位置信息1进行解码,从而文本1的向量表示2。接着,解码器还可基于该图像的视觉特征,对位置信息1以及文本1的向量表示2进行解码,从而文本1的向量表示3。然后,解码器还可基于该图像的视觉特征,对位置信息1、文本1的向量表示2以及文本1的向量表示3进行解码,从而文本1的向量表示4。至此,也就相当于得到了以向量表示形式呈现的文本1。Still as in the above example, assume that we only need to obtain text 1 from the image. After obtaining the position information 1 of text 1, the decoder can decode the position information 1 based on the visual characteristics of the image, so that the vector of text 1 represents 2. Then, the decoder can also decode the position information 1 and the vector representation 2 of the text 1 based on the visual characteristics of the image, so that the vector representation 3 of the text 1 is obtained. The decoder may then also decode the position information 1 , the vector representation 2 of text 1 , and the vector representation 3 of text 1 based on the visual features of the image, resulting in a vector representation 4 of text 1 . At this point, it is equivalent to obtaining text 1 presented in vector representation.
(2)若目标文本的数量为两个,可将这两个目标文本分别称为第一文本以及第二文本。在得到第一文本在目标图像中的第一位置信息后,解码器可先基于目标图像的特征,对第一位置信息进行解码,从而得到第一文本的第1个向量表示。接着,解码器可基于目标图像的特征,对第一位置信息以及第一文本的第1个向量表示进行解码,从而得到第一文本的第2个向量表示。随后,解码器可基于目标图像的特征,对第一位置信息,第一文本的第1个向量表示至第一文本的第2个向量表示进行解码,从而得到第一文本的第3个向量表示,...,最后,解码器可基于目标图像的特征,对第一位置信息,第一文本的第1个向量表示至第一文本的第Y-1个向量表示进行解码,从而得到第一文本的第Y个向量表示。如此一来,解码器可以得到以向量表示形式呈现的第一文本。(2) If the number of target texts is two, the two target texts can be called the first text and the second text respectively. After obtaining the first position information of the first text in the target image, the decoder may first decode the first position information based on the characteristics of the target image, thereby obtaining the first vector representation of the first text. Then, the decoder may decode the first position information and the first vector representation of the first text based on the characteristics of the target image, thereby obtaining the second vector representation of the first text. Subsequently, the decoder can decode the first position information, the first vector representation of the first text to the second vector representation of the first text based on the characteristics of the target image, thereby obtaining the third vector representation of the first text. ,..., finally, the decoder can decode the first position information, the first vector representation of the first text to the Y-1th vector representation of the first text based on the characteristics of the target image, thereby obtaining the first The Yth vector representation of text. In this way, the decoder can get the first text in the form of a vector representation.
得到第一文本后,解码器可基于目标图像的特征,对第一位置信息以及第一文本进行处理,从而得到第二文本在目标图像中的第二位置信息,该过程可参考前述相关说明部分,此处不再赘述。After obtaining the first text, the decoder can process the first position information and the first text based on the characteristics of the target image, thereby obtaining the second position information of the second text in the target image. For this process, please refer to the relevant description section above. , which will not be described again here.
得到第二文本在目标图像中的第二位置信息后,解码器可先基于目标图像的特征,对第一位置信息、第一文本以及第二位置信息进行解码,从而得到第二文本的第1个向量表示。接着,解码器可基于目标图像的特征,对第一位置信息、第一文本、第二位置信息以及第二文本的第1个向量表示进行解码,从而得到第二文本的第2个向量表示。随后,解码器可基于目标图像的特征,对第一位置信息、第一文本、第二位置信息、第二文本的第1个向量表示以及第二文本的第2个向量表示进行解码,从而得到第二文本的第3个向量表示,...,最后,解码器可基于目标图像的特征,对第一位置信息、第一文本、第二位置信息、第二文本的第1个向量表示至第二文本的第U-1个向量表示进行解码,从而得到第二文本的第U个向量表示(U为大于或等于1的正整数)。如此一来,解码器可以得到以向量表示形式呈现的第二文本。After obtaining the second position information of the second text in the target image, the decoder can first decode the first position information, the first text and the second position information based on the characteristics of the target image, thereby obtaining the first position information of the second text. vector representation. Then, the decoder may decode the first position information, the first text, the second position information, and the first vector representation of the second text based on the characteristics of the target image, thereby obtaining the second vector representation of the second text. Subsequently, the decoder may decode the first position information, the first text, the second position information, the first vector representation of the second text, and the second vector representation of the second text based on the characteristics of the target image, thereby obtaining The third vector representation of the second text,... Finally, the decoder can, based on the characteristics of the target image, represent the first position information, the first text, the second position information, and the first vector representation of the second text to The U-1th vector representation of the second text is decoded, thereby obtaining the U-th vector representation of the second text (U is a positive integer greater than or equal to 1). In this way, the decoder can obtain the second text in the form of a vector representation.
依旧如上述例子,设仅需从该图像中获取文本1。在得到文本1的位置信息1后,解码器可基于该图像的视觉特征,对位置信息1进行解码,从而文本1的向量表示2。接着,解码器还可基于该图像的视觉特征,对位置信息1以及文本1的向量表示2进行解码,从而文本1的向量表示3。然后,解码器还可基于该图像的视觉特征,对位置信息1、文本1的向量表示2以及文本1的向量表示3进行解码,从而文本1的向量表示4。至此,也就相当于得到了以向量表示形式呈现的文本1。Still as in the above example, assume that we only need to obtain text 1 from the image. After obtaining the position information 1 of text 1, the decoder can decode the position information 1 based on the visual characteristics of the image, so that the vector of text 1 represents 2. Then, the decoder can also decode the position information 1 and the vector representation 2 of the text 1 based on the visual characteristics of the image, so that the vector representation 3 of the text 1 is obtained. The decoder may then also decode the position information 1 , the vector representation 2 of text 1 , and the vector representation 3 of text 1 based on the visual features of the image, resulting in a vector representation 4 of text 1 . At this point, it is equivalent to obtaining text 1 presented in vector representation.
接着,解码器还可基于该图像的视觉特征,对位置信息1以及文本1进行处理,从而得到文本2的位置信息2,该过程可参考前述相关说明部分,此处不再赘述。Then, the decoder can also process the position information 1 and the text 1 based on the visual characteristics of the image, thereby obtaining the position information 2 of the text 2. For this process, please refer to the relevant description section above and will not be described again here.
然后,解码器还可基于该图像的视觉特征,对位置信息1的向量表示1、文本1的向量表示2、文本1的向量表示3、文本1的向量表示4以及位置信息2的向量表示5进行解码,从而文本2的向量表示6。接着,解码器还可基于该图像的视觉特征,对位置信息1的向量表示1、文本1的向量表示2、文本1的向量表示3、文本1的向量表示4、位置信息2的向量表示5以及文本2的向量表示6进行解码,从而文本2的向量表示7。至此,也就相当于得到了以向量表示形式呈现的文本2。The decoder can then also generate a vector representation 1 for position information 1, a vector representation 2 for text 1, a vector representation 3 for text 1, a vector representation 4 for text 1, and a vector representation 5 for position information 2 based on the visual characteristics of the image. Decode so that the vector representation of text 2 is 6. Then, the decoder can also, based on the visual characteristics of the image, perform vector representation 1 of position information 1, vector representation 2 of text 1, vector representation 3 of text 1, vector representation 4 of text 1, and vector representation 5 of position information 2. and the vector representation of text 2 6 is decoded so that the vector representation of text 2 is 7. At this point, it is equivalent to obtaining text 2 presented in vector representation.
(3)若目标文本的数量为三个或者更多,也就是存在第一文本、第二文本以及第三文本等等,在这种情况下,解码器获取第一文本、第二文本以及第三文本等等的过程,与上述(2)所描述的过程是类似的,此处不做赘述。(3) If the number of target texts is three or more, that is, there are first text, second text, third text, etc., in this case, the decoder obtains the first text, second text and third text. The process of three texts and so on is similar to the process described in (2) above, and will not be described again here.
更具体地,如图7所示(图7为本申请实施例提供的目标模型的另一结构示意图),目标模型在包含编码器以及解码器的基础上,还可包含转换器。需要说明的是,在图4所示的目标模型中,目标模型(的解码器)对外输出的是以向量表示形式呈现的目标文本以及目标文本在目标图像中的位置信息,而在图7所示的目标模型中,解码器可将以向量表示形式呈现的目标文本发送至转换器,转换器可对目标文本的所有向量表示进行转换,得到目标文本的所有字符,故转换器可对外输出以字符(文字)形式呈现的目标文本。同样地,解码器还可将以向量表示形式呈现的目标文本在目标图像中的位置信息,发送至转换模型,转换模型可对目标文本在目标图像中的位置信息的所有向量表示进行转换,得到目标文本在目标图像中所占据的区域的坐标,故转换器可对外输出以坐标形式呈现的目标文本在目标图像中的位置信息。More specifically, as shown in Figure 7 (Figure 7 is another structural schematic diagram of a target model provided by an embodiment of the present application), in addition to including an encoder and a decoder, the target model may also include a converter. It should be noted that in the target model shown in Figure 4, the target model (decoder) outputs the target text presented in the form of a vector representation and the position information of the target text in the target image, while in Figure 7 In the target model shown, the decoder can send the target text presented in the form of vector representation to the converter. The converter can convert all vector representations of the target text to obtain all the characters of the target text. Therefore, the converter can output externally as Target text presented in character (text) form. Similarly, the decoder can also send the position information of the target text in the target image presented in the form of vector representation to the conversion model, and the conversion model can convert all vector representations of the position information of the target text in the target image, obtaining The coordinates of the area occupied by the target text in the target image, so the converter can externally output the position information of the target text in the target image in the form of coordinates.
更具体地,在图7所示的目标模型中,转换器可以为以下至少一种:循环神经网络、多层感知机以及时间卷积网络。相应地,转换器对目标文本以及位置信息所执行的转换则可以为以下至少一种:基于循环神经网络的特征提取、基于多层感知机的特征提取以及基于时间卷积网络的特征提取。More specifically, in the target model shown in Figure 7, the converter may be at least one of the following: a recurrent neural network, a multi-layer perceptron, and a temporal convolutional network. Correspondingly, the conversion performed by the converter on the target text and location information may be at least one of the following: feature extraction based on recurrent neural networks, feature extraction based on multi-layer perceptrons, and feature extraction based on temporal convolutional networks.
更具体地,目标文本在图像图像中所占据的区域的坐标通常包含该区域的左上角的顶点坐标以及该区域的右下角的顶点坐标。需要说明的是,转换模块可通过以下公式来获取该区域的顶点坐标:More specifically, the coordinates of the area occupied by the target text in the image image usually include the vertex coordinates of the upper left corner of the area and the vertex coordinates of the lower right corner of the area. It should be noted that the conversion module can obtain the vertex coordinates of the area through the following formula:
上式中,转换模块可对目标文本在目标图像中的位置信息中的所有向量表示进行计算,从而得到该区域的左上角的顶点横坐标的特征再对/>进行计算,从而得到左上角的顶点横坐标Z1。接着,转换模块可/>以及Z1进行计算,从而得到该区域的左上角的顶点纵坐标的特征/>再对/>进行计算,从而得到左上角的顶点纵坐标Z2。以此类推,直至得到该区域的左上角的顶点横坐标Z1、左上角的顶点纵坐标Z2、右下角的顶点横坐标Z3以及右下角的顶点纵坐标Z4。In the above formula, the conversion module can calculate all vector representations in the position information of the target text in the target image, thereby obtaining the characteristics of the abscissa coordinate of the vertex in the upper left corner of the area. Right again/> Calculate to obtain the abscissa coordinate Z1 of the upper left corner vertex. Next, the conversion module can/> and Z1 are calculated to obtain the characteristics of the vertical coordinate of the vertex of the upper left corner of the area/> Right again/> Calculate to obtain the vertical coordinate Z2 of the vertex of the upper left corner. By analogy, the abscissa coordinate Z1 of the vertex of the upper left corner, the ordinate Z2 of the vertex of the upper left corner, the abscissa coordinate Z3 of the vertex of the lower right corner and the ordinate Z4 of the vertex of the lower right corner of the area are obtained.
应理解,本实施例中,仅以该区域的坐标包含该区域的左上角的顶点坐标以及该区域的右下角的顶点坐标进行示意性介绍。在实际应用中,该区域的坐标还可以是以下多种情况中的任意一种:(1)该区域的右上角的顶点坐标以及该区域的左下角的顶点坐标;(2)该区域的四个角的顶点坐标;(3)该区域的左上角的顶点坐标、该区域的左下角的顶点坐标以及该区域的中心点坐标;(4)该区域的右上角的顶点坐标、该区域的右下角的顶点坐标以及该区域的中心点坐标;(5)该区域的右上角的顶点坐标、该区域的左上角的顶点坐标以及该区域的中心点坐标;(6)该区域的右下角的顶点坐标、该区域的左下角的顶点坐标以及该区域的中心点坐标;(7)该区域的右上角的顶点坐标、该区域的右下角的顶点坐标、该区域的左上角的顶点坐标、该区域的左下角的顶点坐标以及该区域的中心点坐标等等。It should be understood that in this embodiment, the coordinates of the region include the vertex coordinates of the upper left corner of the region and the vertex coordinates of the lower right corner of the region for schematic introduction. In practical applications, the coordinates of the area can also be any of the following situations: (1) the vertex coordinates of the upper right corner of the area and the vertex coordinates of the lower left corner of the area; (2) the four vertex coordinates of the area the vertex coordinates of each corner; (3) the vertex coordinates of the upper left corner of the area, the vertex coordinates of the lower left corner of the area and the center point coordinates of the area; (4) the vertex coordinates of the upper right corner of the area, the right corner of the area The vertex coordinates of the lower corner and the center point coordinates of the area; (5) the vertex coordinates of the upper right corner of the area, the vertex coordinates of the upper left corner of the area and the center point coordinates of the area; (6) the vertex of the lower right corner of the area coordinates, the vertex coordinates of the lower left corner of the area and the center point coordinates of the area; (7) the vertex coordinates of the upper right corner of the area, the vertex coordinates of the lower right corner of the area, the vertex coordinates of the upper left corner of the area, the area The coordinates of the vertex of the lower left corner and the coordinates of the center point of the area, etc.
进一步地,在图4或图7所示的目标模型中,解码器的总输出长度不受限制。一般地,当所需要(位置信息以及文本)的向量表示的总数量小于或等于预置的阈值(例如,1024个)时,解码器可一次性输出所有的向量表示,当所需要的向量表示的总数量大于预置的阈值,解码器可以分批输出这些向量表示。例如,当所需要的向量表示为2000个,解码器可先输出第1个向量表示至第1024个向量表示作为第一批输出,然后,解码器可将第一批输出中末端的25%的向量表示作为输入,继续进行解码,从而输出第1025个向量表示至第2000个向量表示作为第二批输出。由此可见,本申请实施例提供的目标模型,可最终输出数量足够多的文本以及长度足够长的文本。Further, in the target model shown in Figure 4 or Figure 7, the total output length of the decoder is not limited. Generally, when the total number of required vector representations (location information and text) is less than or equal to a preset threshold (for example, 1024), the decoder can output all vector representations at once. If the number is greater than a preset threshold, the decoder can output these vector representations in batches. For example, when the required vector representations are 2000, the decoder can first output the 1st vector representation to the 1024th vector representation as the first batch of outputs, and then the decoder can output the last 25% of the vectors in the first batch of outputs. represents as input, and continues to be decoded, thereby outputting the 1025th vector representation to the 2000th vector representation as the second batch of outputs. It can be seen that the target model provided by the embodiment of the present application can finally output a sufficiently large number of texts and a text of sufficiently long length.
更进一步地,本申请实施例提供的目标模型为预训练模型,为了适应下游任务,可根据不同下游任务的需求对目标模型(的结构和参数)进行微调。下文结合若干个下游任务对该过程进行介绍:Furthermore, the target model provided by the embodiment of the present application is a pre-trained model. In order to adapt to downstream tasks, the target model (structure and parameters) can be fine-tuned according to the requirements of different downstream tasks. This process is introduced below in conjunction with several downstream tasks:
设下游任务为文档问答任务,如图8所示(图8为本申请实施例提供的目标模型的另一结构示意图),目标模型中的解码器依旧连接着坐标转换器和文字转换器(图8所示的目标模型的结构和图7所示的目标模型的结构可以是相同的),此时,输入至解码器的BOS为用户输入的提示(问题),解码器会基于用户输入的图像的特征,输出向量表示形式的回答的位置信息以及向量表示形式的回答。经过坐标转换器转换后,可得到回答的坐标,且经过文字转换器转换后,可得到文字形式的回答。那么,可将回答的坐标和文字形式的回答附加在用户输入的图像上,返回给用户。Assume that the downstream task is a document question and answer task, as shown in Figure 8 (Figure 8 is another structural diagram of the target model provided by the embodiment of the present application). The decoder in the target model is still connected to the coordinate converter and the text converter (Figure 8 The structure of the target model shown in Figure 8 can be the same as the structure of the target model shown in Figure 7). At this time, the BOS input to the decoder is the prompt (question) input by the user, and the decoder will be based on the image input by the user. features, output the location information of the answer in vector representation and the answer in vector representation. After conversion by the coordinate converter, the coordinates of the answer can be obtained, and after conversion by the text converter, the answer in text form can be obtained. Then, the coordinates of the answer and the answer in text form can be attached to the image input by the user and returned to the user.
例如,如图9所示(图9为本申请实施例提供的文档问答的一个示意图),用户输入一张高铁票的图像,并提问“X海鹏去哪里了?”,目标模型可对该图像进行处理后,可得到文字形式的回答“扎兰平站”以及回答“扎兰平站”在图像中的坐标,那么,可在图像中框选出“扎兰平站”,并附上相应的高亮文字显示,以返回给用户浏览。For example, as shown in Figure 9 (Figure 9 is a schematic diagram of document question and answer provided by the embodiment of this application), the user inputs an image of a high-speed rail ticket and asks "Where did X Haipeng go?", the target model can answer the question After the image is processed, the answer "Zhalanping Station" in text form and the coordinates of the answer "Zhalanping Station" in the image can be obtained. Then, "Zhalanping Station" can be selected in the image and attached. The corresponding highlighted text is displayed to return to the user for browsing.
设下游任务为信息抽取任务,如图10所示(图10为本申请实施例提供的目标模型的另一结构示意图),目标模型中的解码器则连接着信息抽取器(也就是说,图7所示的目标模型中的转换器被替换为信息抽取器),此时,输入至解码器的BOS依旧为一个无意义的向量表示,解码器会基于用户输入的图像的特征,输出向量表示形式的目标信息的位置信息以及向量表示形式的目标信息。经过信息抽取器综合处理后,可得到文字形式的目标信息。Assume that the downstream task is an information extraction task, as shown in Figure 10 (Figure 10 is another structural diagram of the target model provided by the embodiment of the present application). The decoder in the target model is connected to the information extractor (that is, Figure The converter in the target model shown in 7 is replaced by an information extractor). At this time, the BOS input to the decoder is still a meaningless vector representation. The decoder will output a vector representation based on the characteristics of the image input by the user. location information in the form of target information and target information in the form of a vector representation. After comprehensive processing by the information extractor, the target information in text form can be obtained.
例如,如图11所示(图11为本申请实施例提供的信息抽取的一个示意图),用户输入一张高铁票的图像。目标模型可对该图像进行处理后,可得到文字形式的时间、目的地、名字、出发地以及班次等等信息,并将这些信息返回给用户浏览。For example, as shown in Figure 11 (Figure 11 is a schematic diagram of information extraction provided by an embodiment of the present application), the user inputs an image of a high-speed rail ticket. After the target model processes the image, it can obtain information such as time, destination, name, departure place, flight, etc. in the form of text, and return this information to the user for browsing.
更进一步地,还可将本申请实施例提供的目标模型与某个相关技术提供的模型进行比较,比较结果如表1所示:Furthermore, the target model provided by the embodiment of the present application can also be compared with a model provided by a related technology. The comparison results are shown in Table 1:
表1Table 1
基于表1可知,本申请实施例提供的目标模型,不仅可解码更多类型的输出,还具备更低的计算复杂度,有效降低模型中解码器的功耗并加快解码速度。Based on Table 1, it can be seen that the target model provided by the embodiment of the present application can not only decode more types of output, but also has lower computational complexity, effectively reducing the power consumption of the decoder in the model and speeding up the decoding.
更进一步地,还可将本申请实施例提供的目标模型(例如,表2中的ours)与另一部分相关技术提供的模型(例如,除表2中的ours之外的其余模型,比如,BERT等等)进行比较,比较结果如表2所示:Furthermore, the target model provided by the embodiment of the present application (for example, ours in Table 2) can also be combined with the model provided by another part of related technology (for example, other models except ours in Table 2, such as BERT etc.) are compared, and the comparison results are shown in Table 2:
表2Table 2
基于表2可知,本申请实施例提供的目标模型具备更优的性能。Based on Table 2, it can be seen that the target model provided by the embodiment of this application has better performance.
本申请实施例中,当需要从目标图像中提取目标文本时,可先获取包含多个文本的目标图像,并将目标图像输入至目标模型。接着,目标模型可对目标图像进行编码,从而得到目标图像的特征。然后,目标模型可对目标图像的特征进行处理,从而得到多个文本中的目标文本在目标图像中的位置信息。最后,目标模型可对目标图像的特征以及目标文本在目标图像中的位置信息做进一步的处理,从而得到目标文本。至此,则成功从目标图像中提取出了目标文本。前述过程中,目标模型在对目标图像的内容进行理解时,不仅考虑了目标图像的特征,还考虑了目标文本在目标图像中的位置信息,这样考虑的因素较为全面,可以对目标图像的内容进行充分且准确的理解,由此可见,目标模型按照这种方式从目标图像所呈现的多个文本中提取出的目标文本,通常是正确的文本。In the embodiment of the present application, when it is necessary to extract target text from a target image, a target image containing multiple texts can be obtained first, and the target image can be input into the target model. Then, the target model can encode the target image to obtain the characteristics of the target image. Then, the target model can process the features of the target image to obtain the position information of the target text in the target image among the multiple texts. Finally, the target model can further process the characteristics of the target image and the position information of the target text in the target image to obtain the target text. At this point, the target text has been successfully extracted from the target image. In the aforementioned process, when the target model understands the content of the target image, it not only considers the characteristics of the target image, but also considers the position information of the target text in the target image. In this way, the factors considered are more comprehensive and the content of the target image can be understood. With a full and accurate understanding, it can be seen that the target text extracted by the target model in this way from the multiple texts presented by the target image is usually the correct text.
进一步地,目标模型最终输出的不仅包含字符形式(文字)的目标文本,还包含目标文本在目标图像中所占据的区域的坐标,可将这两类信息叠加在目标图像上,并返回给用户浏览,这样可以通过可视化交互界面的方式,为用户提供其所需的目标文本,还可向用户解释目标模型提取出目标文本的依据。Furthermore, the final output of the target model not only contains the target text in the form of characters (text), but also contains the coordinates of the area occupied by the target text in the target image. These two types of information can be superimposed on the target image and returned to the user. Browsing can provide users with the target text they need through a visual interactive interface, and can also explain to users the basis for extracting the target text by the target model.
进一步地,目标模型的输出长度是不受限制的,这样一来,即使用户需要获取较长的文本或者数量较多的文本,目标模型均可以满足用户的需求,从而提高用户体验。Furthermore, the output length of the target model is not limited. In this way, even if the user needs to obtain longer text or a larger amount of text, the target model can meet the user's needs, thus improving the user experience.
以上是对本申请实施例提供的文本获取方法所进行的详细说明,以下将对本申请实施例提供的模型训练方法进行介绍。图12为本申请实施例提供的模型训练方法的一个流程示意图,如图12所示,该方法包括:The above is a detailed description of the text acquisition method provided by the embodiment of the present application. The model training method provided by the embodiment of the present application will be introduced below. Figure 12 is a schematic flow chart of the model training method provided by the embodiment of the present application. As shown in Figure 12, the method includes:
1201、获取目标图像,目标图像包含多个文本。1201. Obtain the target image. The target image contains multiple texts.
本实施例中,当需要对待训练模型进行训练时,可先获取一批训练数据,该批训练数据包含目标图像,其中,目标图像所呈现的内容包含多个文本,且对于目标图像所包含的多个文本而言,多个文本中目标文本的所有真实字符是已知的,且目标文本在目标图像所占据的区域的真实坐标也是已知的In this embodiment, when it is necessary to train the model to be trained, a batch of training data can be obtained first. The batch of training data includes a target image, where the content presented by the target image includes multiple texts, and for the content contained in the target image For multiple texts, all the real characters of the target text in the multiple texts are known, and the real coordinates of the target text in the area occupied by the target image are also known.
1202、通过待训练模型对目标图像进行处理,得到目标文本在目标图像中的位置信息以及目标文本,多个文本包含目标文本,待训练模型用于:对目标图像进行编码,得到目标图像的特征;基于特征,获取位置信息;基于特征以及位置信息,获取目标文本。1202. Process the target image through the model to be trained to obtain the position information of the target text in the target image and the target text. Multiple texts contain the target text. The model to be trained is used to: encode the target image and obtain the characteristics of the target image. ; Based on features, obtain location information; Based on features and location information, obtain target text.
得到目标图像后,可将目标图像输入至待训练模型。那么,待训练模型可对目标图像进行编码,得到目标图像的特征。接着,待训练模型可基于目标图像的特征,获取目标文本在目标图像中的位置信息。最后,目标模型可基于目标图像的特征以及目标文本在目标图像中的位置信息,获取目标文本。After obtaining the target image, the target image can be input to the model to be trained. Then, the model to be trained can encode the target image and obtain the characteristics of the target image. Then, the model to be trained can obtain the position information of the target text in the target image based on the characteristics of the target image. Finally, the target model can obtain the target text based on the characteristics of the target image and the position information of the target text in the target image.
在一种可能实现的方式中,待训练模型,用于基于特征,对目标文本在目标图像中的位置信息的第1个向量表示至位置信息的第i个向量表示进行解码,得到位置信息的第i+1个向量表示,i=1,...,X-1,X≥1,位置信息的第1个向量表示基于特征对预置的向量表示进行解码得到。In one possible implementation, the model to be trained is used to decode the first vector representation of the position information of the target text in the target image to the i-th vector representation of the position information based on the features, and obtain the position information. The i+1th vector representation, i=1,...,X-1,X≥1, is obtained by decoding the preset vector representation based on features.
在一种可能实现的方式中,待训练模型,用于基于特征,对位置信息,目标文本的第1个向量表示至目标文本的第j个向量表示进行解码,得到目标文本的第j+1个向量表示,j=1,...,Y-1,Y≥1,目标文本的第1个向量表示基于特征对位置信息进行解码得到。In one possible implementation, the model to be trained is used to decode the position information, the first vector representation of the target text to the jth vector representation of the target text based on the features, and obtain the j+1th vector representation of the target text. vector representation, j=1,...,Y-1, Y≥1, the first vector representation of the target text is obtained by decoding the position information based on the features.
在一种可能实现的方式中,目标文本包含第一文本以及第二文本,位置信息包含第一文本在目标图像中的第一位置信息以及第二文本在目标图像中的第二位置信息,待训练模型,用于:基于特征,对第一位置信息的第1个向量表示至第一位置信息的第i个向量表示进行解码,得到第一位置信息的第i+1个向量表示,i=1,...,X-1,X≥1,第一位置信息的第1个向量表示基于特征对预置的向量表示进行解码得到;基于特征,对第一位置信息,第一文本,第二位置信息的第1个向量表示至第二位置信息的第k个向量表示进行解码,得到第一位置信息的第k+1个向量表示,k=1,...,Z-1,Z≥1,第二位置信息的第1个向量表示基于特征对第一位置信息以及第一文本进行解码得到。In a possible implementation manner, the target text includes a first text and a second text, and the position information includes first position information of the first text in the target image and second position information of the second text in the target image. The training model is used to: decode the first vector representation of the first position information to the i-th vector representation of the first position information based on the features, and obtain the i+1-th vector representation of the first position information, i= 1,...,X-1, Decode the first vector representation of the second position information to the k-th vector representation of the second position information to obtain the k+1-th vector representation of the first position information, k=1,...,Z-1,Z ≥1, the first vector representation of the second position information is obtained by decoding the first position information and the first text based on the features.
在一种可能实现的方式中,待训练模型,用于:基于特征,对第一位置信息,第一文本的第1个向量表示至第一文本的第j个向量表示进行解码,得到第一文本的第j+1个向量表示,j=1,...,Y-1,Y≥1,第一文本的第1个向量表示基于特征对位置信息进行解码得到;基于特征,对第一位置信息,第一文本,第二位置信息,第二文本的第1个向量表示至第二文本的第t个向量表示进行解码,得到第二文本的第t+1个向量表示,t=1,...,U-1,U≥1,第二文本的第1个向量表示基于特征对第一位置信息,第一文本以及第二位置信息进行解码得到。In a possible implementation manner, the model to be trained is used to: decode the first position information, the first vector representation of the first text to the jth vector representation of the first text based on the features, and obtain the first The j+1th vector representation of the text, j=1,...,Y-1, Y≥1, the first vector representation of the first text is obtained by decoding the position information based on the feature; based on the feature, the first Decode the position information, the first text, the second position information, the first vector representation of the second text to the t-th vector representation of the second text, and obtain the t+1-th vector representation of the second text, t=1 ,...,U-1, U≥1, the first vector representation of the second text is obtained by decoding the first position information, the first text and the second position information based on the features.
在一种可能实现的方式中,待训练模型,还用于对位置信息的所有向量表示进行转换,得到目标文本在目标图像中所占据的区域的(预测)坐标。In one possible implementation, the model to be trained is also used to convert all vector representations of position information to obtain the (predicted) coordinates of the area occupied by the target text in the target image.
在一种可能实现的方式中,待训练模型,还用于对目标文本的所有向量表示进行转换,得到目标文本的所有(预测)字符。In one possible implementation, the model to be trained is also used to convert all vector representations of the target text to obtain all (predicted) characters of the target text.
在一种可能实现的方式中,待训练模型对目标文本以及位置信息所执行的转换可以为以下至少一种:基于循环神经网络的特征提取、基于多层感知机的特征提取以及基于时间卷积网络的特征提取。In a possible implementation manner, the conversion performed by the model to be trained on the target text and location information can be at least one of the following: feature extraction based on recurrent neural networks, feature extraction based on multi-layer perceptrons, and temporal convolution based Feature extraction of networks.
在一种可能实现的方式中,区域的坐标为以下至少一种:区域的左上角的顶点坐标以及区域的右下角的顶点坐标;或,区域的右上角的顶点坐标以及区域的左下角的顶点坐标;或,区域的四个角的顶点坐标;或,区域的左上角的顶点坐标、区域的左下角的顶点坐标以及区域的中心点坐标;或,区域的右上角的顶点坐标、区域的右下角的顶点坐标以及区域的中心点坐标;或,区域的右上角的顶点坐标、区域的左上角的顶点坐标以及区域的中心点坐标;或,区域的右下角的顶点坐标、区域的左下角的顶点坐标以及区域的中心点坐标;或,区域的右上角的顶点坐标、区域的右下角的顶点坐标、区域的左上角的顶点坐标、区域的左下角的顶点坐标以及区域的中心点坐标。In a possible implementation manner, the coordinates of the area are at least one of the following: the vertex coordinates of the upper left corner of the area and the vertex coordinates of the lower right corner of the area; or, the vertex coordinates of the upper right corner of the area and the vertex of the lower left corner of the area coordinates; or, the vertex coordinates of the four corners of the area; or, the vertex coordinates of the upper left corner of the area, the vertex coordinates of the lower left corner of the area, and the center point coordinates of the area; or, the vertex coordinates of the upper right corner of the area, the right corner of the area The vertex coordinates of the lower corner and the center point coordinates of the area; or, the vertex coordinates of the upper right corner of the area, the vertex coordinates of the upper left corner of the area, and the center point coordinates of the area; or, the vertex coordinates of the lower right corner of the area, the lower left corner of the area The vertex coordinates and the center point coordinates of the region; or, the vertex coordinates of the upper right corner of the region, the vertex coordinates of the lower right corner of the region, the vertex coordinates of the upper left corner of the region, the vertex coordinates of the lower left corner of the region, and the center point coordinates of the region.
关于步骤1202的介绍,可参考图5所示实施例中步骤502至步骤504的相关说明部分,此处不再赘述。For the introduction of step 1202, please refer to the relevant descriptions of steps 502 to 504 in the embodiment shown in FIG. 5, which will not be described again here.
1203、基于目标文本,对待训练模型进行训练,得到目标模型。1203. Based on the target text, train the model to be trained to obtain the target model.
得到目标文本后,可基于目标文本来对待训练模型进行训练,从而得到图5所示实施例中的目标模型。After obtaining the target text, the model to be trained can be trained based on the target text, thereby obtaining the target model in the embodiment shown in Figure 5.
具体地,可通过以下方式来完成目标模型的训练:Specifically, the training of the target model can be completed in the following ways:
在得到目标文本的所有字符以及目标文本在目标图像中所占据的区域的坐标后,可通过预置的第一损失函数对目标文本的字符以及目标文本的真实字符进行计算,从而得到第一损失。其中,第一损失可通过以下公式获取:After obtaining all the characters of the target text and the coordinates of the area occupied by the target text in the target image, the characters of the target text and the real characters of the target text can be calculated through the preset first loss function, thereby obtaining the first loss . Among them, the first loss can be obtained by the following formula:
上式中,LRead为第一损失,X为目标图像的特征,yr-1为目标文本的第r-1个字符,yr为目标文本的第r个字符,y′r为目标文本的第r个真实字符。由此可见,第一损失可用于指示目标文本的字符以及目标文本的真实字符之间的差异。In the aboveformula ,LRead is the first loss, The rth real character. It follows that the first loss can be used to indicate the difference between the characters of the target text and the real characters of the target text.
接着,还可通过预置的第二损失函数对目标文本在目标图像中所占据的区域的坐标,以及目标文本在目标图像中所占据的区域的真实坐标进行计算,从而得到第二损失。其中,第二损失可通过以下公式获取:Then, the coordinates of the area occupied by the target text in the target image and the real coordinates of the area occupied by the target text in the target image can also be calculated through the preset second loss function, thereby obtaining the second loss. Among them, the second loss can be obtained by the following formula:
上式中,LLocate为第二损失,为第s个目标文本在目标图像中所占据的区域的第u-1个坐标,/>为第s个目标文本在目标图像中所占据的区域的第u个坐标,/>为第s个目标文本在目标图像中所占据的区域的第u个真实坐标。由此可见,第二损失可用于指示目标文本在目标图像中所占据的区域的坐标,以及目标文本在目标图像中所占据的区域的真实坐标之间的差异。In the above formula, LLocate is the second loss, is the u-1th coordinate of the area occupied by the sth target text in the target image,/> is the u-th coordinate of the area occupied by the s-th target text in the target image,/> is the u-th real coordinate of the area occupied by the s-th target text in the target image. It can be seen that the second loss can be used to indicate the difference between the coordinates of the area occupied by the target text in the target image and the true coordinates of the area occupied by the target text in the target image.
然后,可将第一损失以及第二损失进行叠加,从而得到目标损失。那么,可利用目标损失对待训练模型的参数进行更新,从而得到更新后的待训练模型,并利用下一批训练数据对更新参数后的待训练模型继续进行训练,直至满足模型训练条件(例如,目标损失收敛等等),从而得到目标模型。Then, the first loss and the second loss can be superimposed to obtain the target loss. Then, the target loss can be used to update the parameters of the model to be trained, thereby obtaining the updated model to be trained, and the next batch of training data can be used to continue training the model to be trained with updated parameters until the model training conditions are met (for example, Target loss convergence, etc.), thereby obtaining the target model.
本申请实施例训练得到的目标文本,具备文本获取功能。具体地,当需要从目标图像中提取目标文本时,可先获取包含多个文本的目标图像,并将目标图像输入至目标模型。接着,目标模型可对目标图像进行编码,从而得到目标图像的特征。然后,目标模型可对目标图像的特征进行处理,从而得到多个文本中的目标文本在目标图像中的位置信息。最后,目标模型可对目标图像的特征以及目标文本在目标图像中的位置信息做进一步的处理,从而得到目标文本。至此,则成功从目标图像中提取出了目标文本。前述过程中,目标模型在对目标图像的内容进行理解时,不仅考虑了目标图像的特征,还考虑了目标文本在目标图像中的位置信息,这样考虑的因素较为全面,可以对目标图像的内容进行充分且准确的理解,由此可见,目标模型按照这种方式从目标图像所呈现的多个文本中提取出的目标文本,通常是正确的文本。The target text obtained by training in the embodiment of this application has a text acquisition function. Specifically, when the target text needs to be extracted from the target image, a target image containing multiple texts can be obtained first, and the target image can be input to the target model. Then, the target model can encode the target image to obtain the characteristics of the target image. Then, the target model can process the features of the target image to obtain the position information of the target text in the target image among the multiple texts. Finally, the target model can further process the characteristics of the target image and the position information of the target text in the target image to obtain the target text. At this point, the target text has been successfully extracted from the target image. In the aforementioned process, when the target model understands the content of the target image, it not only considers the characteristics of the target image, but also considers the position information of the target text in the target image. In this way, the factors considered are more comprehensive and the content of the target image can be understood. With a full and accurate understanding, it can be seen that the target text extracted by the target model in this way from the multiple texts presented by the target image is usually the correct text.
以上是对本申请实施例提供的文本获取方法以及模型训练方法所进行的详细说明,以下将对本申请实施例提供的文本获取装置以及模型训练装置进行介绍。图13为本申请实施例提供的文本获取装置的一个结构示意图,如图13所示,该装置包括:The above is a detailed description of the text acquisition method and the model training method provided by the embodiment of the present application. The text acquisition device and the model training device provided by the embodiment of the present application will be introduced below. Figure 13 is a schematic structural diagram of a text acquisition device provided by an embodiment of the present application. As shown in Figure 13, the device includes:
第一获取模块1301,用于获取目标图像,目标图像包含多个文本;The first acquisition module 1301 is used to acquire a target image, where the target image contains multiple texts;
编码模块1302,用于对目标图像进行编码,得到目标图像的特征;Encoding module 1302, used to encode the target image to obtain the characteristics of the target image;
第二获取模块1303,用于基于特征,获取目标文本在目标图像中的位置信息,多个文本包含目标文本;The second acquisition module 1303 is used to acquire the position information of the target text in the target image based on the features. Multiple texts include the target text;
第三获取模块1304,用于基于特征以及位置信息,获取目标文本。The third acquisition module 1304 is used to acquire target text based on features and location information.
本申请实施例中,当需要从目标图像中提取目标文本时,可先获取包含多个文本的目标图像,并将目标图像输入至目标模型。接着,目标模型可对目标图像进行编码,从而得到目标图像的特征。然后,目标模型可对目标图像的特征进行处理,从而得到多个文本中的目标文本在目标图像中的位置信息。最后,目标模型可对目标图像的特征以及目标文本在目标图像中的位置信息做进一步的处理,从而得到目标文本。至此,则成功从目标图像中提取出了目标文本。前述过程中,目标模型在对目标图像的内容进行理解时,不仅考虑了目标图像的特征,还考虑了目标文本在目标图像中的位置信息,这样考虑的因素较为全面,可以对目标图像的内容进行充分且准确的理解,由此可见,目标模型按照这种方式从目标图像所呈现的多个文本中提取出的目标文本,通常是正确的文本。In the embodiment of the present application, when it is necessary to extract target text from a target image, a target image containing multiple texts can be obtained first, and the target image can be input into the target model. Then, the target model can encode the target image to obtain the characteristics of the target image. Then, the target model can process the features of the target image to obtain the position information of the target text in the target image among the multiple texts. Finally, the target model can further process the characteristics of the target image and the position information of the target text in the target image to obtain the target text. At this point, the target text has been successfully extracted from the target image. In the aforementioned process, when the target model understands the content of the target image, it not only considers the characteristics of the target image, but also considers the position information of the target text in the target image. In this way, the factors considered are more comprehensive and the content of the target image can be understood. With a full and accurate understanding, it can be seen that the target text extracted by the target model in this way from the multiple texts presented by the target image is usually the correct text.
在一种可能实现的方式中,第二获取模块1303,用于基于特征,对目标文本在目标图像中的位置信息的第1个向量表示至位置信息的第i个向量表示进行解码,得到位置信息的第i+1个向量表示,i=1,...,X-1,X≥1,位置信息的第1个向量表示基于特征对预置的向量表示进行解码得到。In a possible implementation manner, the second acquisition module 1303 is used to decode the first vector representation of the position information of the target text in the target image to the i-th vector representation of the position information based on the features to obtain the position. The i+1th vector representation of the information, i=1,...,X-1,X≥1, and the first vector representation of the position information are obtained by decoding the preset vector representation based on features.
在一种可能实现的方式中,第三获取模块1304,用于基于特征,对位置信息,目标文本的第1个向量表示至目标文本的第j个向量表示进行解码,得到目标文本的第j+1个向量表示,j=1,...,Y-1,Y≥1,目标文本的第1个向量表示基于特征对位置信息进行解码得到。In a possible implementation manner, the third acquisition module 1304 is used to decode the position information, the first vector representation of the target text to the jth vector representation of the target text based on the features, and obtain the jth vector representation of the target text. +1 vector representation, j=1,...,Y-1, Y≥1, the first vector representation of the target text is obtained by decoding the position information based on the features.
在一种可能实现的方式中,目标文本包含第一文本以及第二文本,位置信息包含第一文本在目标图像中的第一位置信息以及第二文本在目标图像中的第二位置信息,第二获取模块1303,用于基于特征,对第一位置信息的第1个向量表示至第一位置信息的第i个向量表示进行解码,得到第一位置信息的第i+1个向量表示,i=1,...,X-1,X≥1,第一位置信息的第1个向量表示基于特征对预置的向量表示进行解码得到;基于特征,对第一位置信息,第一文本,第二位置信息的第1个向量表示至第二位置信息的第k个向量表示进行解码,得到第一位置信息的第k+1个向量表示,k=1,...,Z-1,Z≥1,第二位置信息的第1个向量表示基于特征对第一位置信息以及第一文本进行解码得到。In a possible implementation manner, the target text includes a first text and a second text, and the position information includes first position information of the first text in the target image and second position information of the second text in the target image. The second acquisition module 1303 is used to decode the first vector representation of the first position information to the i-th vector representation of the first position information based on the characteristics, and obtain the i+1-th vector representation of the first position information, i =1,...,X-1, The first vector representation of the second position information is decoded to the k-th vector representation of the second position information, and the k+1-th vector representation of the first position information is obtained, k=1,...,Z-1, Z≥1, the first vector representation of the second position information is obtained by decoding the first position information and the first text based on the features.
在一种可能实现的方式中,第三获取模块1304,用于基于特征,对第一位置信息,第一文本的第1个向量表示至第一文本的第j个向量表示进行解码,得到第一文本的第j+1个向量表示,j=1,...,Y-1,Y≥1,第一文本的第1个向量表示基于特征对位置信息进行解码得到;基于特征,对第一位置信息,第一文本,第二位置信息,第二文本的第1个向量表示至第二文本的第t个向量表示进行解码,得到第二文本的第t+1个向量表示,t=1,...,U-1,U≥1,第二文本的第1个向量表示基于特征对第一位置信息,第一文本以及第二位置信息进行解码得到。In a possible implementation manner, the third acquisition module 1304 is configured to decode the first position information, the first vector representation of the first text to the jth vector representation of the first text based on the features, and obtain the jth vector representation of the first text. The j+1th vector representation of a text, j=1,...,Y-1, Y≥1, the first vector representation of the first text is obtained by decoding the position information based on the feature; based on the feature, the One position information, the first text, the second position information, the first vector representation of the second text to the t-th vector representation of the second text are decoded to obtain the t+1-th vector representation of the second text, t= 1,...,U-1, U≥1, the first vector representation of the second text is obtained by decoding the first position information, the first text and the second position information based on the features.
在一种可能实现的方式中,该装置还包括:第一转换模块,用于对位置信息的所有向量表示进行转换,得到目标文本在目标图像中所占据的区域的坐标。In a possible implementation manner, the device further includes: a first conversion module, configured to convert all vector representations of the position information to obtain the coordinates of the area occupied by the target text in the target image.
在一种可能实现的方式中,该装置还包括:第二转换模块,用于对目标文本的所有向量表示进行转换,得到目标文本的所有字符。In a possible implementation manner, the device further includes: a second conversion module, configured to convert all vector representations of the target text to obtain all characters of the target text.
在一种可能实现的方式中,目标模型对目标文本以及位置信息所执行的转换可以为以下至少一种:基于循环神经网络的特征提取、基于多层感知机的特征提取以及基于时间卷积网络的特征提取。In a possible implementation manner, the conversion performed by the target model on the target text and location information can be at least one of the following: feature extraction based on recurrent neural networks, feature extraction based on multi-layer perceptrons, and temporal convolutional networks. feature extraction.
在一种可能实现的方式中,区域的坐标为以下至少一种:区域的左上角的顶点坐标以及区域的右下角的顶点坐标;或,区域的右上角的顶点坐标以及区域的左下角的顶点坐标;或,区域的四个角的顶点坐标;或,区域的左上角的顶点坐标、区域的左下角的顶点坐标以及区域的中心点坐标;或,区域的右上角的顶点坐标、区域的右下角的顶点坐标以及区域的中心点坐标;或,区域的右上角的顶点坐标、区域的左上角的顶点坐标以及区域的中心点坐标;或,区域的右下角的顶点坐标、区域的左下角的顶点坐标以及区域的中心点坐标;或,区域的右上角的顶点坐标、区域的右下角的顶点坐标、区域的左上角的顶点坐标、区域的左下角的顶点坐标以及区域的中心点坐标。In a possible implementation manner, the coordinates of the area are at least one of the following: the vertex coordinates of the upper left corner of the area and the vertex coordinates of the lower right corner of the area; or, the vertex coordinates of the upper right corner of the area and the vertex of the lower left corner of the area coordinates; or, the vertex coordinates of the four corners of the area; or, the vertex coordinates of the upper left corner of the area, the vertex coordinates of the lower left corner of the area, and the center point coordinates of the area; or, the vertex coordinates of the upper right corner of the area, the right corner of the area The vertex coordinates of the lower corner and the center point coordinates of the area; or, the vertex coordinates of the upper right corner of the area, the vertex coordinates of the upper left corner of the area, and the center point coordinates of the area; or, the vertex coordinates of the lower right corner of the area, the lower left corner of the area The vertex coordinates and the center point coordinates of the region; or, the vertex coordinates of the upper right corner of the region, the vertex coordinates of the lower right corner of the region, the vertex coordinates of the upper left corner of the region, the vertex coordinates of the lower left corner of the region, and the center point coordinates of the region.
图14为本申请实施例提供的模型训练装置的一个结构示意图,如图14所示,该装置包括:Figure 14 is a schematic structural diagram of a model training device provided by an embodiment of the present application. As shown in Figure 14, the device includes:
获取模块1401,用于获取目标图像,目标图像包含多个文本;The acquisition module 1401 is used to acquire a target image, where the target image contains multiple texts;
处理模块1402,用于通过待训练模型对目标图像进行处理,得到目标文本在目标图像中的位置信息以及目标文本,多个文本包含目标文本,待训练模型用于:对目标图像进行编码,得到目标图像的特征;基于特征,获取位置信息;基于特征以及位置信息,获取目标文本;The processing module 1402 is used to process the target image through the model to be trained to obtain the position information of the target text in the target image and the target text. Multiple texts include the target text. The model to be trained is used to: encode the target image to obtain Features of the target image; based on the features, obtain location information; based on features and location information, obtain the target text;
训练模块1403,用于基于目标文本,对待训练模型进行训练,得到目标模型。The training module 1403 is used to train the model to be trained based on the target text to obtain the target model.
本申请实施例训练得到的目标文本,具备文本获取功能。具体地,当需要从目标图像中提取目标文本时,可先获取包含多个文本的目标图像,并将目标图像输入至目标模型。接着,目标模型可对目标图像进行编码,从而得到目标图像的特征。然后,目标模型可对目标图像的特征进行处理,从而得到多个文本中的目标文本在目标图像中的位置信息。最后,目标模型可对目标图像的特征以及目标文本在目标图像中的位置信息做进一步的处理,从而得到目标文本。至此,则成功从目标图像中提取出了目标文本。前述过程中,目标模型在对目标图像的内容进行理解时,不仅考虑了目标图像的特征,还考虑了目标文本在目标图像中的位置信息,这样考虑的因素较为全面,可以对目标图像的内容进行充分且准确的理解,由此可见,目标模型按照这种方式从目标图像所呈现的多个文本中提取出的目标文本,通常是正确的文本。The target text obtained by training in the embodiment of this application has a text acquisition function. Specifically, when the target text needs to be extracted from the target image, a target image containing multiple texts can be obtained first, and the target image can be input to the target model. Then, the target model can encode the target image to obtain the characteristics of the target image. Then, the target model can process the features of the target image to obtain the position information of the target text in the target image among the multiple texts. Finally, the target model can further process the characteristics of the target image and the position information of the target text in the target image to obtain the target text. At this point, the target text has been successfully extracted from the target image. In the aforementioned process, when the target model understands the content of the target image, it not only considers the characteristics of the target image, but also considers the position information of the target text in the target image. In this way, the factors considered are more comprehensive and the content of the target image can be understood. With a full and accurate understanding, it can be seen that the target text extracted by the target model in this way from the multiple texts presented by the target image is usually the correct text.
在一种可能实现的方式中,待训练模型,用于基于特征,对目标文本在目标图像中的位置信息的第1个向量表示至位置信息的第i个向量表示进行解码,得到位置信息的第i+1个向量表示,i=1,...,X-1,X≥1,位置信息的第1个向量表示基于特征对预置的向量表示进行解码得到。In one possible implementation, the model to be trained is used to decode the first vector representation of the position information of the target text in the target image to the i-th vector representation of the position information based on the features, and obtain the position information. The i+1th vector representation, i=1,...,X-1,X≥1, is obtained by decoding the preset vector representation based on features.
在一种可能实现的方式中,待训练模型,用于基于特征,对位置信息,目标文本的第1个向量表示至目标文本的第j个向量表示进行解码,得到目标文本的第j+1个向量表示,j=1,...,Y-1,Y≥1,目标文本的第1个向量表示基于特征对位置信息进行解码得到。In one possible implementation, the model to be trained is used to decode the position information, the first vector representation of the target text to the jth vector representation of the target text based on the features, and obtain the j+1th vector representation of the target text. vector representation, j=1,...,Y-1, Y≥1, the first vector representation of the target text is obtained by decoding the position information based on the features.
在一种可能实现的方式中,目标文本包含第一文本以及第二文本,位置信息包含第一文本在目标图像中的第一位置信息以及第二文本在目标图像中的第二位置信息,待训练模型,用于:基于特征,对第一位置信息的第1个向量表示至第一位置信息的第i个向量表示进行解码,得到第一位置信息的第i+1个向量表示,i=1,...,X-1,X≥1,第一位置信息的第1个向量表示基于特征对预置的向量表示进行解码得到;基于特征,对第一位置信息,第一文本,第二位置信息的第1个向量表示至第二位置信息的第k个向量表示进行解码,得到第一位置信息的第k+1个向量表示,k=1,...,Z-1,Z≥1,第二位置信息的第1个向量表示基于特征对第一位置信息以及第一文本进行解码得到。In a possible implementation manner, the target text includes a first text and a second text, and the position information includes first position information of the first text in the target image and second position information of the second text in the target image. The training model is used to: decode the first vector representation of the first position information to the i-th vector representation of the first position information based on the features, and obtain the i+1-th vector representation of the first position information, i= 1,...,X-1, Decode the first vector representation of the second position information to the k-th vector representation of the second position information to obtain the k+1-th vector representation of the first position information, k=1,...,Z-1,Z ≥1, the first vector representation of the second position information is obtained by decoding the first position information and the first text based on the features.
在一种可能实现的方式中,待训练模型,用于:基于特征,对第一位置信息,第一文本的第1个向量表示至第一文本的第j个向量表示进行解码,得到第一文本的第j+1个向量表示,j=1,...,Y-1,Y≥1,第一文本的第1个向量表示基于特征对位置信息进行解码得到;基于特征,对第一位置信息,第一文本,第二位置信息,第二文本的第1个向量表示至第二文本的第t个向量表示进行解码,得到第二文本的第t+1个向量表示,t=1,...,U-1,U≥1,第二文本的第1个向量表示基于特征对第一位置信息,第一文本以及第二位置信息进行解码得到。In a possible implementation manner, the model to be trained is used to: decode the first position information, the first vector representation of the first text to the jth vector representation of the first text based on the features, and obtain the first The j+1th vector representation of the text, j=1,...,Y-1, Y≥1, the first vector representation of the first text is obtained by decoding the position information based on the feature; based on the feature, the first Decode the position information, the first text, the second position information, the first vector representation of the second text to the t-th vector representation of the second text, and obtain the t+1-th vector representation of the second text, t=1 ,...,U-1, U≥1, the first vector representation of the second text is obtained by decoding the first position information, the first text and the second position information based on the features.
在一种可能实现的方式中,待训练模型,还用于对位置信息的所有向量表示进行转换,得到目标文本在目标图像中所占据的区域的坐标。In one possible implementation, the model to be trained is also used to convert all vector representations of position information to obtain the coordinates of the area occupied by the target text in the target image.
在一种可能实现的方式中,待训练模型,还用于对目标文本的所有向量表示进行转换,得到目标文本的所有字符。训练模块1403,用于基于字符以及坐标,对待训练模型进行训练,得到目标模型。In one possible implementation, the model to be trained is also used to convert all vector representations of the target text to obtain all characters of the target text. The training module 1403 is used to train the model to be trained based on characters and coordinates to obtain the target model.
在一种可能实现的方式中,待训练模型对目标文本以及位置信息所执行的转换可以为以下至少一种:基于循环神经网络的特征提取、基于多层感知机的特征提取以及基于时间卷积网络的特征提取。In a possible implementation manner, the conversion performed by the model to be trained on the target text and location information can be at least one of the following: feature extraction based on recurrent neural networks, feature extraction based on multi-layer perceptrons, and temporal convolution based Feature extraction of networks.
在一种可能实现的方式中,区域的坐标为以下至少一种:区域的左上角的顶点坐标以及区域的右下角的顶点坐标;或,区域的右上角的顶点坐标以及区域的左下角的顶点坐标;或,区域的四个角的顶点坐标;或,区域的左上角的顶点坐标、区域的左下角的顶点坐标以及区域的中心点坐标;或,区域的右上角的顶点坐标、区域的右下角的顶点坐标以及区域的中心点坐标;或,区域的右上角的顶点坐标、区域的左上角的顶点坐标以及区域的中心点坐标;或,区域的右下角的顶点坐标、区域的左下角的顶点坐标以及区域的中心点坐标;或,区域的右上角的顶点坐标、区域的右下角的顶点坐标、区域的左上角的顶点坐标、区域的左下角的顶点坐标以及区域的中心点坐标。In a possible implementation manner, the coordinates of the area are at least one of the following: the vertex coordinates of the upper left corner of the area and the vertex coordinates of the lower right corner of the area; or, the vertex coordinates of the upper right corner of the area and the vertex of the lower left corner of the area coordinates; or, the vertex coordinates of the four corners of the area; or, the vertex coordinates of the upper left corner of the area, the vertex coordinates of the lower left corner of the area, and the center point coordinates of the area; or, the vertex coordinates of the upper right corner of the area, the right corner of the area The vertex coordinates of the lower corner and the center point coordinates of the area; or, the vertex coordinates of the upper right corner of the area, the vertex coordinates of the upper left corner of the area, and the center point coordinates of the area; or, the vertex coordinates of the lower right corner of the area, the lower left corner of the area The vertex coordinates and the center point coordinates of the region; or, the vertex coordinates of the upper right corner of the region, the vertex coordinates of the lower right corner of the region, the vertex coordinates of the upper left corner of the region, the vertex coordinates of the lower left corner of the region, and the center point coordinates of the region.
需要说明的是,上述装置各模块/单元之间的信息交互、执行过程等内容,由于与本申请方法实施例基于同一构思,其带来的技术效果与本申请方法实施例相同,具体内容可参考本申请实施例前述所示的方法实施例中的叙述,此处不再赘述。It should be noted that the information interaction, execution process, etc. between the modules/units of the above-mentioned device are based on the same concept as the method embodiments of the present application, and the technical effects they bring are the same as those of the method embodiments of the present application. The specific content can be Refer to the description in the method embodiments shown above in the embodiments of the present application, which will not be described again here.
本申请实施例还涉及一种执行设备,图15为本申请实施例提供的执行设备的一个结构示意图。如图15所示,执行设备1500具体可以表现为手机、平板、笔记本电脑、智能穿戴设备、服务器等,此处不做限定。其中,执行设备1500上可部署有图13对应实施例中所描述的文本获取装置,用于实现图5对应实施例中文本获取的功能。具体的,执行设备1500包括:接收器1501、发射器1502、处理器1503和存储器1504(其中执行设备1500中的处理器1503的数量可以一个或多个,图15中以一个处理器为例),其中,处理器1503可以包括应用处理器15031和通信处理器15032。在本申请的一些实施例中,接收器1501、发射器1502、处理器1503和存储器1504可通过总线或其它方式连接。The embodiment of the present application also relates to an execution device. Figure 15 is a schematic structural diagram of the execution device provided by the embodiment of the present application. As shown in Figure 15, the execution device 1500 can be embodied as a mobile phone, a tablet, a laptop, a smart wearable device, a server, etc., and is not limited here. The text acquisition device described in the corresponding embodiment of FIG. 13 may be deployed on the execution device 1500 to implement the text acquisition function in the corresponding embodiment of FIG. 5 . Specifically, the execution device 1500 includes: a receiver 1501, a transmitter 1502, a processor 1503 and a memory 1504 (the number of processors 1503 in the execution device 1500 can be one or more, one processor is taken as an example in Figure 15) , wherein the processor 1503 may include an application processor 15031 and a communication processor 15032. In some embodiments of the present application, the receiver 1501, the transmitter 1502, the processor 1503, and the memory 1504 may be connected through a bus or other means.
存储器1504可以包括只读存储器和随机存取存储器,并向处理器1503提供指令和数据。存储器1504的一部分还可以包括非易失性随机存取存储器(non-volatile randomaccess memory,NVRAM)。存储器1504存储有处理器和操作指令、可执行模块或者数据结构,或者它们的子集,或者它们的扩展集,其中,操作指令可包括各种操作指令,用于实现各种操作。Memory 1504 may include read-only memory and random access memory and provides instructions and data to processor 1503 . A portion of memory 1504 may also include non-volatile random access memory (NVRAM). The memory 1504 stores processor and operating instructions, executable modules or data structures, or a subset thereof, or an extended set thereof, where the operating instructions may include various operating instructions for implementing various operations.
处理器1503控制执行设备的操作。具体的应用中,执行设备的各个组件通过总线系统耦合在一起,其中总线系统除包括数据总线之外,还可以包括电源总线、控制总线和状态信号总线等。但是为了清楚说明起见,在图中将各种总线都称为总线系统。The processor 1503 controls the execution of operations of the device. In specific applications, various components of the execution device are coupled together through a bus system. In addition to the data bus, the bus system may also include a power bus, a control bus, a status signal bus, etc. However, for the sake of clarity, various buses are called bus systems in the figure.
上述本申请实施例揭示的方法可以应用于处理器1503中,或者由处理器1503实现。处理器1503可以是一种集成电路芯片,具有信号的处理能力。在实现过程中,上述方法的各步骤可以通过处理器1503中的硬件的集成逻辑电路或者软件形式的指令完成。上述的处理器1503可以是通用处理器、数字信号处理器(digital signal processing,DSP)、微处理器或微控制器,还可进一步包括专用集成电路(application specific integratedcircuit,ASIC)、现场可编程门阵列(field-programmable gate array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。该处理器1503可以实现或者执行本申请实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。结合本申请实施例所公开的方法的步骤可以直接体现为硬件译码处理器执行完成,或者用译码处理器中的硬件及软件模块组合执行完成。软件模块可以位于随机存储器,闪存、只读存储器,可编程只读存储器或者电可擦写可编程存储器、寄存器等本领域成熟的存储介质中。该存储介质位于存储器1504,处理器1503读取存储器1504中的信息,结合其硬件完成上述方法的步骤。The methods disclosed in the above embodiments of the present application can be applied to the processor 1503 or implemented by the processor 1503. The processor 1503 may be an integrated circuit chip with signal processing capabilities. During the implementation process, each step of the above method can be completed by instructions in the form of hardware integrated logic circuits or software in the processor 1503 . The above-mentioned processor 1503 may be a general-purpose processor, a digital signal processor (DSP), a microprocessor or a microcontroller, and may further include an application specific integrated circuit (ASIC) or a field programmable gate. Array (field-programmable gate array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The processor 1503 can implement or execute each method, step and logical block diagram disclosed in the embodiment of this application. A general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present application can be directly implemented by a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software module can be located in random access memory, flash memory, read-only memory, programmable read-only memory or electrically erasable programmable memory, registers and other mature storage media in this field. The storage medium is located in the memory 1504. The processor 1503 reads the information in the memory 1504 and completes the steps of the above method in combination with its hardware.
接收器1501可用于接收输入的数字或字符信息,以及产生与执行设备的相关设置以及功能控制有关的信号输入。发射器1502可用于通过第一接口输出数字或字符信息;发射器1502还可用于通过第一接口向磁盘组发送指令,以修改磁盘组中的数据;发射器1502还可以包括显示屏等显示设备。The receiver 1501 may be configured to receive input numeric or character information and generate signal inputs related to performing relevant settings and functional controls of the device. The transmitter 1502 can be used to output numeric or character information through the first interface; the transmitter 1502 can also be used to send instructions to the disk group through the first interface to modify the data in the disk group; the transmitter 1502 can also include a display device such as a display screen .
本申请实施例中,在一种情况下,处理器1503,用于通过图5对应实施例中的目标模型,从目标图像中获取目标文本。In the embodiment of the present application, in one case, the processor 1503 is configured to obtain the target text from the target image through the target model in the corresponding embodiment of FIG. 5 .
本申请实施例还涉及一种训练设备,图16为本申请实施例提供的训练设备的一个结构示意图。如图16所示,训练设备1600由一个或多个服务器实现,训练设备1600可因配置或性能不同而产生比较大的差异,可以包括一个或一个以上中央处理器(centralprocessing units,CPU)1616(例如,一个或一个以上处理器)和存储器1632,一个或一个以上存储应用程序1642或数据1644的存储介质1630(例如一个或一个以上海量存储设备)。其中,存储器1632和存储介质1630可以是短暂存储或持久存储。存储在存储介质1630的程序可以包括一个或一个以上模块(图示没标出),每个模块可以包括对训练设备中的一系列指令操作。更进一步地,中央处理器1616可以设置为与存储介质1630通信,在训练设备1600上执行存储介质1630中的一系列指令操作。The embodiment of the present application also relates to a training device. Figure 16 is a schematic structural diagram of the training device provided by the embodiment of the present application. As shown in Figure 16, the training device 1600 is implemented by one or more servers. The training device 1600 may vary greatly due to different configurations or performance, and may include one or more central processing units (CPUs) 1616 ( For example, one or more processors) and memory 1632, one or more storage media 1630 (eg, one or more mass storage devices) storing applications 1642 or data 1644. Among them, the memory 1632 and the storage medium 1630 may be short-term storage or persistent storage. The program stored in the storage medium 1630 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the training device. Furthermore, the central processor 1616 may be configured to communicate with the storage medium 1630 and execute a series of instruction operations in the storage medium 1630 on the training device 1600 .
训练设备1600还可以包括一个或一个以上电源1626,一个或一个以上有线或无线网络接口1650,一个或一个以上输入输出接口1658;或,一个或一个以上操作系统1641,例如Windows ServerTM,Mac OS XTM,UnixTM,LinuxTM,FreeBSDTM等等。The training device 1600 may also include one or more power supplies 1626, one or more wired or wireless network interfaces 1650, one or more input and output interfaces 1658; or, one or more operating systems 1641, such as Windows ServerTM, Mac OS XTM , UnixTM, LinuxTM, FreeBSDTM and so on.
具体的,训练设备可以执行图12对应实施例中的模型训练方法,从而得到目标模型。Specifically, the training device can execute the model training method in the corresponding embodiment of Figure 12 to obtain the target model.
本申请实施例还涉及一种计算机存储介质,该计算机可读存储介质中存储有用于进行信号处理的程序,当其在计算机上运行时,使得计算机执行如前述执行设备所执行的步骤,或者,使得计算机执行如前述训练设备所执行的步骤。Embodiments of the present application also relate to a computer storage medium. The computer-readable storage medium stores a program for performing signal processing. When the program is run on a computer, it causes the computer to perform the steps performed by the aforementioned execution device, or, The computer is caused to perform the steps performed by the aforementioned training device.
本申请实施例还涉及一种计算机程序产品,该计算机程序产品存储有指令,该指令在由计算机执行时使得计算机执行如前述执行设备所执行的步骤,或者,使得计算机执行如前述训练设备所执行的步骤。Embodiments of the present application also relate to a computer program product that stores instructions that, when executed by a computer, cause the computer to perform the steps performed by the foregoing execution device, or cause the computer to perform the steps performed by the foregoing training device. A step of.
本申请实施例提供的执行设备、训练设备或终端设备具体可以为芯片,芯片包括:处理单元和通信单元,所述处理单元例如可以是处理器,所述通信单元例如可以是输入/输出接口、管脚或电路等。该处理单元可执行存储单元存储的计算机执行指令,以使执行设备内的芯片执行上述实施例描述的数据处理方法,或者,以使训练设备内的芯片执行上述实施例描述的数据处理方法。可选地,所述存储单元为所述芯片内的存储单元,如寄存器、缓存等,所述存储单元还可以是所述无线接入设备端内的位于所述芯片外部的存储单元,如只读存储器(read-only memory,ROM)或可存储静态信息和指令的其他类型的静态存储设备,随机存取存储器(random access memory,RAM)等。The execution device, training device or terminal device provided by the embodiment of the present application may specifically be a chip. The chip includes: a processing unit and a communication unit. The processing unit may be, for example, a processor. The communication unit may be, for example, an input/output interface. Pins or circuits, etc. The processing unit can execute the computer execution instructions stored in the storage unit, so that the chip in the execution device executes the data processing method described in the above embodiment, or so that the chip in the training device executes the data processing method described in the above embodiment. Optionally, the storage unit is a storage unit within the chip, such as a register, cache, etc. The storage unit may also be a storage unit located outside the chip in the wireless access device, such as Read-only memory (ROM) or other types of static storage devices that can store static information and instructions, random access memory (random access memory, RAM), etc.
具体的,请参阅图17,图17为本申请实施例提供的芯片的一个结构示意图,所述芯片可以表现为神经网络处理器NPU 1700,NPU 1700作为协处理器挂载到主CPU(Host CPU)上,由Host CPU分配任务。NPU的核心部分为运算电路1703,通过控制器1704控制运算电路1703提取存储器中的矩阵数据并进行乘法运算。Specifically, please refer to Figure 17. Figure 17 is a schematic structural diagram of a chip provided by an embodiment of the present application. The chip can be represented as a neural network processor NPU 1700. The NPU 1700 serves as a co-processor and is mounted to the Host CPU. ), the Host CPU allocates tasks. The core part of the NPU is the arithmetic circuit 1703. The arithmetic circuit 1703 is controlled by the controller 1704 to extract the matrix data in the memory and perform multiplication operations.
在一些实现中,运算电路1703内部包括多个处理单元(Process Engine,PE)。在一些实现中,运算电路1703是二维脉动阵列。运算电路1703还可以是一维脉动阵列或者能够执行例如乘法和加法这样的数学运算的其它电子线路。在一些实现中,运算电路1703是通用的矩阵处理器。In some implementations, the computing circuit 1703 internally includes multiple processing units (Process Engine, PE). In some implementations, arithmetic circuit 1703 is a two-dimensional systolic array. The arithmetic circuit 1703 may also be a one-dimensional systolic array or other electronic circuit capable of performing mathematical operations such as multiplication and addition. In some implementations, arithmetic circuit 1703 is a general-purpose matrix processor.
举例来说,假设有输入矩阵A,权重矩阵B,输出矩阵C。运算电路从权重存储器1702中取矩阵B相应的数据,并缓存在运算电路中每一个PE上。运算电路从输入存储器1701中取矩阵A数据与矩阵B进行矩阵运算,得到的矩阵的部分结果或最终结果,保存在累加器(accumulator)1708中。For example, assume there is an input matrix A, a weight matrix B, and an output matrix C. The arithmetic circuit obtains the corresponding data of matrix B from the weight memory 1702 and caches it on each PE in the arithmetic circuit. The operation circuit takes matrix A data and matrix B from the input memory 1701 to perform matrix operations, and the partial result or final result of the matrix is stored in an accumulator (accumulator) 1708 .
统一存储器1706用于存放输入数据以及输出数据。权重数据直接通过存储单元访问控制器(Direct Memory Access Controller,DMAC)1705,DMAC被搬运到权重存储器1702中。输入数据也通过DMAC被搬运到统一存储器1706中。The unified memory 1706 is used to store input data and output data. The weight data directly passes through the storage unit access controller (Direct Memory Access Controller, DMAC) 1705, and the DMAC is transferred to the weight memory 1702. Input data is also transferred to unified memory 1706 via DMAC.
BIU为Bus Interface Unit即,总线接口单元1717,用于AXI总线与DMAC和取指存储器(Instruction Fetch Buffer,IFB)1709的交互。BIU is the Bus Interface Unit, that is, the bus interface unit 1717, which is used for the interaction between the AXI bus and the DMAC and the Instruction Fetch Buffer (IFB) 1709.
总线接口单元1717(Bus Interface Unit,简称BIU),用于取指存储器1709从外部存储器获取指令,还用于存储单元访问控制器1705从外部存储器获取输入矩阵A或者权重矩阵B的原数据。The Bus Interface Unit 1717 (BIU for short) is used to fetch the memory 1709 to obtain instructions from the external memory, and is also used for the storage unit access controller 1705 to obtain the original data of the input matrix A or the weight matrix B from the external memory.
DMAC主要用于将外部存储器DDR中的输入数据搬运到统一存储器1706或将权重数据搬运到权重存储器1702中或将输入数据数据搬运到输入存储器1701中。DMAC is mainly used to transfer the input data in the external memory DDR to the unified memory 1706 or the weight data to the weight memory 1702 or the input data to the input memory 1701 .
向量计算单元1707包括多个运算处理单元,在需要的情况下,对运算电路1703的输出做进一步处理,如向量乘,向量加,指数运算,对数运算,大小比较等等。主要用于神经网络中非卷积/全连接层网络计算,如Batch Normalization(批归一化),像素级求和,对预测标签平面进行上采样等。The vector calculation unit 1707 includes multiple arithmetic processing units. If necessary, the output of the arithmetic circuit 1703 is further processed, such as vector multiplication, vector addition, exponential operation, logarithmic operation, size comparison, etc. It is mainly used for non-convolutional/fully connected layer network calculations in neural networks, such as Batch Normalization, pixel-level summation, upsampling of the predicted label plane, etc.
在一些实现中,向量计算单元1707能将经处理的输出的向量存储到统一存储器1706。例如,向量计算单元1707可以将线性函数;或,非线性函数应用到运算电路1703的输出,例如对卷积层提取的预测标签平面进行线性插值,再例如累加值的向量,用以生成激活值。在一些实现中,向量计算单元1707生成归一化的值、像素级求和的值,或二者均有。在一些实现中,处理过的输出的向量能够用作到运算电路1703的激活输入,例如用于在神经网络中的后续层中的使用。In some implementations, vector calculation unit 1707 can store the processed output vectors to unified memory 1706 . For example, the vector calculation unit 1707 can apply a linear function; or a nonlinear function to the output of the operation circuit 1703, such as linear interpolation on the prediction label plane extracted by the convolution layer, or a vector of accumulated values, to generate an activation value. . In some implementations, vector calculation unit 1707 generates normalized values, pixel-wise summed values, or both. In some implementations, the processed output vector can be used as an activation input to the arithmetic circuit 1703, such as for use in a subsequent layer in a neural network.
控制器1704连接的取指存储器(instruction fetch buffer)1709,用于存储控制器1704使用的指令;The instruction fetch buffer 1709 connected to the controller 1704 is used to store instructions used by the controller 1704;
统一存储器1706,输入存储器1701,权重存储器1702以及取指存储器1709均为On-Chip存储器。外部存储器私有于该NPU硬件架构。The unified memory 1706, the input memory 1701, the weight memory 1702 and the fetch memory 1709 are all On-Chip memories. External memory is private to the NPU hardware architecture.
其中,上述任一处提到的处理器,可以是一个通用中央处理器,微处理器,ASIC,或一个或多个用于控制上述程序执行的集成电路。The processor mentioned in any of the above places can be a general central processing unit, a microprocessor, an ASIC, or one or more integrated circuits used to control the execution of the above programs.
另外需说明的是,以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。另外,本申请提供的装置实施例附图中,模块之间的连接关系表示它们之间具有通信连接,具体可以实现为一条或多条通信总线或信号线。In addition, it should be noted that the device embodiments described above are only illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physically separate. The physical unit can be located in one place, or it can be distributed across multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. In addition, in the drawings of the device embodiments provided in this application, the connection relationship between modules indicates that there are communication connections between them, which can be specifically implemented as one or more communication buses or signal lines.
通过以上的实施方式的描述,所属领域的技术人员可以清楚地了解到本申请可借助软件加必需的通用硬件的方式来实现,当然也可以通过专用硬件包括专用集成电路、专用CPU、专用存储器、专用元器件等来实现。一般情况下,凡由计算机程序完成的功能都可以很容易地用相应的硬件来实现,而且,用来实现同一功能的具体硬件结构也可以是多种多样的,例如模拟电路、数字电路或专用电路等。但是,对本申请而言更多情况下软件程序实现是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在可读取的存储介质中,如计算机的软盘、U盘、移动硬盘、ROM、RAM、磁碟或者光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,训练设备,或者网络设备等)执行本申请各个实施例所述的方法。Through the above description of the embodiments, those skilled in the art can clearly understand that the present application can be implemented by software plus necessary general hardware. Of course, it can also be implemented by dedicated hardware including dedicated integrated circuits, dedicated CPUs, dedicated memories, Special components, etc. to achieve. In general, all functions performed by computer programs can be easily implemented with corresponding hardware. Moreover, the specific hardware structures used to implement the same function can also be diverse, such as analog circuits, digital circuits or special-purpose circuits. circuit etc. However, for this application, software program implementation is a better implementation in most cases. Based on this understanding, the technical solution of the present application can be embodied in the form of a software product in essence or that contributes to the existing technology. The computer software product is stored in a readable storage medium, such as a computer floppy disk. , U disk, mobile hard disk, ROM, RAM, magnetic disk or optical disk, etc., including several instructions to cause a computer device (which can be a personal computer, training device, or network device, etc.) to execute the steps described in various embodiments of this application. method.
在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it may be implemented in whole or in part in the form of a computer program product.
所述计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行所述计算机程序指令时,全部或部分地产生按照本申请实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、训练设备或数据中心通过有线(例如同轴电缆、光纤、数字用户线(DSL))或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、训练设备或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存储的任何可用介质或者是包含一个或多个可用介质集成的训练设备、数据中心等数据存储设备。所述可用介质可以是磁性介质,(例如,软盘、硬盘、磁带)、光介质(例如,DVD)、或者半导体介质(例如固态硬盘(Solid State Disk,SSD))等。The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present application are generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in or transmitted from one computer-readable storage medium to another, for example, the computer instructions may be transferred from a website, computer, training device, or data The center transmits to another website site, computer, training equipment or data center through wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store, or a data storage device such as a training device or a data center integrated with one or more available media. The available media may be magnetic media (eg, floppy disk, hard disk, magnetic tape), optical media (eg, DVD), or semiconductor media (eg, solid state disk (Solid State Disk, SSD)), etc.
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202310488188.8ACN116758572A (en) | 2023-04-28 | 2023-04-28 | Text acquisition method and related equipment thereof |
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202310488188.8ACN116758572A (en) | 2023-04-28 | 2023-04-28 | Text acquisition method and related equipment thereof |
| Publication Number | Publication Date |
|---|---|
| CN116758572Atrue CN116758572A (en) | 2023-09-15 |
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202310488188.8APendingCN116758572A (en) | 2023-04-28 | 2023-04-28 | Text acquisition method and related equipment thereof |
| Country | Link |
|---|---|
| CN (1) | CN116758572A (en) |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| WO2012043541A1 (en)* | 2010-09-30 | 2012-04-05 | シャープ株式会社 | Prediction vector generation method, image encoding method, image decoding method, prediction vector generation device, image encoding device, image decoding device, prediction vector generation program, image encoding program, and image decoding program |
| CN114399629A (en)* | 2021-12-22 | 2022-04-26 | 北京沃东天骏信息技术有限公司 | A target detection model training method, target detection method and device |
| CN114639096A (en)* | 2022-04-22 | 2022-06-17 | 深圳市星桐科技有限公司 | Text recognition method and device, electronic equipment and storage medium |
| CN114758342A (en)* | 2022-04-19 | 2022-07-15 | 北京字节跳动网络技术有限公司 | Text recognition method, device, medium and electronic equipment |
| CN114972823A (en)* | 2022-06-14 | 2022-08-30 | 北京有竹居网络技术有限公司 | Data processing method, apparatus, equipment and computer medium |
| CN115631498A (en)* | 2022-11-03 | 2023-01-20 | 中国农业银行股份有限公司 | A text position determination method, device, electronic equipment and storage medium |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| WO2012043541A1 (en)* | 2010-09-30 | 2012-04-05 | シャープ株式会社 | Prediction vector generation method, image encoding method, image decoding method, prediction vector generation device, image encoding device, image decoding device, prediction vector generation program, image encoding program, and image decoding program |
| CN114399629A (en)* | 2021-12-22 | 2022-04-26 | 北京沃东天骏信息技术有限公司 | A target detection model training method, target detection method and device |
| CN114758342A (en)* | 2022-04-19 | 2022-07-15 | 北京字节跳动网络技术有限公司 | Text recognition method, device, medium and electronic equipment |
| CN114639096A (en)* | 2022-04-22 | 2022-06-17 | 深圳市星桐科技有限公司 | Text recognition method and device, electronic equipment and storage medium |
| CN114972823A (en)* | 2022-06-14 | 2022-08-30 | 北京有竹居网络技术有限公司 | Data processing method, apparatus, equipment and computer medium |
| CN115631498A (en)* | 2022-11-03 | 2023-01-20 | 中国农业银行股份有限公司 | A text position determination method, device, electronic equipment and storage medium |
| Title |
|---|
| WX61DE: "目标检测算法之Faster-RCNN", Retrieved from the Internet <URL:https://blog.51cto.com/u_15490502/5218646>* |
| Publication | Publication Date | Title |
|---|---|---|
| CN113065633B (en) | Model training method and associated equipment | |
| CN113627422A (en) | Image classification method and related equipment thereof | |
| WO2022111387A1 (en) | Data processing method and related apparatus | |
| CN113627421B (en) | An image processing method, a model training method and related equipment | |
| CN115238909A (en) | Data value evaluation method based on federal learning and related equipment thereof | |
| EP4617909A1 (en) | Summary generation method and related device | |
| CN116312489A (en) | A kind of model training method and related equipment | |
| WO2023197857A1 (en) | Model partitioning method and related device thereof | |
| WO2024140630A1 (en) | Model training method and related device | |
| WO2024179485A1 (en) | Image processing method and related device thereof | |
| CN117173626A (en) | A target detection method and related equipment | |
| CN117011620A (en) | Target detection method and related equipment thereof | |
| CN116739154A (en) | Fault prediction method and related equipment thereof | |
| CN115712828A (en) | Image classification method and related equipment thereof | |
| WO2023185541A1 (en) | Model training method and related device | |
| CN116259311A (en) | Voice processing method and related equipment thereof | |
| CN115292583A (en) | Project recommendation method and related equipment thereof | |
| WO2024260361A1 (en) | Table recognition method and related device therefor | |
| WO2024235107A1 (en) | Object model rotation method and related device thereof | |
| WO2024239927A1 (en) | Model training method and related device | |
| WO2024199404A1 (en) | Consumption prediction method and related device | |
| WO2024061123A1 (en) | Image processing method and image processing related device | |
| WO2024046144A1 (en) | Video processing method and related device thereof | |
| CN117149034A (en) | Image processing method and related equipment thereof | |
| CN117056589A (en) | Article recommendation method and related equipment thereof |
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination |