Image generation text description control method and system
By training the image generation text description model based on the image description of the visual large language model, it solves the accuracy and automatic generation problems of image text description in the existing technology, realizes the function of user-defined categories, and ensures the accuracy and accuracy of text description. Automatically generated.
Patent Information
- Application Number
- CN202410836504.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-26
- Publication Date
- 2024-09-10
AI Technical Summary
Existing technology cannot guarantee the accuracy and automatic generation of appropriate text descriptions for image matching, and lacks the functionality of user-defined categories.
By constraining the visual large language model based on images and image categories, image descriptions are generated, and the image generation text description model is trained to achieve one-click generation of text descriptions and support user-defined categories.
It ensures the accuracy and automatic generation of text descriptions, while allowing users to customize categories and focus on categories that users are interested in.
Smart Images

Figure CN118628829A
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of controlling the generation of text descriptions from images, and in particular, relates to a control method and system for generating text descriptions from images. Background Art
[0002] With the development of technology, general data workers will use search engines to retrieve images and image titles, descriptions, tags, user comments and other text information related to the image content. Manual methods are used to match appropriate text information to images and manually generate text descriptions, which cannot guarantee the accuracy and automatic generation of text descriptions. Summary of the invention
[0003] In view of the above deficiencies in the prior art, the purpose of the invention is to provide a control method and system for generating text descriptions from images, constraining a visual big language model based on images and image categories, and generating image descriptions based on the visual big language model, thereby training the image-to-text description model through image descriptions, so as to generate corresponding text descriptions based on images with one click, thereby ensuring the accuracy and automatic generation of text descriptions. At the same time, category labels are customized to facilitate the addition of user-defined categories, which can pay more attention to categories of interest to users.
[0004] In a first aspect of the present invention, a control method for generating text description from an image is proposed, which is applied to a control scenario of generating text description from an image;
[0005] The control method for generating text description from an image comprises:
[0006] Collect images and label them with category labels;
[0007] Customize based on category labels. In this case, plug-in training customizes categories.
[0008] A visual language model is constrained based on images and image categories, and an image description is generated based on the visual language model; the image categories include general categories and custom categories;
[0009] The image-generated text description model is trained according to the image description, and the image-generated text description model outputs the corresponding text description.
[0010] Furthermore, collecting images and labeling the images with category labels includes:
[0011] Collect images;
[0012] Annotate category labels based on images.
[0013] Furthermore, the customization based on the category label, at this time, the plug-in training custom category includes:
[0014] Get images and corresponding category labels;
[0015] Customize based on category tags and define hobby tags. At this time, plug-in training custom categories.
[0016] Furthermore, the plug-in training custom category includes:
[0017] During the training process, the output of the general category is covered by a mask. At this time, an index list is established, and the elements in it are integers from 0 to 4584. The index in the list is deleted from all the outputs of the model, so that only the custom category remains in the output of the model.
[0018] Furthermore, the plug-in training custom category also includes:
[0019] The custom category also only takes the output of the second dimension and is trained using the multi-category label classification loss BCELoss.
[0020] Furthermore, the visual large language model is constrained based on the image and the image category, and the image description is generated based on the visual large language model; the image category includes a general category and a custom category, including:
[0021] Collect images and image categories;
[0022] Constraining the visual language model based on images and image categories;
[0023] Generate image descriptions based on a large visual language model; image categories include general categories and custom categories.
[0024] Furthermore, the method constrains the visual large language model based on the image and the image category, and generates the image description based on the visual large language model; the image category includes a general category and a custom category, and further includes:
[0025] In the visual large language model, image descriptions are generated based on turn-by-turn question answering.
[0026] Furthermore, the step of training an image-generated text description model according to the image description and outputting a corresponding text description in the image-generated text description model includes:
[0027] Collect image descriptions;
[0028] Train a model to generate text descriptions from images based on image descriptions.
[0029] Furthermore, the step of training the image-generated text description model according to the image description and outputting the corresponding text description in the image-generated text description model further includes:
[0030] The text description model generates the corresponding text description based on the image output.
[0031] In a second aspect of the present invention, a control system for generating text description from an image is proposed, comprising:
[0032] The collection module is used to collect images and annotate category labels for the images;
[0033] Custom module, used for customization based on category labels. In this case, plug-in training is used for custom categories.
[0034] An image description module is used to constrain the visual language model based on images and image categories, and generate image descriptions based on the visual language model; image categories include general categories and custom categories;
[0035] The text description module is used to train the image-generated text description model according to the image description, and output the corresponding text description in the image-generated text description model.
[0036] The beneficial effects of the present invention are as follows:
[0037] The method and device described in the present invention collect images and annotate category labels for the images; customize based on the category labels, at this time, plug-in training custom categories; constrain the visual big language model based on the image and image category, and generate image descriptions based on the visual big language model; the image category includes general categories and custom categories; train the image-generated text description model according to the image description, and output the corresponding text description in the image-generated text description model, at this time, constrain the visual big language model based on the image and image category, and generate the image description based on the visual big language model, so as to train the image-generated text description model through the image description, so as to generate the corresponding text description based on the image with one click, thereby ensuring the accuracy and automatic generation of the text description. At the same time, the category labels are customized so as to add user-defined categories, so as to pay more attention to the categories of interest to the user. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] The accompanying drawings are only used to illustrate specific embodiments and are not considered to limit the present invention. In the entire drawings, the same reference symbols represent the same components. Obviously, the drawings described below are only some embodiments recorded in the embodiments of the present invention. For those of ordinary skill in the art, other drawings can also be obtained based on these drawings.
[0039] Figure 1 is a flow chart of a control method for generating text description from an image in an embodiment of the present invention;
[0040] Figure 2is a flow chart of S12 in the control method for generating text description from an image in an embodiment of the present invention;
[0041] Figure 3 is a flow chart of S13 in the control method for generating text description from an image in an embodiment of the present invention;
[0042] Figure 4 is a flow chart of S14 in the control method for generating text description from an image in an embodiment of the present invention;
[0043] Figure 5 Schematic diagram of the structure of a control system for generating text description from an image in an embodiment of the present invention;
[0044] Figure 6 The figure is a hardware diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0045] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present invention, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. It should be understood that these descriptions are only exemplary and are not intended to limit the scope of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in the field without making creative work should fall within the scope of protection of the present invention.
[0046] Furthermore, in the following description, descriptions of well-known structures and technologies are omitted to avoid unnecessarily obscuring the concepts disclosed in the present invention.
[0047] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the orientation or position relationship indicated by the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inside", "outside", etc. is based on the orientation or position relationship shown in the drawings, which is only for the convenience of describing the present invention and simplifying the description, and does not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation of the present invention. In addition, the terms "first", "second", and "third" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. The terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be a connection between the two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0048] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Instead, they are merely examples of methods and systems consistent with some aspects of the present invention as detailed in the appended claims.
[0049] The present invention proposes a control method and system for generating text description from an image, which defines a control area for generating text description from an image based on a combination of basic attribute labels and real-time location labels, so as to clarify the control area for generating text description from an image, thereby defining a text message sending range for the control area for generating text description from an image, so as to train an image-generated text description model according to the image description, and output a corresponding text description in the image-generated text description model, thereby realizing the accurate sending of emergency text messages and multi-dimensional control of emergency scenarios, and then quickly deploying targeted release of emergency information.
[0050] Method Embodiment
[0051] See also Figures 1 to 6 , a control method for generating text description from an image, applied to a control scenario of generating text description from an image; the control method for generating text description from an image comprises:
[0052] Step S11: Collect images and label the images with category labels;
[0053] Step S12: Customize based on the category label. At this time, the plug-in training customizes the category;
[0054] Step S13: constraining a visual language model based on the image and the image category, and generating an image description based on the visual language model; the image category includes a general category and a custom category;
[0055] Step S14: training an image-generated text description model according to the image description, and outputting a corresponding text description in the image-generated text description model.
[0056] In an embodiment of the present invention, through the method in the embodiment of the present invention, a visual big language model is constrained based on images and image categories, and an image description is generated based on the visual big language model, so that an image generation text description model is trained through image description, so that a corresponding text description can be generated based on the image with one click, thereby ensuring the accuracy and automatic generation of the text description. At the same time, the category labels are customized to add user-defined categories, so that more attention can be paid to the categories of interest to the user.
[0057] In step S11, images are collected and category labels are annotated for the images;
[0058] In the specific implementation process of the present invention, images are collected; category labels are annotated based on the images. At this time, images are collected in a communication network, and integrity checks are performed on the images to facilitate troubleshooting of the integrity of the images, so that they can be annotated based on graphics, thereby ensuring the category labels corresponding to the images. At this time, the category labels can be determined by image recognition.
[0059] In step S12, customization is performed based on the category label. At this time, plug-in training customizes the category;
[0060] In the specific implementation process of the present invention, the specific steps may be:
[0061] S121: Obtain images and corresponding category labels;
[0062] S122: Customize based on category tags and define hobby tags. At this time, the plug-in training customizes the category.
[0063] In an embodiment of the present application, images and corresponding category labels are obtained to facilitate associating the images and the corresponding category labels. At this time, the category labels can be manually adjusted to facilitate customization based on the category labels, and hobby labels are defined, thereby ensuring the input of hobby labels. At this time, plug-in training custom categories are performed.
[0064] At this time, the implementation method is to freeze all the weights of the original RAM model. On the basis of the label-embed of the original RAM, a tensor with a dimension of (number of custom categories, 512) is spliced. This tensor expresses the same category through multiple texts, and finally uses the norm and mean to obtain a 512-dimensional vector corresponding to a category, and stacks the corresponding vectors of multiple categories into this tensor. In the fc layer, modify the original fully connected layer, the output dimension is 2, and one of the outputs is the probability value output of the original RAM predicted category. When training custom categories, freeze the weight tensor corresponding to the first output of the fc layer, and only release the weight for predicting custom categories.
[0065] During the training process, the output of the general category is covered by a mask. At this time, an index list is created, and the elements in the list are integers from 0 to 4584. The index in the list is deleted from all the outputs of the model, so that only the custom category is left in the output of the model. At this time, the custom category also only takes the output of the second dimension and uses the multi-category label classification loss BCELoss for training.
[0066] Optional, FC (Fully Connected Layer): A network structure in a neural network. Its main function is to increase or decrease the dimension of the input feature vector. It is also used in classification tasks to output the number of categories through the fully connected layer. Each value represents the possibility of the corresponding category.
[0067] CLIP (Contrastive Language-Image Pre-Training): A network structure that uses contrastive learning technology to align images and texts. When a single image is inferred, the final result can get scores corresponding to different texts.
[0068] Label-Embed (Label Embeding, text encoding vector): Different text categories are generated into different sentences through different text prefixes and suffixes. Different sentences are then quantified using a tokenizer, and finally a two-dimensional matrix is solved into a vector through the norm and mean.
[0069] BERT (Bidirectional Encoder Representation from Transformers) is a pre-trained language model based on the Transformer architecture. BERT is characterized by bidirectional context modeling and can simultaneously use contextual information to understand the meaning of words.
[0070] RAM (Recognition Anything Model): A model that uses a combination of image feature vectors and text feature vectors to jointly predict the category to which an image belongs. A total of 4585 categories can be predicted.
[0071] In step S13, a visual large language model is constrained based on the image and the image category, and an image description is generated based on the visual large language model; the image category includes a general category and a custom category;
[0072] In the specific implementation process of the present invention, the specific steps may be:
[0073] S131: Collect images and image categories;
[0074] S132: Constraining the visual large language model based on images and image categories;
[0075] S133: Generate image description based on the visual large language model; image categories include general categories and custom categories.
[0076] In an embodiment of the present application, images and image categories are collected to facilitate association between the images and image categories, thereby constraining the visual big language model according to the images and image categories, so as to make full use of the visual big language model, and then generate image descriptions based on the visual big language model; image categories include general categories and custom categories.
[0077] At this time, in the visual language model, image description is generated based on turn-based question answering.
[0078] The specific method is explained using the following pseudo code:
[0079] taglist = inference_new_ram(image,model,5)#Numbers represent topk
[0080] history=[(f' {imagepath}Please indicate the category of the image',f'This image includes {taglist}')]#Use the category as the answer of the large language model
[0081] response,history=modelchat.chat(tokenizer,'Please describe this picture',history=history)#Second round of questions and answers, response is used as the description of the picture.
[0082] S14: constraining a visual language model based on images and image categories, and generating image descriptions based on the visual language model; image categories include general categories and custom categories;
[0083] In the specific implementation process of the present invention, the specific steps may be:
[0084] S141: Collect image description;
[0085] S142: training an image to generate a text description model based on image description;
[0086] S143: Generate a text description model based on the image and output a corresponding text description.
[0087] In an embodiment of the present application, image description is introduced to train an image-generated text description model based on the image description, thereby performing multi-level training on the text description model and then outputting the corresponding text description according to the image-generated text description model.
[0088] At this time, the visual big language model is constrained based on the image and image category, and the image description is generated based on the visual big language model, so that the image generation text description model is trained through the image description, so that the corresponding text description can be generated based on the image with one click, ensuring the accuracy and automatic generation of the text description. At the same time, the category label is customized to add user-defined categories, which can pay more attention to the categories of interest to users.
[0089] In an embodiment of the present invention, through the method in the embodiment of the present invention, images are collected and category labels are annotated for the images; customization is performed based on the category labels, at this time, plug-in training is performed for custom categories; a visual big language model is constrained based on the image and image category, and an image description is generated based on the visual big language model; the image category includes a general category and a custom category; an image-generated text description model is trained according to the image description, and the image-generated text description model outputs a corresponding text description, at this time, a visual big language model is constrained based on the image and image category, and an image description is generated based on the visual big language model, so that the image-generated text description model is trained through the image description, so that the corresponding text description is generated based on the image with one click, thereby ensuring the accuracy and automatic generation of the text description. At the same time, the category labels are customized so that user-defined categories can be added, so that more attention can be paid to the categories of interest to the user.
[0090] In addition, this training method does not change the training weights and functions of the original model, and can add new functions to the original model. Use image labels as answers to the language model, and use round-trip question-answering to generate image descriptions. Provide constraints for the generation of descriptions for large visual models.
[0091] Device Embodiment
[0092] See also Figure 5 , Figure 5 Schematic diagram of the structure of a control system for generating text description from an image in an embodiment of the present invention.
[0093] like Figure 5 As shown, a control system for generating text description from an image, the control system for generating text description from an image comprises:
[0094] A collection module 21 is used to collect images and label the images with category labels;
[0095] A custom module 22 is used for customizing based on category labels. In this case, plug-in training is used for customizing categories.
[0096] An image description module 23 is used to constrain a visual large language model based on an image and an image category, and generate an image description based on the visual large language model; the image category includes a general category and a custom category;
[0097] The text description module 24 is used to train the image-generated text description model according to the image description, and output the corresponding text description in the image-generated text description model.
[0098] See also Figure 6 , refer to the following Figure 6 The electronic device 40 according to this embodiment of the present invention will be described. Figure 6 The electronic device 40 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0099] like Figure 6 As shown, the electronic device 40 is in the form of a general computing device. The components of the electronic device 40 may include but are not limited to: at least one processing unit 41, at least one storage unit 42, and a bus 43 connecting different system components (including the storage unit 42 and the processing unit 41).
[0100] The storage unit stores program codes, which can be executed by the processing unit 41, so that the processing unit 41 executes the steps according to various exemplary embodiments of the present invention described in the above “Embodiment Method” section of this specification.
[0101] The storage unit 42 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 421 and / or a cache memory unit 422 , and may further include a read-only memory unit (ROM) 423 .
[0102] The storage unit 42 may also include a program / utility 424 having a set (at least one) of program modules 425, such program modules 425 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0103] Bus 43 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0104] The electronic device 40 may also communicate with one or more external devices (e.g., keyboards, pointing devices, Bluetooth devices, etc.), one or more devices that enable a user to interact with the electronic device 40, and / or any device that enables the electronic device 40 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 44. Furthermore, the electronic device 40 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 45. Figure 6 As shown, the network adapter 45 communicates with other modules of the electronic device 40 via the bus 43. It should be understood that although Figure 6 Not shown, other hardware and / or software modules may be used in conjunction with the electronic device 40, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup planning systems.
[0105] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the implementation of the present disclosure.
[0106] Those skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium, and the storage medium can include: a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc. In addition, it stores computer program instructions, and when the computer program instructions are executed by a computer, the computer executes the above method.
[0107] In addition, the control method and system for generating text description from an image provided by an embodiment of the present invention are introduced in detail above. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A control method for generating text description from an image, characterized in that: Applied to control scenarios where text descriptions are generated from images; The control method for generating text description from an image comprises: Collect images and label them with category labels; Customize based on category labels. In this case, plug-in training customizes categories. A visual language model is constrained based on images and image categories, and an image description is generated based on the visual language model; the image categories include general categories and custom categories; The image-generated text description model is trained according to the image description, and the image-generated text description model outputs the corresponding text description.
2. The control method for generating text description from an image according to claim 1, characterized in that: The collecting of images and labeling of category labels for the images include: Collect images; Annotate category labels based on images.
3. The control method for generating text description from an image according to claim 1, characterized in that: The customization is based on the category label. At this time, the plug-in training custom category includes: Get images and corresponding category labels; Customize based on category tags and define hobby tags. At this time, plug-in training custom categories.
4. The control method for generating text description from an image according to claim 3, characterized in that: The plug-in training custom categories include: During the training process, the output of the general category is covered by a mask. At this time, an index list is established, and the elements in it are integers from 0 to 4584. The index in the list is deleted from all the outputs of the model, so that only the custom category remains in the output of the model.
5. The control method for generating text description from an image according to claim 3, characterized in that: The plug-in training custom category also includes: The custom category also only takes the output of the second dimension and is trained using the multi-category label classification loss BCELoss.
6. The control method for generating text description from an image according to claim 1, characterized in that: The method constrains the visual large language model based on the image and the image category, and generates an image description based on the visual large language model; Image categories include common categories and custom categories, including: Collect images and image categories; Constraining the visual language model based on images and image categories; Generate image descriptions based on a large visual language model; image categories include general categories and custom categories.
7. The control method for generating text description from an image according to claim 6, characterized in that: The method constrains the visual large language model based on the image and the image category, and generates an image description based on the visual large language model; Image categories include common categories and custom categories, and also include: In the visual large language model, image descriptions are generated based on turn-by-turn question answering.
8. The control method for generating text description from an image according to claim 1, characterized in that: The step of training the image-generated text description model according to the image description and outputting the corresponding text description in the image-generated text description model includes: Collect image descriptions; Train a model to generate text descriptions from images based on image descriptions.
9. The control method for generating text description from an image according to claim 8, characterized in that: The step of training the image-generated text description model according to the image description and outputting the corresponding text description in the image-generated text description model further includes: The text description model generates the corresponding text description based on the image output.
10. A control system for generating text description from an image, characterized in that: The control system for generating text description from an image is applied to the control method for generating text description from an image as claimed in any one of claims 1 to 9, and the control system for generating text description from an image comprises: The collection module is used to collect images and annotate category labels for the images; Custom module, used for customization based on category labels. In this case, plug-in training is used for custom categories. An image description module is used to constrain the visual language model based on images and image categories, and generate image descriptions based on the visual language model; image categories include general categories and custom categories; The text description module is used to train the image-generated text description model according to the image description, and output the corresponding text description in the image-generated text description model.
Citation Information
Patent Citations
Image description generation method and system combined with abstract semantic representation and medium
CN111612103A
Object detection method and system based on user-defined category
CN117746078A
Controllable image description generation method and device and electronic equipment
CN117974846A
