Image generation method, device, computer equipment and storage medium
By segmenting the input text and generating image description sentences, combined with the second keyword, the target image is directly generated, which solves the problem of low matching between text and pictures in the existing technology, and improves efficiency and matching.
Patent Information
- Application Number
- CN202310390686.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-13
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2043-04-13
AI Technical Summary
In the existing technology, users need to select pictures that match the copy content among a large number of Internet pictures, which takes a long time and the selection results may not necessarily match completely, making it difficult to improve the matching between text and pictures.
By performing word segmentation processing on the input text, the first keyword and the second keyword are determined, an image description sentence is generated and combined with the second keyword, the target image is directly generated to improve matching and efficiency.
It significantly improves the efficiency of obtaining target images that match the input text, and improves the matching degree between the generated target image and the input text, making the generated image more consistent with the semantics of the input text.
Smart Images

Figure CN117725922B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an image generation method, apparatus, computer equipment and storage medium. Background Art
[0002] With the development of computer technology, users can use terminal applications to match text with pictures, such as poetry and mood text. For example, users can search for pictures related to the text content on the Internet as matching pictures through information retrieval and other methods.
[0003] Obviously, the existing way of matching text with pictures requires users to select the required pictures from the existing pictures according to the content of the text. However, it takes a lot of time to select the massive amount of pictures on the Internet, and the selected pictures may not completely match the content of the text. Summary of the invention
[0004] The embodiments of the present application provide an image generation method, apparatus, computer device, and storage medium, which can improve the efficiency of acquiring a target image that matches an input text, and improve the matching degree between the generated target image and the input text.
[0005] An embodiment of the present application provides an image generation method, including: performing word segmentation processing on an input text to obtain multiple candidate words; determining at least one first keyword and at least one second keyword from the multiple candidate words, the first keyword being the candidate word among the multiple candidate words that satisfies a preset association relationship, and the second keyword being the candidate word among the multiple candidate words other than the first keyword; generating an image description sentence from the first keyword; and combining the image description sentence and the second keyword to generate a target image based on the combined text.
[0006] The embodiment of the present application also provides an image generating device, including: a word segmentation processing unit, used to perform word segmentation processing on an input text to obtain multiple candidate words; a keyword determination unit, used to determine at least one first keyword and at least one second keyword from the multiple candidate words, the first keyword being the candidate word among the multiple candidate words that satisfies a preset association relationship, and the second keyword being the candidate word among the multiple candidate words other than the first keyword; a sentence generating unit, used to generate an image description sentence from the first keyword; and an image generating unit, used to combine the image description sentence and the second keyword to generate a target image based on the combined text.
[0007] An embodiment of the present application also provides a computer device, including a processor and a memory, wherein the memory stores multiple instructions; the processor loads instructions from the memory to execute the steps in any one of the image generation methods provided in the embodiments of the present application.
[0008] An embodiment of the present application also provides a computer-readable storage medium, which stores a plurality of instructions, and the instructions are suitable for a processor to load to execute the steps in any one of the image generation methods provided in the embodiment of the present application.
[0009] The embodiment of the present application can perform word segmentation processing on the input text to obtain multiple candidate words; determine at least one first keyword and at least one second keyword from the multiple candidate words, the first keyword is the candidate word among the multiple candidate words that satisfies a preset association relationship, and the second keyword is the candidate word among the multiple candidate words other than the first keyword; generate an image description sentence from the first keyword; combine the image description sentence and the second keyword to generate a target image according to the combined text.
[0010] In the present application, by dividing the input text into the first keyword and the second keyword, in the process of generating the target image, the image description sentence can be used as the main content (main feature) of the generated target image, and the second keyword can be used as the supplementary condition (supplementary feature) of the generated target image, and the target image can be directly generated based on the text after the combination of the two, thereby improving the efficiency of obtaining the target image that matches the input text. In addition, the main elements of the target image are determined by the image description sentence, and other features in the input text are retained by the second keyword, and the target image finally generated is affected, so that the target image is more consistent with the semantics of the input text, and the matching degree between the generated target image and the input text is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0012] Figure 1a is a scene schematic diagram of the image generation method provided in an embodiment of the present application;
[0013] Figure 1b It is a flowchart of the image generation method provided in the embodiment of the present application;
[0014] Figure 1c is a schematic diagram of an aesthetic scoring model provided in an embodiment of the present application;
[0015] Figure 1d is a schematic diagram of a linear prediction model provided in an embodiment of the present application;
[0016] Figure 2a is a schematic diagram of an image generation system provided in an embodiment of the present application;
[0017] Figure 2b is a flowchart of an image generation method provided by another embodiment of the present application;
[0018] Figure 3 is a schematic diagram of the structure of an image generating device provided in an embodiment of the present application;
[0019] Figure 4 It is a schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0020] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.
[0021] Embodiments of the present application provide an image generation method, apparatus, computer device, and storage medium.
[0022] The image generation device may be integrated into an electronic device, which may be a terminal, a server, or the like. The terminal may be a mobile phone, a tablet computer, a smart Bluetooth device, a laptop, or a personal computer (PC); the server may be a single server or a server cluster consisting of multiple servers.
[0023] In some embodiments, the image generating device may also be integrated into multiple electronic devices. For example, the image generating device may be integrated into multiple servers, and the image generating method of the present application may be implemented by multiple servers.
[0024] In some embodiments, the server may also be implemented in the form of a terminal.
[0025] For example, refer to Figure 1a , a scene diagram of an image generation system is provided, and the system can implement an image generation method. In this scene, a terminal and a server can be included.
[0026] Among them, the server can be used to perform word segmentation processing on the input text to obtain multiple candidate words; determine at least one first keyword and at least one second keyword from the multiple candidate words, the first keyword is a candidate word that satisfies a preset association relationship among the multiple candidate words, and the second keyword is a candidate word other than the first keyword among the multiple candidate words; generate an image description sentence from the first keyword; combine the image description sentence and the second keyword to generate a target image according to the combined text. The terminal can be used to obtain the input text and send it to the server, and obtain the target image from the server for display. Data can be transmitted between the server and the terminal through a network, and the network can be a wireless network or a wired network, such as a wireless network such as a wireless local area network (WLAN), a local area network (LAN), a cellular network, a 2D network, a 3G network, a 4G network, a 5G network, etc.
[0027] The following are described in detail. It should be noted that the order of the following embodiments is not intended to limit the preferred order of the embodiments. It is understood that in the specific implementation of the present application, data related to user input text, input initial text, etc., when the embodiments of the present application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions.
[0028] In this embodiment, an image generation method is provided, such as Figure 1b As shown, the specific process of the image generation method can be as follows:
[0029] 110. Perform word segmentation on the input text to obtain multiple candidate words.
[0030] The input text refers to the text input by the user for generating an image. For example, the input text may include text in one or more forms of sentences, phrases or words, etc., and the sentences, phrases or words may be composed of semantically coherent or semantically incoherent texts. For example, the input text may be a semantically coherent "standing on the shore, feeling the breath of nature, the sun in the distance gradually sets", or the input text may be a semantically incoherent "rainy day, wet streets".
[0031] In practical applications, the text composition of the input text has a great influence on the generated image, and the images generated by the input texts with similar semantics but different text composition will also have large differences. Therefore, the image generation method of the embodiment of the present application can be integrated in the terminal, and when the user enters the text, the relevant prompt information can be displayed on the graphical user interface of the terminal to assist the user in entering effective text and improve the accuracy of the image generated by the text. For example, the sample text of the input text such as "yellow-haired dog" and "wet street" can be displayed on the graphical user interface, and the user can write the input text according to the displayed sample text, or a plurality of prompt words such as "sky", "ocean", "puppy", "rainy day", "sunrise", "white cloud blue sky" etc. that can be used to form the input text can be displayed on the graphical user interface, and the user can select part of these prompt words for writing the input text.
[0032] Among them, word segmentation refers to the process of dividing the input text into independent words according to certain rules. For example, a word segmentation tool can be called to segment the input text. The word segmentation tool can be an open source Chinese word segmentation tool, such as Jieba word segmentation, Hanlp word segmenter, Harbin Institute of Technology Language Technology Platform (LTP), Stanford word segmenter, natural language processing and information retrieval sharing platform NLPIR, etc.
[0033] Among them, the candidate words can be all or part of the words that constitute the input text. In some embodiments, nouns, place names, adjectives, verbs and other content words in the words after the input text is segmented can be selected as candidate words according to the part of speech. Part of speech refers to the basis for dividing word classes based on the characteristics of the word. Usually, the part of speech can include content words and function words. Content words include nouns, pronouns, verbs, adjectives, numerals, and quantifiers. Function words include adverbs, prepositions, conjunctions, articles, auxiliary words, interjections, and onomatopoeia.
[0034] In some implementations, when a user inputs text, a corresponding prompt may be given according to the text structure of the input text to assist the user in inputting valid text and improve the accuracy of generating images from text. Specifically, before performing word segmentation processing on the input text and obtaining multiple candidate words, the following is also included:
[0035] Get the initial text entered by the user;
[0036] Perform word segmentation on the initial text to obtain multiple initial candidate words;
[0037] Determining the text structure of the initial text according to the parts of speech of the multiple initial candidate words;
[0038] If the text structure does not satisfy the preset text structure, a first prompt for the text structure is displayed so that the initial text can be adjusted to the input text according to the first prompt.
[0039] The initial text refers to the text initially input by the user for generating an image. The initial text can be used directly as the input text, or the initial text can be adjusted to obtain the input text. The initial candidate words refer to all or part of the words that constitute the input text. In some embodiments, nouns, place names, adjectives, verbs, and other content words in the words after the initial text segmentation can be selected as keywords according to the part of speech.
[0040] The text structure refers to a structure determined by the combination and / or order of words in the text, and the text structure may include but is not limited to the types of parts of speech of the words constituting the text and / or the order of words of different parts of speech, etc. In some embodiments, the text structure may include the types of parts of speech of the words in the text and the number of words of different parts of speech.
[0041] The preset text structure refers to a text structure preset according to requirements or application scenarios. It is understandable that the accuracy of images generated from texts with the preset text structure is usually higher than the accuracy of images generated from texts with non-preset text structures.
[0042] For example, in actual applications, the text input by the user should contain at least one word with specific semantics to avoid completely abstract descriptions. In this way, the preset text structure can be set to include the form of "subject + predicate + object", where the subject and object are entity nouns such as "sky", "ocean", and "puppy", and the predicate is a verb. The image content generated in this way will tend to generate objects corresponding to the entity nouns in the text. In addition, too many entity nouns should be avoided in the text. If too many entity words are included, the generated image may lack focus, and the objects appearing in the image are uncontrollable. Therefore, the preset text structure also includes that the number of entity nouns in the text is less than or equal to a preset number, such as 2. Therefore, the preset text structure can be in the form of "subject + predicate + object", and / or the number of nouns in the text is less than or equal to a preset number.
[0043] In some embodiments, in order to further improve the accuracy of the generated image, in the preset text structure, specific adjectives such as color, state, etc. can be prefixed to the entity word to adjust the display effect of the object corresponding to the entity word in the image.
[0044] Among them, the first prompt refers to information used to prompt the adjustment of the text structure of the initial text. Different prompts can be set according to different application scenarios. For example, the first prompt can be in the form of text, logo, etc. For example, the first prompt can be a prompt text indicating that the text structure is wrong, such as "the text structure does not meet the specifications", or it can be a prompt text pointing out the text structure error "too many nouns in the text", or it can be a key information in the text structure such as subject, predicate, object to be highlighted, or names exceeding a preset number to be highlighted.
[0045] For example, when a user inputs text through a terminal, the text (initial text) input by the user can be segmented, and based on the part of speech of the initial candidate words after segmentation, it can be determined whether the initial text contains the form of "subject + predicate + object" and whether it contains more than two entity words. If not (i.e., it satisfies the preset text structure), the initial text can be used as the input text. If the initial text lacks any structure of "subject + predicate + object", such as the subject structure, a prompt "text lacks subject" can be displayed on the graphical user interface of the terminal; if there are more than two entity words in the initial text, a prompt "too many entity words in the text" can be displayed on the graphical user interface of the terminal, and the entity words in the initial text can be highlighted. The user can modify the initial text according to the prompt to make it meet the preset text structure to obtain the input text.
[0046] In some implementations, the terminal may also automatically adjust the initial text to the input text according to the first prompt to improve the efficiency of generating the input text. Specifically, if the text structure does not meet the preset text structure, after displaying the first prompt for the text structure, it also includes:
[0047] According to the first prompt, adjust the initial text to obtain the input text.
[0048] For example, the terminal may automatically modify the initial text according to the first prompt and in combination with the context of the initial text, such as automatically completing the missing structure of the initial text or deleting excessive entity words, to obtain the input text.
[0049] In some implementations, when a user inputs text, a corresponding prompt may be given according to the type of the input text to assist the user in inputting valid text and improve the accuracy of generating images from text. Specifically, before performing word segmentation processing on the input text to obtain multiple candidate words, the following is also included:
[0050] Get the initial text entered by the user;
[0051] Determine the text type of the initial text according to the semantics of the initial text;
[0052] If the text type is a specified text type, a second prompt for the specified text type is displayed so that the initial text is adjusted to the input text according to the second prompt.
[0053] Among them, the text type refers to the type divided according to the semantics of the text. For example, the topic, emotion, scene, etc. expressed by the semantics in the text can be determined through semantic analysis methods, and the text can be divided into different types. For example, through the semantic analysis of the initial text "The kitten is very happy", it can be known that it represents the emotion of happiness, so it can be determined that the text type of the initial text is happy. For another example, through the semantic analysis of the initial text "The child kicked a ball", it can be known that it represents the scene of sports, so it can be determined that the text type of the initial text is sports.
[0054] The designated text type refers to one or more text types designated according to actual needs or application scenarios. For example, text types of abstract classes can be designated as text types, such as emotion-related text types, which represent relatively abstract semantics and can therefore be designated as text types.
[0055] Among them, the second prompt refers to the information used to prompt the adjustment of the initial text according to the specified text type. Different prompts can be set according to different application scenarios. For example, the second prompt can be in the form of text, logo, etc. For example, for the initial text "The kitten is very happy". The second prompt can be a modification prompt text for emotion-related words in the text, such as "Please modify the word "happy" in the text", or it can highlight the word "happy" in the initial text, and can also display concrete prompt text related to the word "happy" that can be used to replace the word "happy" and is used to describe real scenes, such as "blue sky", "bright flowers", etc.
[0056] For example, when a user inputs text through a terminal, a semantic analysis can be performed on the text (initial text) input by the user to determine the text type of the initial text. If the text type of the initial text is not an emotional type, the initial text can be used as the input text. If the text type of the initial text is an emotional type, such as "sadness", prompts such as "rainy day" and "wet street" can be displayed on the graphical user interface of the terminal. If the text type of the initial text is "joy", prompts such as "sunrise" and "white clouds and blue sky" can be displayed on the graphical user interface of the terminal. The user can modify the initial text according to the prompt to make the semantics it expresses more concrete, so as to obtain the input text.
[0057] In some implementations, the terminal may also automatically adjust the initial text to the input text according to the second prompt, thereby improving the efficiency of generating the input text. Specifically, if the text type is a specified text type, after displaying the second prompt for the specified text type, it also includes:
[0058] The target text is replaced according to the second prompt to obtain the output text, where the target text is the text in the initial text that matches the specified text type.
[0059] For example, if the text type of the initial text is "sadness", the terminal can automatically select the prompt text most relevant to the context of the initial text from the second prompt based on the second prompt and the context of the initial text, and replace the text matching "sadness" in the initial text with the prompt text to obtain the input text.
[0060] 120. Determine at least one first keyword and at least one second keyword from the plurality of candidate words.
[0061] Among them, the first keyword is a candidate word among multiple candidate words that meets a preset association relationship, and the second keyword is a candidate word among multiple candidate words except the first keyword.
[0062] The preset association relationship refers to an association relationship condition preset according to needs or application scenarios. The association relationship is used to characterize the association of keywords in the input text, such as whether it is associated and / or the degree of association.
[0063] For example, all candidate words may be extracted through a word segmentation tool, and then candidate words with relevance among the candidate words may be used as keywords.
[0064] In some implementations, a candidate word that satisfies a preset context association relationship may be used as the first keyword to make the semantics of the constructed image description sentence accurate and improve the accuracy of generating images from text. Specifically, the preset association relationship includes a preset context association relationship, and determining at least one first keyword and at least one second keyword from multiple candidate words includes:
[0065] Determine the contextual relationship of the candidate words;
[0066] The candidate word whose context association relationship satisfies the preset context association relationship is used as the first keyword;
[0067] Among the plurality of candidate words, candidate words other than the first keyword are used as second keywords.
[0068] The contextual relationship refers to the logical relationship between language units based on semantics. It can be understood that language units with contextual relationships (such as keywords) can form a consistent linguistic environment.
[0069] For example, the preset association relationship may be context association, and a candidate word with context association among multiple candidate words may be used as the first keyword, and a candidate word without context association may be used as the second keyword.
[0070] In some implementations, the context association relationship may include a keyword score, wherein the keyword score refers to a score of a candidate word determined by a keyword extraction algorithm.
[0071] For example, you can use a word segmentation tool to extract all candidate words, and then use a trained keyword extraction classifier, such as a TF-IDF-based keyword extraction algorithm or a TextRank-based keyword extraction algorithm, to score each candidate word, and then output the topK candidate words with the highest scores as the first keyword, and the other candidate words as the second keyword, where K in topK is set according to the application scenario or actual needs.
[0072] In some implementations, the contextual association relationship may include the contextual association relationship between candidate words, and multiple candidate words with contextual association relationships may be used as first keywords to construct a structurally complete image description sentence, so as to further improve the accuracy of the semantics represented by the image description sentence and improve the accuracy of generating images from text. Specifically, there are multiple first keywords, and determining the contextual association relationship of the candidate words includes:
[0073] A context association relationship between candidate words in a candidate word group is determined, wherein the candidate word group includes a plurality of candidate words.
[0074] The candidate phrase refers to a phrase composed of candidate words selected according to the number and / or part of speech of the first keyword. For example, the candidate words include entity word 1, entity word 2, entity word 3, verb 1, and verb 2. Multiple candidate words can be combined into six candidate phrases: entity word 1+verb 1, entity word 1+verb 2, entity word 2+verb 1, entity word 2+verb 2, entity word 3+verb 1, entity word 3+verb 2.
[0075] For another example, the occurrence probabilities of different candidate phrases can be compared based on statistical language models, HMM and Viterbi algorithm, and used as contextual association relationships. For example, a sequence of multiple candidate words can be input into a statistical language model such as N-gram (language model) to determine the occurrence probabilities (i.e., contextual association relationships) of the six candidate phrases of entity word 1 + verb 1, entity word 1 + verb 2, entity word 2 + verb 1, entity word 2 + verb 2, entity word 3 + verb 1, and entity word 3 + verb 2, and the candidate phrase with the highest occurrence probability, entity word 2 + verb 2, is taken as having contextual association, that is, entity word 2 and verb 2 are the first keywords, and the other candidate words entity word 1, entity word 3 and verb 1 are the second keywords.
[0076] 130. Generate an image description sentence based on the first keyword.
[0077] The image description sentence refers to a sentence used to describe the image content. For example, the first keyword "grass, running, puppy" can generate an image description sentence "a puppy running on the grass".
[0078] In some implementations, an image description sentence may be generated using an image description template to generate a structurally standardized and semantically rich image description sentence, thereby improving the accuracy of generating images from text. Specifically, generating an image description sentence from a first keyword includes:
[0079] Acquire an image description template, the image description template including at least one padding bit;
[0080] The first keyword is filled in the filling position to obtain an image description sentence.
[0081] The image description template refers to a text template used to generate an image description sentence. The image description text may be in the form of a sentence, and includes at least one preset word and at least one filler position.
[0082] For example, the image description text may be an ink painting of xxx, where "a", "of" and "ink painting" are preset words, and xxx is a filler position. The first keyword "mountain" can be filled in the filler position to form the image description sentence "an ink painting of a mountain". In this way, the richness of the semantic representation of the constructed image description sentence can be increased by using preset words, and by setting filler positions, the position of the first keyword in the image description sentence structure can be limited to standardize the structure of the generated image description sentence and improve the accuracy of generating images from text.
[0083] In some embodiments, the first keyword can be determined based on the image description template so that the determined first keyword meets the requirements of the image description template and improves the accuracy of generating images from text. For example, the number M of filling positions of the image description template can be used as the K value in topK, that is, the M candidate words with the highest scores are selected as the first keyword. For another example, the first keyword can also be determined based on the number of filling positions of different parts of speech in the image description template. For example, if the image description template includes M filling positions corresponding to nouns and N filling positions corresponding to adjectives, the M nouns with the highest scores and the N adjectives with the highest scores can be selected as the first keyword.
[0084] In some implementations, when there are multiple first keywords, ie, multiple filling positions, candidate phrases may be determined based on the filling positions.
[0085] For example, according to the number of filling positions of the image description template and / or the part of speech corresponding to the filling positions, a candidate word that meets the number of filling positions and / or the part of speech corresponding to the filling positions can be selected from the candidate words. For example, if the image description template includes M filling positions corresponding to nouns and N filling positions corresponding to adjectives, nouns and adjectives can be randomly selected from the candidate words to generate multiple groups of candidate phrases, each candidate phrase including M nouns and N adjectives, and it is determined whether there is a contextual association between the candidate words in each group of candidate phrases, and the candidate words in the candidate phrases with contextual associations are used as the first keywords.
[0086] For another example, the contextual association relationship between at least two arbitrary candidate words can be determined according to the order of the filling positions of different parts of speech in the image description template. For example, the image description template is "a xxx (filling position 1) of xxx (filling position 2) ink painting", where filling position 1 corresponds to a noun and filling position 2 corresponds to an adjective. For the keywords noun 1, noun 2, noun 3, adjective 1 and adjective 2, a candidate phrase of noun + adjective with the same order of parts of speech as the filling positions can be formed and its occurrence probability can be determined. The sequence composed of multiple candidate words can be input into a statistical language model such as N-gram (language model) to determine the occurrence probability (i.e., contextual association relationship) of the six candidate phrases of noun 1 + adjective 1, noun 1 + adjective 2, noun 2 + adjective 1, noun 2 + adjective 2, noun 3 + adjective 1, and noun 3 + adjective 2, and noun 1 and adjective 2 in the candidate phrase noun 1 + adjective 2 with the highest occurrence probability are used as the first keyword, and the other candidate words noun 2, noun 3 and adjective 1 are used as the second keyword. And the noun 1 and the adjective 2 can be filled in the corresponding filling positions of "a xxx (filling position 1) of xxx (filling position 2) ink painting" to obtain a noun 1 and adjective 2 ink painting.
[0087] It should be noted that, when there are multiple image description templates, the corresponding first keyword and second keyword may be determined for each image description template to generate image description sentences corresponding to different image description templates.
[0088] 140. Combine the image description sentence and the second keyword to generate a target image according to the combined text.
[0089] For example, the combined text may be separated by a separator for the image description statement and the second keyword, and the separator may include a vertical bar, a semicolon, a comma, a slash, a delim (separator string), and other symbols, or other custom separators. For example, the combined text may be in the form of "image description statement, second keyword".
[0090] It is understandable that in the process of generating a target image, the embodiment of the present application can use the image description sentence as the main content (main feature) of generating the target image, and the second keyword as the supplementary condition (supplementary feature) of generating the target image, and directly generate the target image based on the text after the combination of the two, thereby improving the efficiency of obtaining the target image that matches the input text. In addition, the main elements of the target image are determined by the image description sentence, and other features in the input text are retained by the second keyword, and the target image finally generated is affected, so that the target image is more consistent with the semantics of the input text, and the matching degree between the generated target image and the input text is improved.
[0091] In some implementations, the image generation model may be used to infer the combined text to obtain a target image, so that the image generation model can learn to obtain image features from the image description sentence and the second keyword to improve the accuracy of generating the target image. Specifically, combining the image description sentence and the second keyword to generate the target image according to the combined text includes:
[0092] Get the image generation model;
[0093] Combining the image description sentence and the second keyword to obtain a combined text;
[0094] The combined text is input into the image generation model to generate the target image.
[0095] For example, the image description sentence and the second keyword may be combined to obtain a combined text, and then the combined text may be input into an image generation model, which may decode and generate a target image. The image generation model may include but is not limited to a Stable Diffusion model, a GAN (Generative Adversarial Network) model, a VQ-VAE (Vector Quantization Auto-Encoding) model, and other models that can generate images from text.
[0096] In some implementations, the image generation model may include an encoding network, a denoising network, a denoising network, and a decoding network.
[0097] The encoding network may refer to a network that can represent text as feature values. The encoding network may be a combination of one or more networks such as an encoder in an autoencoder network, a back propagation network, a recurrent neural network, and an image encoder of a CLIP (pre-training based on contrastive text-image pairs) network. The decoding network may refer to a network that can convert image features into images, and the decoding network may be a combination of one or more networks such as a decoder in an autoencoder network, a recurrent neural network, and a generative adversarial network. The denoising network may refer to a network that can add noise to image data. The denoising network may refer to a network that can be used to restore the original image data from the data after adding noise.
[0098] For example, the encoding network can encode the combined input text to generate text features, then slowly add random noise to the image features through the denoising network, and then reversely deduce from the noise through the denoising network to gradually eliminate the noise, and then decode it by the decoding network to generate the target image.
[0099] In some embodiments, the encoding network may be an image encoder of a CLIP network, which converts text into a representation form that can be understood by the model through the image encoder of the CLIP network to guide the learning process of the denoising network. The CLIP network may also supervise the training process by calculating the cosine similarity between the generated first stylized image and the training description text.
[0100] In some implementations, images may be filtered by the similarity between the target image and a preset filter word to improve the user experience. Specifically, after combining the image description sentence and the second keyword to generate the target image according to the combined text, the method further includes:
[0101] Calculate the similarity between the target image and the preset filter words;
[0102] If the similarity is higher than a preset similarity threshold, the target image is determined as an image to be filtered.
[0103] The preset filter words refer to words used to filter images. You can set the preset filter words according to actual needs or application scenarios. For example, you can set multiple 17 sensitive words such as pornography and violence as preset filter words. Users can also add sensitive word lists according to usage scenarios, such as specific political figures.
[0104] For example, multiple sensitive words can be set as preset filter words, and the security check model can be used to calculate the similarity between each sensitive word and the target image in turn. If the similarity between the target image and any sensitive word is higher than the threshold, it will be judged as an unsafe image (i.e., the image to be filtered). In this way, the image to be filtered can be filtered in the background so that it is not displayed on the user terminal. If the similarity between the target image and all sensitive words is equal to or higher than the threshold, the target image can be returned to the user's terminal, thereby improving the user experience.
[0105] In some embodiments, the security check model may include an image encoder of a CLIP network, that is, the image encoder of the CLIP network may be used to calculate the similarity between the target image and a preset filter word to filter the image. In this way, the image encoder of the CLIP network may be used in the encoding process of the image generation model and the filtering process of the target image, thereby improving the utilization rate of computing resources.
[0106] In some embodiments, since text and pictures usually require image aesthetics, the CLIP network can be used to use the text template ["Goodphoto", "Badphoto"] to evaluate the overall quality of the target image (the aesthetic score of the target image). The scores of dimensions such as brightness, noisiness, colorfulness, and sharpness of the image can also be evaluated. Images can be filtered based on the scores of overall quality, brightness, noise, color, sharpness, etc.; the scores of the overall quality, brightness, noise, color, sharpness, etc. of the target image can also be displayed on the user terminal so that the user can choose whether to discard the image, thereby improving the user experience.
[0107] In some implementations, the aesthetic score of the target image can be determined by encoding and linearly transforming the target image to improve the user experience. Specifically, after combining the image description sentence and the second keyword to generate the target image according to the combined text, the method further includes:
[0108] Encode the target image to obtain image features;
[0109] Perform linear transformation on image features to obtain the aesthetic score of the target image.
[0110] For example, an aesthetic scoring model can be used to calculate the aesthetic score of a target image, such as Figure 1c As shown, the aesthetic scoring model includes a coding network and a linear prediction model. The target image is encoded by the coding network to obtain a feature representation (image feature) of the target image, and then the linear prediction model performs a linear transformation on the image feature to obtain an aesthetic score of the target image. If the aesthetic score of the target image (such as 6.23) is higher than the preset aesthetic score (such as 5), the target image can be returned to the user's terminal. If the aesthetic score of the target image (such as 1.64) is equal to or lower than the preset aesthetic score, the image to be filtered can be filtered in the background so that it is not displayed on the user's terminal; the aesthetic score of the target image can also be displayed on the user's terminal to assist the user in choosing whether to discard the image, thereby improving the user experience.
[0111] In some embodiments, the encoding network of the aesthetic scoring model may be an image encoder of a CLIP network. Thus, the image encoder of the CLIP network may be used in the encoding process of the image generation model and the aesthetic score calculation process of the target image, thereby improving the utilization of computing resources. In addition, since the image features of the image encoder of the CLIP network already contain high-level semantics, using this feature can obtain a more accurate image score.
[0112] In some embodiments, a lightweight linear prediction model can be formed by a fully connected layer and a feature discarding layer to improve the efficiency of determining the aesthetic score of the target image. In addition, the feature discarding layer is used in the linear prediction model to avoid overfitting of the model. Specifically, the image features are linearly transformed to obtain the aesthetic score of the target image, including:
[0113] Obtain a linear prediction model, the linear prediction model comprising a first fully connected layer, a feature discarding layer, and a second fully connected layer;
[0114] Through the first fully connected layer, the image features are linearly transformed to obtain the first features;
[0115] Through the feature discarding layer, according to the preset discarding probability, the first feature is subjected to feature discarding processing to obtain the second feature;
[0116] Through the second fully connected layer, the second feature is linearly transformed to obtain the aesthetic score of the target image.
[0117] For example, there may be one or more first fully connected layer, feature discard layer (dropout layer) and second fully connected layer, and the feature discard layer is connected after the first fully connected layer. Figure 1d As shown, the linear prediction model may include five fully connected layers connected in series, wherein the first three are the first fully connected layers and the last two are the second fully connected layers. A feature discarding layer is connected after each first fully connected layer.
[0118] In this way, the dimensionality reduction of the input image features can be gradually achieved through multiple fully connected layers, and overfitting can be avoided by using multiple feature discarding layers. Figure 1d As shown, after the image encoder of the CLIP network encodes the target image to obtain an image feature with a dimension of 1*512, the image feature is input into the first fully connected layer 1 with a parameter dimension of 512*1024 for linear transformation. After obtaining the feature, the feature is discarded by the feature discarding layer 1 according to the discarding probability of 0.2, and then the first fully connected layer 2 with an input parameter dimension of 1024*128 is linearly transformed. After obtaining the feature, the feature is discarded by the feature discarding layer 2 according to the discarding probability of 0.2, and then the first fully connected layer 3 with an input parameter dimension of 128*64 is linearly transformed. After obtaining the feature, the feature is discarded by the feature discarding layer 3 according to the discarding probability of 0.1, and then the second fully connected layer 1 with an input parameter dimension of 64*16 is linearly transformed. After obtaining the feature, the second fully connected layer 2 with a parameter dimension of 16*1 is linearly transformed, and finally the aesthetic score is 6.23.
[0119] In some embodiments, the initial linear prediction model can be trained by a preset aesthetic data set, such as an open source aesthetic data set, until the loss function converges to obtain a linear prediction model, so that the model can be used to determine the aesthetic score of the image. For example, in the preset aesthetic data set, real users can give aesthetic scores to each image, and the score range is 1 to 10, and the higher the score, the better the aesthetic effect. The loss function used by the linear prediction model can be MSE Loss (mean square error loss function).
[0120] The image generation scheme provided by the embodiment of the present application can be applied in various image processing scenarios. For example, taking the scenario of generating an image by user input text as an example, the input text is segmented to obtain multiple candidate words; from the multiple candidate words, at least one first keyword and at least one second keyword are determined, the first keyword is a candidate word among the multiple candidate words that meets the preset association relationship, and the second keyword is a candidate word among the multiple candidate words other than the first keyword; an image description sentence is generated from the first keyword; the image description sentence and the second keyword are combined to generate a target image according to the combined text.
[0121] As can be seen from the above, the embodiment of the present application divides the input text into the first keyword and the second keyword. In the process of generating the target image, the image description sentence can be used as the main content (main feature) of the generated target image, and the second keyword can be used as the supplementary condition (supplementary feature) of the generated target image, and the target image can be directly generated based on the text after the combination of the two, thereby improving the efficiency of obtaining the target image that matches the input text. In addition, the main elements of the target image are determined by the image description sentence, and other features in the input text are retained by the second keyword, and the target image finally generated is affected, so that the target image is more consistent with the semantics of the input text, and the matching degree between the generated target image and the input text is improved.
[0122] The method described in the above embodiment will be further described in detail below.
[0123] In this embodiment, the method of the embodiment of the present application will be described in detail by taking application to an image generation system as an example.
[0124] The image generation system may include a user end and a server end, wherein the server end includes an image generation model, a security check model, and an aesthetic scoring model. Figure 2a As shown, the image generation model may include an encoding network, a denoising network, a denoising network, and a decoding network, the security check model may include the encoding network in the image generation model, and the aesthetic scoring model may include a linear prediction model and the encoding network in the image generation model.
[0125] like Figure 2b As shown, the specific process of an image generation method is as follows:
[0126] 210. When the user performs an input operation, obtain the initial text of the input.
[0127] For example, the user terminal can run on a terminal used by the user, and the terminal can monitor the user's input operation. When the user enters text through the terminal, the initial text entered by the user can be obtained, and the text structure and text type of the initial text can be detected.
[0128] 221. If the text structure of the initial text does not satisfy the preset text structure, display a first prompt for the text structure.
[0129] For example, if the initial text input by the user does not meet the preset text structure, a prompt such as "the text lacks a subject" may be displayed.
[0130] 222. If the text type of the initial text is a specified text type, display a second prompt for the specified text type.
[0131] For example, if the text type of the initial text entered by the user is emotion, a prompt such as “Please modify the word “happy” in the text” may be displayed.
[0132] 230. In response to the adjustment operation, obtain input text.
[0133] For example, after displaying the first prompt or the second prompt, the user's adjustment operations on the initial text can be monitored, such as modifying the initial text or re-entering the initial text. If the adjusted initial text meets the preset text structure and does not contain emotion-related words, the text can be used as input text.
[0134] 240. Perform word segmentation on the input text to obtain multiple candidate words.
[0135] For example, a word segmentation tool may be called to segment the input text to obtain multiple candidate words.
[0136] 250. Determine at least one first keyword and at least one second keyword from a plurality of candidate words according to the image description template.
[0137] For example, a trained keyword extraction classifier can be used to determine the keyword score of each candidate word. According to the number of filling positions and parts of speech in the image description template, the candidate word that meets the number of filling positions and parts of speech is selected as the first keyword according to the keyword scores of the candidate words from high to low, and the other candidate words are selected as the second keywords.
[0138] 260. Generate an image description sentence based on the first keyword.
[0139] For example, the first keyword may be filled in a corresponding filling position of the image description template to obtain an image description sentence.
[0140] 270. Combine the image description sentence and the second keyword, and generate a target image according to the combined text through an image generation model.
[0141] For example, the image description sentence and the second keyword may be combined, and then the combined text may be encoded, denoised, denoised, and decoded through an image generation model to generate a target image.
[0142] 280. Through the security check model, determine whether the target image is an image to be filtered.
[0143] For example, the encoding network in the image generation model can be an image encoder of the CLIP network. The security check model can calculate the similarity between the target image and the preset filter words through the image encoder of the CLIP network. If the similarity between the target image and any filter is higher than the threshold, it will be judged as an unsafe image (i.e., the image to be filtered). The image to be filtered can be filtered on the server side so that it is not displayed on the user side.
[0144] 290. Determine the aesthetic score of the target image through the aesthetic scoring model.
[0145] For example, the encoding network in the image generation model can be an image encoder of the CLIP network. The aesthetic scoring model can encode the target image by the image encoder of the CLIP network to obtain image features, and then gradually reduce the dimension of the input image features through multiple fully connected layers, and use multiple feature discarding layers to avoid overfitting, and output the aesthetic score of the target image. The aesthetic score can be displayed on the user side to assist the user in choosing whether to discard the image.
[0146] It should be noted that multiple image description templates can be set, and the corresponding first keyword and second keyword can be determined for each image description template to generate image description sentences corresponding to different image description templates, and generate target images corresponding to each image description sentence (i.e., each image description template). Security checks are performed on the generated multiple target images, and only safe images (i.e., non-filtered images) are displayed on the user side, and the aesthetic scores of these safe images can be displayed.
[0147] It should be noted that in actual applications, the application of the safety check model and the aesthetic scoring model can be turned on or off based on actual needs or application scenarios. For example, when computing resources are tight, the application of the safety check model and / or the aesthetic scoring model can be turned off.
[0148] As can be seen from the above, the input text is divided into the first keyword and the second keyword. In the process of generating the target image, the image description sentence can be used as the main content (main feature) of generating the target image, and the second keyword can be used as the supplementary condition (supplementary feature) of generating the target image. The image generation model directly generates the target image based on the text after the combination of the two, thereby improving the efficiency of obtaining the target image that matches the input text. In addition, the main elements of the target image are determined by the image description sentence, and other features in the input text are retained by the second keyword, which affects the final generated target image, making the target image more consistent with the semantics of the input text, and improving the matching degree between the generated target image and the input text. At the same time, based on the model structure of the image generation model, security checks and aesthetic checks on the target image are introduced to improve the utilization of computing resources.
[0149] In order to better implement the above method, the embodiment of the present application also provides an image generation device, which can be integrated in an electronic device, and the electronic device can be a terminal, a server, etc. Among them, the terminal can be a mobile phone, a tablet computer, a smart Bluetooth device, a laptop, a personal computer, etc.; the server can be a single server or a server cluster composed of multiple servers.
[0150] For example, in this embodiment, the method of the embodiment of the present application is described in detail by taking the image generating device being specifically integrated in the server as an example.
[0151] For example, Figure 3 As shown, the image generating device may include a word segmentation processing unit 310, a keyword determination unit 320, a sentence generating unit 330 and an image generating unit 340, as follows:
[0152] (I) Word segmentation processing unit 310
[0153] Used to perform word segmentation on the input text to obtain multiple candidate words.
[0154] In some implementations, the image generating device may further include a text adjustment unit, which may be specifically used to:
[0155] Get the initial text entered by the user;
[0156] Perform word segmentation on the initial text to obtain multiple initial candidate words;
[0157] Determining the text structure of the initial text according to the parts of speech of the multiple initial candidate words;
[0158] If the text structure does not satisfy the preset text structure, a first prompt for the text structure is displayed so that the initial text can be adjusted to the input text according to the first prompt.
[0159] In some implementations, the image generating device may further include a text adjustment unit, which may be specifically used to:
[0160] Get the initial text entered by the user;
[0161] Determine the text type of the initial text according to the semantics of the initial text;
[0162] If the text type is a specified text type, a second prompt for the specified text type is displayed so that the initial text is adjusted to the input text according to the second prompt.
[0163] (II) Keyword determination unit 320
[0164] Used to determine at least one first keyword and at least one second keyword from multiple candidate words, the first keyword is a candidate word among the multiple candidate words that meets a preset association relationship, and the second keyword is a candidate word among the multiple candidate words except the first keyword.
[0165] In some implementations, the preset association relationship includes a preset context association relationship, and the keyword determination unit 320 may be specifically configured to:
[0166] Determine the contextual relationship of the candidate words;
[0167] The candidate word whose context association relationship satisfies the preset context association relationship is used as the first keyword;
[0168] Among the plurality of candidate words, candidate words other than the first keyword are used as second keywords.
[0169] (III) Sentence Generation Unit 330
[0170] Used to generate an image description sentence based on the first keyword.
[0171] In some implementations, the statement generation unit 330 may be specifically used to:
[0172] Acquire an image description template, the image description template including at least one padding bit;
[0173] The first keyword is filled in the filling position to obtain an image description sentence.
[0174] (IV) Image generation unit 340
[0175] Used to combine the image description sentence and the second keyword to generate a target image according to the combined text.
[0176] In some implementations, the image generation unit 340 may be specifically configured to:
[0177] Get the image generation model;
[0178] Combining the image description sentence and the second keyword to obtain a combined text;
[0179] The combined text is input into the image generation model to generate the target image.
[0180] In some embodiments, the image generating device may further include an image checking unit, which may be specifically used to:
[0181] Calculate the similarity between the target image and the preset filter words;
[0182] If the similarity is higher than a preset similarity threshold, the target image is determined as an image to be filtered.
[0183] In some embodiments, the image generating device may further include an image checking unit, which may be specifically used to:
[0184] Encode the target image to obtain image features;
[0185] Perform linear transformation on image features to obtain the aesthetic score of the target image.
[0186] In some implementations, performing a linear transformation on image features to obtain an aesthetic score of a target image includes:
[0187] Obtain a linear prediction model, the linear prediction model comprising a first fully connected layer, a feature discarding layer, and a second fully connected layer;
[0188] Through the first fully connected layer, the image features are linearly transformed to obtain the first features;
[0189] Through the feature discarding layer, according to the preset discarding probability, the first feature is subjected to feature discarding processing to obtain the second feature;
[0190] Through the second fully connected layer, the second feature is linearly transformed to obtain the aesthetic score of the target image.
[0191] In specific implementation, the above units can be implemented as independent entities, or can be arbitrarily combined to be implemented as the same or several entities. The specific implementation of the above units can refer to the previous method embodiments, which will not be repeated here.
[0192] Therefore, the embodiment of the present application can improve the efficiency of obtaining a target image that matches the input text by dividing the input text into the first keyword and the second keyword. In the process of generating the target image, the image description sentence can be used as the main content (main feature) of the generated target image, and the second keyword can be used as the supplementary condition (supplementary feature) of the generated target image, and the target image can be directly generated based on the text after the combination of the two, thereby improving the efficiency of obtaining a target image that matches the input text. In addition, the main elements of the target image are determined by the image description sentence, and other features in the input text are retained by the second keyword, and the target image finally generated is affected, so that the target image is more consistent with the semantics of the input text, and the matching degree between the generated target image and the input text is improved.
[0193] Correspondingly, an embodiment of the present application also provides a computer device, which may be a terminal or a server, and the terminal may be a smart phone, a tablet computer, a laptop computer, a touch screen, a game console, a personal computer, a personal digital assistant (PDA), or other terminal devices.
[0194] like Figure 4 As shown, Figure 4 The schematic diagram of the structure of the computer device provided in the embodiment of the present application is that the computer device 400 includes a processor 410 having one or more processing cores, a memory 420 having one or more computer-readable storage media, and a computer program stored in the memory 420 and executable on the processor. The processor 410 is electrically connected to the memory 420. It can be understood by those skilled in the art that the computer device structure shown in the figure does not constitute a limitation on the computer device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0195] The processor 410 is the control center of the computer device 400. It uses various interfaces and lines to connect various parts of the entire computer device 400, executes various functions of the computer device 400 and processes data by running or loading software programs and / or modules stored in the memory 420, and calling data stored in the memory 420, thereby monitoring the computer device 400 as a whole.
[0196] In the embodiment of the present application, the processor 410 in the computer device 400 will load instructions corresponding to the processes of one or more application programs into the memory 420 according to the following steps, and the processor 410 will run the application programs stored in the memory 420 to implement various functions:
[0197] The input text is segmented to obtain multiple candidate words; from the multiple candidate words, at least one first keyword and at least one second keyword are determined, the first keyword is a candidate word among the multiple candidate words that satisfies a preset association relationship, and the second keyword is a candidate word among the multiple candidate words other than the first keyword; an image description sentence is generated from the first keyword; the image description sentence and the second keyword are combined to generate a target image according to the combined text.
[0198] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0199] Optional, such as Figure 4 As shown, the computer device 400 further includes: a touch screen 430, a radio frequency circuit 440, an audio circuit 450, an input unit 460, and a power supply 470. The processor 410 is electrically connected to the touch screen 430, the radio frequency circuit 440, the audio circuit 450, the input unit 460, and the power supply 470, respectively. Those skilled in the art will appreciate that Figure 4 The computer device structure shown in the figure does not constitute a limitation on the computer device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0200] The touch display screen 430 can be used to display a graphical user interface and receive operation instructions generated by the user acting on the graphical user interface. The touch display screen 430 may include a display panel and a touch panel. Among them, the display panel can be used to display information input by the user or information provided to the user and various graphical user interfaces of the computer device, which can be composed of graphics, text, icons, videos and any combination thereof. Optionally, the display panel can be configured in the form of a liquid crystal display (LCD, Liquid Crystal Display), an organic light-emitting diode (OLED, Organic Light-Emitting Diode), etc. The touch panel can be used to collect the user's touch operations on or near it (such as the user's operation on the touch panel or near the touch panel using any suitable object or accessory such as a finger, stylus, etc.), and generate corresponding operation instructions, and the operation instructions execute the corresponding program. Optionally, the touch panel may include two parts: a touch detection device and a touch controller. Among them, the touch detection device detects the user's touch orientation, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into the touch point coordinates, and then sends it to the processor 410, and can receive the command sent by the processor 410 and execute it. The touch panel can cover the display panel. When the touch panel detects a touch operation on or near it, it is transmitted to the processor 410 to determine the type of touch event, and then the processor 410 provides a corresponding visual output on the display panel according to the type of touch event. In an embodiment of the present application, the touch panel and the display panel can be integrated into the touch display screen 430 to realize the input and output functions. However, in some embodiments, the touch panel and the display panel can be used as two independent components to realize the input and output functions. That is, the touch display screen 430 can also be used as a part of the input unit 460 to realize the input function.
[0201] The radio frequency circuit 440 may be used to send and receive radio frequency signals, so as to establish wireless communication with a network device or other computer devices through wireless communication, and to send and receive signals between the network device or other computer devices.
[0202] The audio circuit 450 can be used to provide an audio interface between the user and the computer device through a speaker and a microphone. The audio circuit 450 can transmit the electrical signal converted from the received audio data to the speaker, which is converted into a sound signal for output; on the other hand, the microphone converts the collected sound signal into an electrical signal, which is received by the audio circuit 450 and converted into audio data, and then the audio data is output to the processor 410 for processing, and then sent to another computer device through the radio frequency circuit 440, or the audio data is output to the memory 420 for further processing. The audio circuit 450 may also include an earphone jack to provide communication between an external headset and the computer device.
[0203] The input unit 460 may be used to receive input numbers, character information or user feature information (such as fingerprint, iris, facial information, etc.), and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.
[0204] The power supply 470 is used to supply power to various components of the computer device 400. Optionally, the power supply 470 can be logically connected to the processor 410 through a power management system, so that the power management system can manage charging, discharging, and power consumption. The power supply 470 can also include one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, power status indicators, and other arbitrary components.
[0205] although Figure 4 Not shown, the computer device 400 may also include a camera, a sensor, a wireless fidelity module, a Bluetooth module, etc., which will not be described in detail here.
[0206] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0207] As can be seen from the above, the computer device provided in this embodiment can divide the input text into the first keyword and the second keyword. In the process of generating the target image, the image description sentence can be used as the main content (main feature) of generating the target image, and the second keyword can be used as the supplementary condition (supplementary feature) of generating the target image, and the target image can be directly generated based on the text after the combination of the two, thereby improving the efficiency of obtaining the target image that matches the input text. In addition, the main elements of the target image are determined by the image description sentence, and other features in the input text are retained by the second keyword, and the target image finally generated is affected, so that the target image is more consistent with the semantics of the input text, and the matching degree between the generated target image and the input text is improved.
[0208] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0209] To this end, an embodiment of the present application provides a computer-readable storage medium, in which multiple computer programs are stored, and the computer program can be loaded by a processor to execute the steps in any one of the image generation methods provided in the embodiments of the present application. For example, the computer program can execute the following steps:
[0210] The input text is segmented to obtain multiple candidate words; from the multiple candidate words, at least one first keyword and at least one second keyword are determined, the first keyword is a candidate word among the multiple candidate words that satisfies a preset association relationship, and the second keyword is a candidate word among the multiple candidate words other than the first keyword; an image description sentence is generated from the first keyword; the image description sentence and the second keyword are combined to generate a target image according to the combined text.
[0211] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0212] The storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0213] Since the computer program stored in the storage medium can execute the steps in any image generation method provided in the embodiments of the present application, the beneficial effects that can be achieved by any image generation method provided in the embodiments of the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.
[0214] The above is a detailed introduction to an image generation method, device, computer equipment and storage medium provided in the embodiments of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. An image generation method, characterized in that: include: Perform word segmentation on the input text to obtain multiple candidate words; Determine at least one first keyword and at least one second keyword from the multiple candidate words, wherein the first keyword is the candidate word among the multiple candidate words that satisfies a preset association relationship, and the second keyword is the candidate word among the multiple candidate words except the first keyword; Acquire an image description template, wherein the image description template includes at least one padding bit; Filling the first keyword into the filling position to obtain the image description sentence; Get the image generation model; combining the image description sentence and the second keyword to obtain a combined text; The combined text is input into the image generation model to generate a target image.
2. The image generation method according to claim 1, characterized in that: The preset association relationship includes a preset context association relationship, and determining at least one first keyword and at least one second keyword from the plurality of candidate words includes: Determining the contextual association relationship of the candidate words; Taking the candidate word whose context association relationship satisfies the preset context association relationship as the first keyword; The candidate words other than the first keyword among the plurality of candidate words are used as the second keyword.
3. The image generation method according to claim 1, wherein: After inputting the combined text into the image generation model to generate the target image, the method further includes: Calculating the similarity between the target image and a preset filter word; If the similarity is higher than a preset similarity threshold, the target image is determined as an image to be filtered.
4. The image generation method according to claim 1, wherein: After inputting the combined text into the image generation model to generate the target image, the method further includes: Performing encoding processing on the target image to obtain image features; Performing a linear transformation on the image features to obtain an aesthetic score of the target image.
5. The image generation method according to claim 4, characterized in that: The performing a linear transformation on the image features to obtain an aesthetic score of the target image includes: Acquire a linear prediction model, wherein the linear prediction model includes a first fully connected layer, a feature discarding layer, and a second fully connected layer; Performing a linear transformation on the image feature through the first fully connected layer to obtain a first feature; By means of the feature discarding layer, according to a preset discarding probability, the first feature is subjected to feature discarding processing to obtain a second feature; The second feature is linearly transformed through the second fully connected layer to obtain an aesthetic score of the target image.
6. The image generation method according to any one of claims 1 to 5, characterized in that: Before the word segmentation process is performed on the input text to obtain multiple candidate words, the process further includes: Get the initial text entered by the user; Performing word segmentation processing on the initial text to obtain multiple initial candidate words; Determining the text structure of the initial text according to the parts of speech of the multiple initial candidate words; If the text structure does not satisfy a preset text structure, a first prompt for the text structure is displayed so that the initial text is adjusted to the input text according to the first prompt.
7. The image generation method according to any one of claims 1 to 5, characterized in that: Before the word segmentation process is performed on the input text to obtain multiple candidate words, the process further includes: Get the initial text entered by the user; Determining the text type of the initial text according to the semantics of the initial text; If the text type is a specified text type, a second prompt for the specified text type is displayed so that the initial text is adjusted to the input text according to the second prompt.
8. An image generating device, characterized in that: include: A word segmentation processing unit, used to perform word segmentation on the input text to obtain multiple candidate words; A keyword determination unit, configured to determine at least one first keyword and at least one second keyword from the multiple candidate words, wherein the first keyword is a candidate word among the multiple candidate words that satisfies a preset association relationship, and the second keyword is a candidate word among the multiple candidate words other than the first keyword; A sentence generating unit is used to obtain an image description template, wherein the image description template includes at least one filling position; fill the first keyword in the filling position to obtain the image description sentence; An image generation unit, configured to obtain an image generation model; combine the image description sentence and the second keyword to obtain a combined text; The combined text is input into the image generation model to generate a target image.
9. A computer device, characterized in that: It comprises a processor and a memory, wherein the memory stores a plurality of instructions; the processor loads instructions from the memory to execute the steps in the image generation method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor to execute the steps in the image generation method according to any one of claims 1 to 7.
