Training method and device for image description sentence generation module, and electronic device
By obtaining image feature labels and probability vectors, generating feature information and conducting generative model training, the problem of the impact of noise data in image description is solved, and the accuracy of image description and the quality of semantic description are improved.
Patent Information
- Application Number
- CN202210028541.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-11
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2042-01-11
AI Technical Summary
Image features in existing image description methods often contain noise data, resulting in uncertainty in feature decoding and reduced image description accuracy.
By obtaining image feature labels and probability vectors, feature information is generated, and a generative model is used for training. Importance analysis of feature labels and error gradient backpropagation are introduced to optimize the sentence generation module.
It improves the accuracy of image description sentence generation, effectively filters out non-important information in images, and improves the quality of semantic description.
Smart Images

Figure CN114358203B
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a training method and device for an image description sentence generation module, and an electronic device. Background Art
[0002] Image caption, that is, generating natural language sentences to describe images based on image content, can be widely used in educational scenarios such as picture description. Most current image captioning methods extract image features from images through image feature extraction models such as ImageNet, and then input the image features into a recurrent neural network for decoding to obtain a target description sentence sequence. However, in practice, it is found that image features usually contain noise data, such as information irrelevant to the image subject, half a face, or a messy background. These noise data increase the uncertainty of feature decoding in existing methods and reduce the accuracy of image description. Summary of the invention
[0003] The present application provides a training method and device for an image description sentence generation module, and an electronic device, the main purpose of which is to improve the accuracy of image description sentence generation.
[0004] To achieve the above-mentioned purpose, the embodiment of the present application provides a training method for an image description sentence generation module, the method comprising:
[0005] Acquire a first sample image and a first description statement of the first sample image;
[0006] Inputting the first sample image into a pre-trained prediction module for label recognition to obtain at least one first feature label and a first probability vector corresponding to the first feature label;
[0007] Acquire a label vector of the first feature label, and generate feature information of the first feature label according to the label vector of the first feature label and the first probability vector;
[0008] The generative model is trained according to the feature information and the first description sentence to obtain a sentence generation module.
[0009] To achieve the above purpose, the present application also proposes a training device for an image description sentence generation module, the device comprising:
[0010] An acquisition module, used for acquiring a first sample image and a first description statement of the first sample image;
[0011] A recognition module, configured to input the first sample image into a pre-trained prediction module for label recognition, and obtain at least one first feature label and a first probability vector corresponding to the first feature label;
[0012] The acquisition module is further used to acquire a label vector of the first feature label;
[0013] A generating module, configured to generate feature information of the first feature label according to the label vector of the first feature label and the first probability vector;
[0014] A training module is used to train a generative model according to the feature information and the first description sentence to obtain a sentence generation module.
[0015] To achieve the above objectives, an embodiment of the present application further proposes an electronic device, which includes a memory and a processor, wherein a program is stored in the memory, and the program implements the steps of the above method when executed by the processor.
[0016] To achieve the above objectives, the present application provides a storage medium for computer-readable storage, wherein the storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of the aforementioned method.
[0017] The training method, device, and electronic device of the image description sentence generation module proposed in the present application can input the first sample image into the trained prediction module for label recognition in the module training stage to obtain at least one first feature label and the first probability vector of the first feature label, so as to realize the labeling and probability analysis of the content of the first sample image. Afterwards, according to the label vector and the first probability vector of each first feature label, the feature information corresponding to the first feature label is generated for the training of the sentence generation module, so that the label features of the feature label and the probability of its occurrence in the first sample image can be integrated, which not only approximates the probability distribution of each feature label, but also enables the sentence generation module to introduce the importance analysis of the feature label while performing semantic description learning, so as to filter out the non-important information in the image in a targeted manner, and can also perform gradient back-transmission on the error amount based on the differentiability of the label feature information to update the module parameters, so as to achieve a better training effect, and thus is conducive to improving the accuracy of image description sentence generation. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 is a structural block diagram of an electronic device used in an embodiment of the present application;
[0019] Figure 2 is a flowchart of a training method for an image description sentence generation module provided in Example 1 of the present application;
[0020] Figure 3 is a flowchart of a training method for an image description sentence generation module provided in Embodiment 2 of the present application;
[0021] Figure 4 It is a structural block diagram of a training device for an image description sentence generation module used in an embodiment of the present application. DETAILED DESCRIPTION
[0022] It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0023] In the subsequent description, the suffixes such as "module", "component" or "unit" used to represent elements are only used to facilitate the description of the present application, and have no special meanings. Therefore, "module", "component" or "unit" can be used in a mixed manner.
[0024] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Artificial Intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. Among them, the basic technologies of artificial intelligence generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc., while artificial intelligence software technology mainly includes computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology and machine learning / deep learning and other major directions.
[0025] The present application provides a training method for an image description sentence generation module, which is applied to an electronic device. Figure 1 As shown, Figure 1 It is a structural block diagram of an electronic device used in an embodiment of the present application.
[0026] In this embodiment, the electronic device may be a terminal device with computing functions, such as a server, a smart phone, a tablet computer, a portable computer, or a desktop computer.
[0027] The electronic device includes a memory 11 , a processor 12 , a network interface 13 and a data bus 14 .
[0028] The memory 11 includes at least one type of readable storage medium, and at least one type of readable storage medium may be a non-volatile storage medium such as a flash memory, a hard disk, a multimedia card, a card-type memory, etc. In some embodiments, the readable storage medium may be an internal storage unit of an electronic device, such as a hard disk of the electronic device. In other embodiments, the readable storage medium may also be an external memory of the electronic device, such as a plug-in hard disk equipped on the electronic device, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, D) card, a flash card (Flash Card), etc.
[0029] In this embodiment, the readable storage medium of the memory 11 is generally used to store the image description sentence generation program 10 installed in the electronic device, various sample sets and pre-trained models, etc. The memory 11 can also be used to temporarily store data that has been output or is to be output.
[0030] In some embodiments, the processor 12 may be a central processing unit (CPU), a microprocessor or other data processing chip, and is used to run program codes stored in the memory 11 or process data, such as executing an image description statement generation program.
[0031] The network interface 13 may optionally include a standard wired interface, a wireless interface (such as a WI-FI interface), and is generally used to establish a communication connection between the electronic device and other electronic devices.
[0032] The data bus 14 is used to realize the connection and communication between these components.
[0033] Optionally, the electronic device may further include a user interface, which may include an input unit such as a keyboard, a voice input device such as a microphone and other devices with voice recognition function, a voice output device such as a speaker, headphones, etc. Optionally, the user interface may also include a standard wired interface or a wireless interface.
[0034] Optionally, the electronic device may further include a display, which may also be referred to as a display screen or a display unit. In some embodiments, it may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an organic light-emitting diode (OLED) touch device. The display is used to display information processed in the electronic device and to display a visual user interface.
[0035] Optionally, the electronic device further includes a touch sensor. The area provided by the touch sensor for the user to perform a touch operation is called a touch control area. In addition, the touch sensor described here may be a resistive touch sensor, a capacitive touch sensor, etc. Moreover, the touch sensor includes not only a contact touch sensor, but also a proximity touch sensor, etc. In addition, the touch sensor may be a single sensor or a plurality of sensors arranged in an array, for example.
[0036] In addition, the area of the display of the electronic device can be the same as or different from the area of the touch sensor. Optionally, the display and the touch sensor are stacked to form a touch display screen. The device detects a touch operation triggered by a user based on the touch display screen.
[0037] The following is a detailed description of a training method for an image description sentence generation module disclosed in an embodiment of the present application.
[0038] Embodiment 1
[0039] like Figure 2 As shown, Figure 2 : is a flowchart of the training method of the image description sentence generation module provided in the first embodiment of the present application. Figure 1 In the device embodiment shown, the processor 12 implements the following steps when executing the image description sentence generation program 10 stored in the memory 11:
[0040] Step S200: Acquire a first sample image and a first description statement of the first sample image.
[0041] In an embodiment of the present application, the number of first sample images may be multiple. Specifically, the first sample image may be image data obtained from the Internet using a search engine or crawler software, or image data retrieved from a chat record of a social software, or image data uploaded in a functional module of a user interface (such as a picture upload bar), without limitation. Correspondingly, the first description statement may be a natural language statement that artificially describes the first sample image, or text information obtained by using image recognition technology to identify the text content of the first sample image, or related description information obtained by searching the image using image search technology (such as searching with an image), without limitation. For example, for a first sample image containing an elephant, the sky, and grass, the first description statement is "the sky is clear and the elephant is walking on the grass."
[0042] In some optional implementations, step S200 may specifically be: obtaining an original image, performing data enhancement processing on the original image, and obtaining a processed original image, wherein the data enhancement processing at least includes image editing processing and random Gaussian blur processing, and the image editing processing includes at least one of the following: rotation, scaling, shifting, and cropping. Afterwards, the original image and the processed original image are taken as the first sample image, so the number of sample images is expanded through a combination of multiple incremental processing methods, which is conducive to achieving a better data enhancement effect.
[0043] Step S210: inputting the first sample image into a pre-trained prediction module for label recognition to obtain at least one first feature label and a first probability vector corresponding to the first feature label.
[0044] In the embodiment of the present application, the prediction module can adopt a neural network model (such as a convolutional neural network model and a recurrent neural network model, etc.), a Bayesian model or an attention model, etc., without limitation. The first probability vector corresponding to the first feature label is a vector representation of the probability of identifying the first feature label from the first sample image.
[0045] Specifically, in an optional implementation, the training step of the prediction module may include: obtaining multiple sample data, the sample data includes a second sample image and a sample label corresponding to the second sample image, the second sample image includes multiple target segmentation areas and example labels annotated for the target segmentation areas. The multiple sample data are divided into a training set of a first proportion (e.g., 60%) and a verification set of a second proportion (e.g., 40%). Based on this, the training set can be used to train a convolutional neural network to obtain a prediction module, and the verification set can be used to verify the accuracy of the prediction module. If the accuracy is greater than or equal to the preset accuracy, the training ends, or, if the accuracy is less than the preset accuracy, the number of sample data is increased and the training step of the prediction module is re-executed.
[0046] For example, if the second sample image is a beach picture, the sample label for the second sample image can be "beach", and by segmenting the beach picture, the seawater area and the beach area can be obtained, so the second sample image also includes two sample labels, namely seawater and beach. It can be seen that by combining the multi-instance learning method and segmenting the sample image into different content areas, the prediction module can be trained to perform label recognition on the specific image content of multiple content areas in the sample image, and further determine the label classification of the entire sample image, which is conducive to improving the classification performance of the prediction module and the accuracy of label recognition.
[0047] Optionally, the prediction module can adopt the VGG model, and the prediction module can include M convolutional layers, N fully connected layers and softmax classification layers, where M and N are both positive integers. The image is input into the prediction module, and the image is sequentially feature extracted and classified through M convolutional layers, N fully connected layers and softmax classification layers to obtain multiple probability vectors output by the softmax classification layer. More specifically, the prediction module can adopt the VGG16 model, which includes 13 convolutional layers, 3 fully connected layers and a softmax classification layer.
[0048] Furthermore, in some implementations, expected data such as Chinese-English dictionaries, synonym dictionaries, and other related subject dictionaries can be taken as text expansion corpus data, and then the text expansion corpus data and multiple sample data are used to train the prediction module to achieve noun expansion of the label text. In other implementations, the second sample image can also be subjected to data enhancement processing and label re-labeling to obtain multiple processed sample data, and then the multiple sample data and the processed sample data are divided into a first proportion of training sets and a second proportion of verification sets, thereby increasing the number of samples for training the prediction module and improving the reliability of label recognition of the prediction module. Among them, the data enhancement processing includes at least image editing processing and random Gaussian blur processing, and the image editing processing includes at least one of the following: rotation, scaling, shifting and cropping, so a better data enhancement effect is achieved through a combination of multiple incremental processing.
[0049] In another optional implementation, the training step of the prediction module may also include: obtaining multiple sample data, the sample data including a certain number of positive sample images and negative sample images. Among them, the positive sample image is marked as having a scene label, and the negative sample image is marked as having no scene label. The scene label includes at least one sample label corresponding to the positive sample image, and the positive sample image includes multiple first segmented areas, and the multiple first segmented areas include the segmented areas indicated by the scene label, such as the first segmented area indicated by the scene label "grass" is the grass area in the positive sample image. The negative sample image includes multiple second segmented areas, and the multiple second segmented areas do not include the segmented areas indicated by the above scene label. Based on this, the positive sample image is added to the training set, and the negative sample image is added to the verification set, so that the training set and the verification set are used to respectively realize the training and verification of the prediction module. It can be seen that under this implementation, there is no need to mark the segmented areas in the sample image one by one, but the prediction module summarizes the characteristic laws of the segmented areas indicated by the scene label during the training process, thereby saving the cost and time of sample image data annotation and improving the editing efficiency of image description data.
[0050] Step S220: Obtain a label vector of the first feature label, and generate feature information of the first feature label according to the label vector of the first feature label and the first probability vector.
[0051] In the embodiment of the present application, specifically, the first feature tag can be encoded using a predetermined encoder to obtain a tag vector of the first feature tag. The encoder can be word2vec, Fast Text or Glove model, etc., which is not limited. In step S220, the feature information generated for the first feature tag has continuous derivability and is used to indicate the importance of the first feature tag.
[0052] In one implementation, the label vector of the first feature label can be directly multiplied by the first probability vector to obtain the feature information of the first feature label. The first probability vector includes the probability value of identifying each first feature label from the first sample image, and the sum of the probability values corresponding to all first feature labels is 1. Exemplarily, for three first feature labels, the corresponding first probability vector W is [0.1, 0.2, 0.7], and the corresponding label vector is [a, b, c]. Then the feature information of these three first feature labels = 0.1a + 0.2b + 0.7c. It can be seen that at this time, the feature information of the first feature label is still a differentiable feature vector, which can not only represent the probability distribution of different feature labels, but also facilitate calculation and model training.
[0053] In another implementation, a sampling method based on gumbel-softmax can also be used to add a random weight value to the first probability vector to obtain a processed first probability vector, and then multiply the processed first probability vector and the label vector of the first feature label to obtain the feature information of the first feature label, thereby sampling the parameters of the discrete distribution by adding constant noise, and getting closer to the true probability distribution. Among them, the random weight value u~specified weight distribution P, the specified weight distribution P can be U(0,1), that is, the random weight value satisfies the uniform distribution on (0,1), and there is no limitation on this. For example, still taking the above three first feature labels as an example, taking the random weight value u=[0.5, 0.6, 0.05], the processed first probability vector W+u=[0.1+0.5, 0.2+0.6, 0.7+0.05]=[0.6, 0.8, 0.75], based on this, the feature information of the above three feature labels=0.6a+0.8b+0.75c.
[0054] Step S230: training the generative model according to the feature information and the first description sentence to obtain a sentence generation module.
[0055] In an embodiment of the present application, the statement generation module may be a single generation module, or may include at least two generation modules, such as a first generation module for label sorting and a second generation module for statement generation, without specific limitation.
[0056] Specifically, in step S230, the feature information of each first sample image can be taken as input data, the first description sentence of the first sample image can be taken as the annotation result of the corresponding input data, the input data is input into the generative model, and then the loss value is calculated for the output of the generative model and the annotation result through the cross entropy loss function, and the parameters of the generative model are adjusted through the back propagation of the loss value, and finally the sentence generation module is obtained. Among them, the sentence generation module can specifically include a BERT model, a hidden Markov model, a naive Bayes model or a Gaussian mixture model, etc., which is not limited to this.
[0057] It can be seen that the prediction module and the sentence generation module can be pre-trained by adopting steps S200 to S230. Optionally, in actual applications, the following steps S240 and S250 can also be implemented by applying the prediction module and the sentence generation module.
[0058] Step S240: Acquire a target image, input the target image into a prediction module for label recognition, and obtain label information of the target image.
[0059] In an embodiment of the present application, the target image is input into the prediction module for label recognition to obtain the label information of the target image, which can be: the target image is input into the prediction module for label recognition to obtain an output matrix, the output matrix includes at least one second feature label output by the prediction module and a second probability vector corresponding to the second feature label. Based on this, the label information of the target image can be determined according to the output matrix and the label vectors of each second feature label; or, k (k is a positive integer) target labels can be directly determined as the label information of the target image according to the second probability vector corresponding to the second feature label, and there is no limitation on this.
[0060] Step S250: input the label information into the sentence generation module to obtain the target description sentence of the target image.
[0061] It can be seen that the implementation of the above method embodiment can integrate the label features of the feature labels and the probability of their occurrence in the first sample image, which can not only approximate the probability distribution of each feature label, but also enable the sentence generation module to introduce the importance analysis of the feature labels while performing semantic description learning, so as to filter out non-important information in the image in a targeted manner, and can also perform gradient backpropagation on the error amount based on the differentiability of the label feature information to update the module parameters, thereby achieving better training results, and therefore helping to improve the accuracy of image description sentence generation.
[0062] Embodiment 2
[0063] like Figure 3 As shown, Figure 3 Flowchart of the training method of the image description sentence generation module provided in the second embodiment of the present application. Figure 1 In the electronic device embodiment shown, the processor 12 implements the following steps when executing the image description sentence generation program 10 stored in the memory 11:
[0064] Step S300: Acquire a first sample image and a first description statement of the first sample image.
[0065] Step S310: inputting the first sample image into a pre-trained prediction module for label recognition to obtain at least one first feature label and a first probability vector corresponding to the first feature label.
[0066] Step S320: Obtain a label vector of the first feature label, and generate feature information of the first feature label according to the label vector of the first feature label and the first probability vector.
[0067] Step S330: training the generative model according to the feature information and the first description sentence to obtain a sentence generation module.
[0068] Step S340: Obtain a target image, input the target image into a prediction module, and obtain an output matrix.
[0069] In the embodiment of the present application, the output matrix includes at least one second feature label identified from the icon image and a second probability vector corresponding to the second feature label.
[0070] Step S350: Calculate the sum of the second probability vectors according to the objective function and at least one second probability vector, and take the k second probability vectors with the largest sum as the target probability vectors.
[0071] The second probability vector corresponding to the second feature label is a vector representation of the probability of identifying the second feature label from the second sample image, k is a positive integer, and k can be manually set and adjusted. Then, the objective function satisfies:
[0072] Among them, i and j are both positive integers, Y ij is the j-th vector data of the i-th second probability vector in the output matrix, f is a summation function (such as norm calculation) specified and adjusted manually, and Si is the summation value of the i-th second probability vector.
[0073] For example, for a target image with the theme of an elephant walking on the grass, the prediction module can identify the feature labels and probability vectors of elephants, chickens, grass, sky, beach and sun from the target image. Substitute the probability vectors of the above feature labels into the target function respectively to obtain the sum value S1 corresponding to the elephant, the sum value S2 corresponding to the chicken, the sum value S3 corresponding to the grass, the sum value S4 corresponding to the sky, the sum value S5 corresponding to the beach and the sum value S6 corresponding to the sun. Assuming that S1>S3>S4>S6>S2>S5, and k is 4, the second probability vectors corresponding to the elephant, grass, sky and sun are taken as the target probability vector.
[0074] It can be seen that by using the objective function to calculate the sum of the second probability vectors, the importance of the corresponding target label can be further analyzed. It can be understood that the smaller the sum value, the lower the importance, and the larger the sum value, the higher the importance. Therefore, sorting and selecting the first k second probability vectors according to the size of the sum value can filter out non-important labels and reduce the interference of image noise data.
[0075] Step S360: Determine k target labels according to the second feature label corresponding to the target probability vector.
[0076] Specifically, the target probability vector can be decoded by a predetermined decoder to obtain the second feature label. It can be understood that the decoder is used in conjunction with the above encoder, so the type of the decoder can also be word2vec, FastText or Glove model, etc., and this is not limited.
[0077] It can be seen that in the actual module usage stage, the most optimized k target labels can be directly screened out according to the output of the prediction module, and the k target labels can be input into the target generation module to obtain the image description information, thereby realizing flexible processing of the output results of the prediction module, thereby meeting the different data requirements of the model usage and training stages respectively.
[0078] Step S370: input k target tags into the first generation module to obtain sentence position information corresponding to the target tags, where the sentence position information is used to indicate the position of the target tag in the sentence.
[0079] Step S380: Generate a tag sequence according to k target tags and the sentence position information corresponding to the target tags.
[0080] For example, assuming that four target tags "elephant", "grass", "sky" and "sun" are input into the first generation module, the sentence position information of the four target tags can be obtained as a position sequence [3, 4, 1, 2], wherein each position information included in the position sequence represents the ranking value of the corresponding target tag, that is, the position information of "elephant" is 3, the position information of "grass" is 4, the position information of "sky" is 1, and the position information of "sun" is 2. Based on this, an ordered tag sequence [sky, sun, elephant, grass] can be generated.
[0081] Step S390: Input the label sequence into the second generation module to obtain a target description statement of the target image.
[0082] Still taking the above label sequence [sky, sun, elephant, grass] as an example, after inputting the label sequence [sky, sun, elephant, grass] into the second generation module, we can get the target description sentence: the sky is clear and the elephant is walking on the grass. In other words, the target description sentence can include two layers of information: image label and image description. The image label is a noun label output by the prediction model based on multi-instance learning, such as sky, elephant and grass, which makes it easier to achieve image classification. The image description is a natural sentence, such as the sky is clear and the elephant is walking on the grass, which makes it easier to achieve image search.
[0083] In the embodiment of the present application, optionally, both the first generation module and the second generation module may include a BERT model, thereby combining the self-attention mechanism of the BERT model to reduce the word distance between input labels, improve the effectiveness of information transfer, and achieve unified input and parallel computing, thereby improving module computing efficiency. It is understandable that the first generation module and the second generation module can be trained based on different parameters and training strategies.
[0084] In some implementations, the first generation module may specifically include a first BERT model, a first fully connected layer, and a first classification layer. In practical applications, k unordered target tags are input into the first BERT model to obtain tag semantic vectors, and then the tag semantic vectors are sequentially input into the first fully connected layer and the first classification layer for tag sorting to obtain the sentence position information of each target tag.
[0085] Similarly, the second generation module may specifically include a second BERT model, a second fully connected layer, and a second classification layer. After the ordered tag sequence is input into the second generation module, the second generation module may predict a suitable target description statement based on the contextual information and semantic features of each target tag in the tag sequence. It is understandable that the target description statement may include tags that do not exist in the tag sequence, or may ignore some tags in the tag sequence, thereby ensuring the fluency and rationality of the target description statement.
[0086] Furthermore, in some implementations, both the first BERT model and the second BERT model can be pre-trained with bidirectional Transformers using a masked language model to generate deep bidirectional language representations. After pre-training, in the subsequent training process of the first generation module, the first generation module can be trained by adjusting the parameters of the first fully connected layer, so there is no need to make specific structural modifications to the first BERT model. In the subsequent training process of the second generation module, the training of the second generation module can be achieved by simultaneously adjusting the parameters of the second BERT model and the second fully connected layer.
[0087] It can be seen that by adopting steps S370 to S390, the target labels are sorted in sequence through the two-level generation module, and the final description sentence is generated based on the ordered label sequence, so that the predicted target description sentence is smoother.
[0088] It can be understood that the specific implementation of steps S300 to S390 in this embodiment can also refer to the description of steps S200 to S250 in the above embodiment 1, and will not be repeated here.
[0089] It can be seen that the implementation of the present method embodiment can merge the label features of the feature labels and their occurrence probabilities in the first sample image, which not only approximates the probability distribution of each feature label, but also enables the sentence generation module to introduce the importance analysis of the feature labels while performing semantic description learning, so as to filter out non-important information in the image in a targeted manner, and can also perform gradient back-propagation of the error amount based on the differentiability of the label feature information to update the module parameters, thereby achieving a better training effect, and thus is conducive to improving the accuracy of image description sentence generation. In addition, the two-level generation modules in the sentence generation module can sequentially realize the sorting of target labels and generate the final description sentence based on the ordered label sequence, so that the predicted target description sentence is smoother.
[0090] The present application also provides a training device for an image description sentence generation module. Figure 4 , Figure 4 1 is a structural block diagram of a training device for an image description sentence generation module used in an embodiment of the present application. Figure 4 As shown, the training device 400 of the image description sentence generation module includes:
[0091] The acquisition module 410 is configured to acquire a first sample image and a first description statement of the first sample image.
[0092] The recognition module 420 is used to input the first sample image into a pre-trained prediction module for label recognition to obtain at least one first feature label and a first probability vector corresponding to the first feature label.
[0093] The acquisition module 410 is further configured to acquire a label vector of the first feature label.
[0094] The generating module 430 is used to generate feature information of the first feature label according to the label vector and the first probability vector of the first feature label.
[0095] The training module 440 is used to train the generative model according to the feature information and the first description sentence to obtain a sentence generation module.
[0096] It should be noted that the specific implementation process of this embodiment can refer to the specific implementation process of the above method embodiment, and will not be repeated here.
[0097] An embodiment of the present application also provides an electronic device, which includes a memory and a processor. The memory stores a program, and when the program is executed by the processor, the training method of the above-mentioned image description sentence generation module is implemented.
[0098] An embodiment of the present application also provides a storage medium for computer-readable storage, wherein the storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the training method of the above-mentioned image description sentence generation module.
[0099] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.
[0100] In hardware implementation, the division between the functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed by several physical components in cooperation. Some physical components or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor or a microprocessor, or implemented as hardware, or implemented as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or non-transitory medium) and a communication medium (or temporary medium). As known to those of ordinary skill in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disk (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. Furthermore, it is well known to those skilled in the art that communication media typically embodies computer readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.
[0101] The preferred embodiments of the present application are described above with reference to the accompanying drawings, but the scope of the present application is not limited thereby. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present application shall be within the scope of the present application.
Claims
1. A method for generating an image description sentence, characterized in that: The method comprises: Acquire a first sample image and a first description statement of the first sample image; Inputting the first sample image into a pre-trained prediction module for label recognition to obtain at least one first feature label and a first probability vector corresponding to the first feature label; Acquire a label vector of the first feature label, and multiply the label vector of the first feature label by the first probability vector to obtain feature information of the first feature label; Training a generative model according to the feature information and the first description sentence to obtain a sentence generation module; Wherein, after the generative model is trained according to the feature information and the first description sentence to obtain a sentence generation module, the method further includes: Acquire a target image, and input the target image into the prediction module for label recognition to obtain label information of the target image; Inputting the label information into the sentence generation module to obtain a target description sentence of the target image; The step of inputting the target image into the prediction module for label recognition to obtain label information of the target image includes: Inputting the target image into the prediction module to obtain an output matrix, wherein the output matrix includes at least one second feature label and a second probability vector corresponding to the second feature label; Calculate the sum of the second probability vectors according to the objective function and at least one of the second probability vectors, and take the k second probability vectors with the largest sum as the target probability vectors, where k is a positive integer; Determine k target labels according to the second feature label corresponding to the target probability vector; Wherein, the objective function satisfies: And= , Where i and j are both positive integers. is the j-th vector data of the ith second probability vector in the output matrix, f is the summation function, and Si is the summation value of the ith second probability vector.
2. The method according to claim 1, characterized in that: The sentence generation module includes a first generation module and a second generation module, and the label information includes at least one target label; The step of inputting the label information into the sentence generating module to obtain a target description sentence of the target image includes: Inputting the at least one target tag into the first generation module to obtain sentence position information corresponding to the target tag, where the sentence position information is used to indicate the position of the target tag in the sentence; Generate a label sequence according to at least one of the target labels and the sentence position information corresponding to the target label; The label sequence is input into the second generation module to obtain a target description statement of the target image.
3. The method according to claim 1 or 2, characterized in that: The training steps of the prediction module include: Acquire a plurality of sample data, wherein the sample data includes a second sample image and a sample label corresponding to the second sample image, wherein the second sample image includes a plurality of target segmentation regions and example labels annotated for the target segmentation regions; Dividing the plurality of sample data into a training set of a first proportion and a validation set of a second proportion; The convolutional neural network is trained using the training set to obtain a prediction module, and the accuracy of the prediction module is verified using the verification set. If the accuracy is greater than or equal to the preset accuracy, the training ends. Alternatively, if the accuracy is less than the preset accuracy, the amount of sample data is increased and the training steps of the prediction module are re-executed.
4. The method according to claim 1 or 2, characterized in that: The obtaining of the first sample image comprises: Get the original image; Performing data enhancement processing on the original image to obtain a processed original image, wherein the data enhancement processing at least includes image editing processing and random Gaussian blur processing, and the image editing processing includes at least one of the following: rotation, scaling, shifting and cropping; The original image and the processed original image are taken as first sample images.
5. A device for generating an image description sentence, characterized in that: The device comprises: An acquisition module, used for acquiring a first sample image and a first description statement of the first sample image; A recognition module, configured to input the first sample image into a pre-trained prediction module for label recognition, and obtain at least one first feature label and a first probability vector corresponding to the first feature label; The acquisition module is further used to acquire a label vector of the first feature label; A generating module, configured to multiply the label vector of the first feature label and the first probability vector to obtain feature information of the first feature label; A training module, used for training a generative model according to the feature information and the first description sentence to obtain a sentence generation module; Wherein, after the generative model is trained according to the feature information and the first description sentence to obtain a sentence generation module, the device is further used to: Acquire a target image, and input the target image into the prediction module for label recognition to obtain label information of the target image; Inputting the label information into the sentence generation module to obtain a target description sentence of the target image; The step of inputting the target image into the prediction module for label recognition to obtain label information of the target image includes: Inputting the target image into the prediction module to obtain an output matrix, wherein the output matrix includes at least one second feature label and a second probability vector corresponding to the second feature label; Calculate the sum of the second probability vectors according to the objective function and at least one of the second probability vectors, and take the k second probability vectors with the largest sum as the target probability vectors, where k is a positive integer; Determine k target labels according to the second feature label corresponding to the target probability vector; Wherein, the objective function satisfies: And= , Where i and j are both positive integers. is the j-th vector data of the ith second probability vector in the output matrix, f is the summation function, and Si is the summation value of the ith second probability vector.
6. An electronic device, characterized in that: The electronic device includes a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for realizing connection and communication between the processor and the memory. When the program is executed by the processor, the steps of the method described in any one of claims 1 to 4 are realized.
7. A storage medium for computer-readable storage, characterized in that: The storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of any one of claims 1 to 4.
Citation Information
Patent Citations
Image description method and device and training method and device of image description model
CN110472688A
Method for realizing smoke-related vehicle anomaly detection based on small data set
CN110929633A
Image processing method and device, computer equipment and storage medium
CN111368127A
Picture description generation method and device and computer readable storage medium
CN111488473A
Image poem description generation method and device, and equipment
CN113010717A
