Graphics and text generation method, device, computer equipment and storage medium
By extracting the features of images and texts and constructing an objective function that exchanges hidden states, the problem of low accuracy in image and text generation is solved and the accuracy of image and text generation is improved.
Patent Information
- Application Number
- CN202110610447.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-01
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2041-06-01
AI Technical Summary
The accuracy of image text generation and text image generation in the prior art is low, resulting in text generated from input images being less accurate than real text, and images generated from input text being less accurate than real images.
By obtaining the image and text to be converted, visual features and semantic features are extracted, and the image text objective function and the text image objective function are constructed, and the hidden states are exchanged to achieve the optimization parameter generation of the image and text objective function, and finally the text corresponding to the image to be converted is generated and the image corresponding to the text to be converted.
The accuracy of image and text generation is improved, and image text generation and text image generation are coupled and learned with each other, thereby improving the accuracy of the generation results.
Smart Images

Figure CN113223120B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of intelligent decision-making technology, and in particular to a method and device for generating images and texts, a computer device, and a storage medium. Background Art
[0002] With the rapid development of computer networks, LSTM (Long Short-Term Memory) networks have been widely used in image-to-text generation and text-to-image generation. In LSTM, an input sequence (including visual, semantic, and textual features) is mapped to a hidden state, which is then mapped to an output function using a recursive formula, ultimately resulting in text or an image. However, existing technologies often only perform the task of image-to-text generation or text-to-image generation individually, resulting in text generated from an input image being less accurate than the actual text. Similarly, images generated from input text are also less accurate than the actual image. Summary of the Invention
[0003] The embodiments of the present invention provide a method, apparatus, computer device and storage medium for generating images and texts, aiming to solve the problem of low accuracy in existing image and text generation.
[0004] In a first aspect, an embodiment of the present invention provides a method for generating a graphic and text, comprising:
[0005] Obtain the image and text to be converted;
[0006] Performing feature extraction on the image to be converted to obtain visual features and semantic features, and constructing an image-text objective function based on the visual features, the semantic features, the text to be converted, and the hidden state of the text image, wherein the text to be converted is a description language corresponding to the image to be converted, and the hidden state of the text image is a hidden state in a text image LSTM network;
[0007] Performing feature extraction on the text to be converted to obtain text features, and constructing a text image objective function based on the text features, the image to be converted after being adjusted to a preset size, and the image text hidden state, wherein the image text hidden state is a hidden state in the image text LSTM network;
[0008] Constructing an image-text objective function according to the image-text objective function and the text-image objective function, and generating image-text objective optimization parameters and text-image objective optimization parameters according to the image-text objective function after a preset number of iterations;
[0009] The text corresponding to the image to be converted and the image corresponding to the text to be converted are generated respectively according to the image-text target optimization parameters and the text-image target optimization parameters.
[0010] In a second aspect, an embodiment of the present invention further provides a graphic and text generating device, comprising:
[0011] An acquisition unit, used for acquiring an image to be converted and a text to be converted;
[0012] A first construction unit is configured to perform feature extraction on the image to be converted to obtain visual features and semantic features, and construct an image-text objective function based on the visual features, the semantic features, the text to be converted, and the hidden state of the text image, wherein the text to be converted is a description language corresponding to the image to be converted, and the hidden state of the text image is a hidden state in a text image LSTM network;
[0013] a second construction unit, configured to extract features of the text to be converted to obtain text features, and construct a text image objective function based on the text features, the image to be converted after being adjusted to a preset size, and an image text hidden state, wherein the image text hidden state is a hidden state in an image text LSTM network;
[0014] A first generating unit is configured to construct an image-text objective function according to the image-text objective function and the text-image objective function, and generate an image-text objective optimization parameter and a text-image objective optimization parameter according to the image-text objective function after a preset number of iterations;
[0015] The second generating unit is configured to generate text corresponding to the image to be converted and an image corresponding to the text to be converted according to the image-text target optimization parameter and the text-image target optimization parameter respectively.
[0016] In a third aspect, an embodiment of the present invention further provides a computer device, which includes a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the above method when executing the computer program.
[0017] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the storage medium stores a computer program, and the computer program can implement the above method when executed by a processor.
[0018] An embodiment of the present invention provides a method, apparatus, computer device, and storage medium for generating images and texts. The method comprises: obtaining an image to be converted and text to be converted; performing feature extraction on the image to be converted to obtain visual features and semantic features, and constructing an image-text objective function based on the visual features, the semantic features, the text to be converted, and a text image hidden state, wherein the text to be converted is a description language corresponding to the image to be converted, and the text image hidden state is a hidden state in a text-image LSTM network; performing feature extraction on the text to be converted to obtain text features, and constructing a text-image objective function based on the text features, the image to be converted after being resized to a preset size, and the image-text hidden state, wherein the image-text hidden state is a hidden state in the image-text LSTM network; constructing an image-text objective function based on the image-text objective function and the text-image objective function, and generating image-text objective optimization parameters and text-image objective optimization parameters based on the image-text objective function after a preset number of iterations; and generating text corresponding to the image to be converted and an image corresponding to the text to be converted based on the image-text objective optimization parameters and the text-image objective optimization parameters, respectively. The technical solution of the embodiment of the present invention, during the image-text generation process, exchanges the hidden state of the image text and the hidden state of the text image, so that the image text generation and the text image generation can be coupled and learned with each other, thereby improving the accuracy of image-text generation. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0020] Figure 1 A flowchart of a method for generating images and texts provided by an embodiment of the present invention;
[0021] Figure 2 A schematic diagram of a sub-process of a method for generating images and texts provided by an embodiment of the present invention;
[0022] Figure 3 A schematic diagram of a sub-process of a method for generating images and texts provided by an embodiment of the present invention;
[0023] Figure 4 A schematic diagram of a sub-process of a method for generating images and texts provided by an embodiment of the present invention;
[0024] Figure 5 A schematic diagram of a sub-process of a method for generating images and texts provided by an embodiment of the present invention;
[0025] Figure 6 A schematic block diagram of a device for generating images and texts according to an embodiment of the present invention;
[0026] Figure 7 A schematic block diagram of a first construction unit of the image-text generation device provided in an embodiment of the present invention;
[0027] Figure 8 A schematic block diagram of a second construction unit of the image-text generation device provided in an embodiment of the present invention;
[0028] Figure 9 A schematic block diagram of a first generating unit of the image and text generating device provided in an embodiment of the present invention;
[0029] Figure 10 A schematic block diagram of a second generating unit of the image and text generating device provided by an embodiment of the present invention; and
[0030] Figure 11 A schematic block diagram of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0031] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0032] It will be understood that when used in this specification and the appended claims, the terms “comprises” and “comprising” indicate the presence of described features, integers, steps, operations, elements and / or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof.
[0033] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the present invention. As used in the specification and appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms unless the context clearly indicates otherwise.
[0034] It should be further understood that the term "and / or" used in the present description and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
[0035] As used in this specification and the appended claims, the term "if" can be interpreted as "when" or "upon" or "in response to determining" or "in response to detecting," depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "upon determination" or "in response to determining" or "upon detection of [described condition or event]" or "in response to detecting [described condition or event]," depending on the context.
[0036] See also Figure 1 , Figure 1 This is a flow chart of a method for generating text and images provided by an embodiment of the present invention. The method for generating text and images according to the embodiment of the present invention can be applied to a server. For example, the method for generating text and images can be implemented by a software program configured on the server to improve the accuracy of text and image generation. Figure 2 As shown, the method includes the following steps S100-S140.
[0037] S100: Obtain an image to be converted and a text to be converted.
[0038] In an embodiment of the present invention, to achieve image-text generation, the server must first obtain the image to be converted and the text to be converted, and then perform a series of processing based on the image to be converted and the text to be converted before achieving image-text generation. In an embodiment of the present invention, the user can upload the image to be converted and the text to be converted through the user terminal. Specifically, the user can upload the image to be converted and the text to be converted through the image-text webpage of the user terminal to send the image to be converted and the text to be converted to the server.
[0039] S110. Perform feature extraction on the image to be converted to obtain visual features and semantic features, and construct an image-text objective function based on the visual features, the semantic features, the text to be converted, and the hidden state of the text image, wherein the text to be converted is a description language corresponding to the image to be converted, and the hidden state of the text image is a hidden state in the text image LSTM network.
[0040] In an embodiment of the present invention, after obtaining the image to be converted and the text to be converted, the image to be converted is first subjected to feature extraction to obtain visual features and semantic features. It is understandable that the semantic features are the description language of the image to be converted. After obtaining the visual features and the semantic features, an image-text objective function is constructed based on the visual features, the semantic features, the text to be converted, and the hidden state of the text image, wherein the text to be converted is the description language corresponding to the image to be converted, and the hidden state of the text image is the hidden state in the text image LSTM network. In actual applications, an image-text output function is first constructed based on the visual features, the semantic features, and the text to be converted, and then, after a series of processing, an image-text objective function is constructed.
[0041] See also Figure 2 In one embodiment, for example, in an embodiment of the present invention, step S110 includes the following steps S111-S114.
[0042] S111. extracting features of the image to be converted by a convolutional neural network model to obtain visual features and semantic features;
[0043] S112, constructing an image-text output function through the image-text LSTM network according to the visual features, the semantic features, the text to be converted, and the hidden state of the image-text LSTM network;
[0044] S113, constructing an image-text distance function according to the image-text hidden state and the text-image hidden state;
[0045] S114: Construct an image-text target function according to the image-text output function and the image-text distance function.
[0046] In an embodiment of the present invention, after obtaining the image to be converted and the text to be converted, a convolutional neural network model is first used to extract features from the image to be converted to obtain visual features and semantic features, wherein the visual features and the semantic features are both vectors of preset dimensions. After extracting the visual features and the semantic features, an image-text output function is constructed using the image-text LSTM network based on the visual features, the semantic features, the text to be converted, and the hidden state of the image-text LSTM network. It can be understood that the image-text output function is a Softmax function, which is used to select the words with the highest probability in the image-text LSTM network and connect them into a descriptive sentence. After constructing the image-text output function, an image-text distance function is constructed based on the image-text hidden state and the text-image hidden state. Specifically, the difference between the image-text hidden state and the text-image hidden state is first calculated, and then the difference is squared to obtain the image-text square value. Finally, the image-text square value is divided by the cosine distance between the image-text hidden state and the text-image hidden state to obtain the image-text distance function. After constructing the image-text distance function, an image-text target function is constructed based on the image-text output function and the image-text distance function. It is understandable that in this embodiment of the present invention, the constructed image-text target function is the sum of the log-likelihoods of the visual features, the semantic features, and the hidden state of the text image.
[0047] S120. Perform feature extraction on the text to be converted to obtain text features, and construct a text image objective function based on the text features, the image to be converted after being adjusted to a preset size, and the image text hidden state, wherein the image text hidden state is a hidden state in the image text LSTM network.
[0048] In an embodiment of the present invention, after constructing the image-text objective function, feature extraction is performed on the text to be converted to obtain text features. A text-image objective function is then constructed based on the text features, the image to be converted after being resized to a preset size, and the image-text hidden state. The preset size is 32×32×3, i.e., the input image to be converted is 32×32×3; the image-text hidden state is the hidden state in the image-text LSTM network. Understandably, the text-image objective function and the image-text objective function interchange the hidden states to facilitate dynamic learning of their respective attributes and better generate text and images.
[0049] See also Figure 3 In one embodiment, for example, in an embodiment of the present invention, step S110 includes the following steps S121-S124.
[0050] S121, performing feature extraction on the text to be converted using a bidirectional recurrent neural network model to obtain text features;
[0051] S122, constructing a text image output function through the text image LSTM network according to the text features, the image to be converted after being adjusted to a preset size, and the hidden state of the text image;
[0052] S123, constructing a text-image distance function according to the text-image hidden state and the image-text hidden state;
[0053] S124: Construct a text image target function according to the text image output function and the text image distance function.
[0054] In an embodiment of the present invention, after constructing the image-text target function, the text to be converted is first subjected to feature extraction using a bidirectional recurrent neural network model to obtain text features, wherein the text features are vectors of a preset dimension. A text-image output function is constructed using the text-image LSTM network based on the text features, the image to be converted after being adjusted to a preset size, and the text-image hidden state. The text-image output function is a Write function, which writes the text-image hidden state to a canvas, which is then aggregated using a sigmoid function to reduce the Bernoulli distribution, thereby obtaining an image of a preset dimension. After constructing the text-image output function, a text-image distance function is constructed based on the text-image hidden state and the image-text hidden state. Specifically, the difference between the text-image hidden state and the image-text hidden state is first calculated, the difference is then squared to obtain the image-text square value, and finally the image-text square value is divided by the cosine distance between the text-image hidden state and the image-text hidden state to obtain the text-image distance function. After constructing the text-image distance function, a text-image target function is constructed based on the text-image output function and the text-image distance function. It can be understood that in the embodiment of the present invention, the constructed text image objective function is to solve the lower bound of the output image based on the input text feature vector and the hidden state of the image text.
[0055] S130 , constructing an image-text objective function according to the image-text objective function and the text-image objective function, and generating image-text objective optimization parameters and text-image objective optimization parameters according to the image-text objective function after a preset number of iterations.
[0056] In an embodiment of the present invention, after constructing the image-text objective function and the text-image objective function, a graphic-text objective function will be constructed based on the image-text objective function and the text-image objective function. It is understandable that the graphic-text objective function is a function of seven parameters including the visual features, the voice features, the text features, the image to be converted after adjusting to a preset size, image-text parameters, and text-image parameters. After the graphic-text objective function is constructed, the image-text objective optimization parameters and the text-image objective optimization parameters are generated based on the graphic-text objective function after a preset number of iterations. The preset number of iterations can be arbitrarily set according to actual needs. It is understandable that the image-text objective optimization parameters and the text-image objective optimization parameters are the corresponding parameters after the image-text parameters and the text-image parameters are optimized.
[0057] See also Figure 4 In one embodiment, for example, in an embodiment of the present invention, step S130 includes the following steps S131-S134.
[0058] S131, respectively expressing the parameters in the image-text objective function and the text-image objective function as image-text parameters and text-image parameters using preset symbols, and constructing the image-text objective function based on the image-text parameters and the text-image parameters;
[0059] S132, respectively obtaining the text image hidden state and the image text hidden state according to the image text parameter and the text image parameter in the image-text objective function;
[0060] S133, replacing the value of the image text hidden state with the value of the text image hidden state and substituting it into the image text output function and the image text distance function to optimize the image text parameters in the image text target function;
[0061] S134, replacing the value of the text image hidden state with the value of the image text hidden state and substituting it into the text image output function and the text image distance function to optimize the text image parameters in the text image target function;
[0062] S135 . Generate the image-text target optimization parameters and the text-image target optimization parameters corresponding to the image-text parameters and the text-image parameters respectively after a preset number of generations.
[0063] In an embodiment of the present invention, after constructing the image-text objective function and the text-image objective function, the parameters in the image-text objective function and the text-image objective function are respectively represented by preset symbols as image-text parameters and text-image parameters, wherein the preset symbol is θ. In an embodiment of the present invention, the image-text parameter can be represented as θi2t , the text image parameters can be expressed as θ 2ti . And construct an image-text objective function based on the image-text parameters and the text-image parameters. Specifically, the image-text objective function is constructed based on the visual features, the semantic features, the text features, the image to be converted after adjusting to a preset size, the image-text parameters and the text-image parameters. According to the image-text parameters and the text-image parameters in the image-text objective function, the text-image hidden state and the image-text hidden state are respectively obtained; according to the text-image hidden state and the image-text hidden state, the image-text objective optimization parameters and the text-image objective optimization parameters are respectively generated after a preset number of generations. Specifically, the value of the image-text hidden state is replaced by the value of the text-image hidden state and substituted into the image-text output function and the image-text distance function to optimize the image-text parameters in the image-text objective function; the value of the text-image hidden state is replaced by the value of the image-text hidden state and substituted into the text-image output function and the text-image distance function to optimize the text-image parameters in the text-image objective function. It can be understood that the image-text parameters and the text-image parameters are optimized in a gradient descent manner. After a preset number of generations, the image-text target optimization parameters and the text-image target optimization parameters corresponding to the image-text parameters and the text-image parameters are generated respectively.
[0064] S140 : Generate text corresponding to the image to be converted and an image corresponding to the text to be converted according to the image-text target optimization parameters and the text-image target optimization parameters, respectively.
[0065] In an embodiment of the present invention, after the image-text target optimization parameters and the text-image target optimization parameters are generated, text corresponding to the image to be converted and an image corresponding to the text to be converted are generated based on the image-text target optimization parameters and the text-image target optimization parameters, respectively. Specifically, the corresponding text-image hidden state is obtained based on the image-text target optimization parameters, and the corresponding image-text hidden state is obtained based on the text-image target optimization parameters. Then, text is generated based on the image-text hidden state, and an image is generated based on the text-image hidden state.
[0066] See also Figure 5 In one embodiment, for example, in an embodiment of the present invention, step S130 includes the following steps S141-S143.
[0067] S141, respectively obtaining the corresponding text image hidden state and the image text hidden state according to the image text target optimization parameter and the text image target optimization parameter;
[0068] S142, substituting the image text hidden state into a Softmax function to generate text corresponding to the image to be converted;
[0069] S143: Substitute the hidden state of the text image into a Write function to generate an image corresponding to the text to be converted.
[0070] In an embodiment of the present invention, after generating the image-text target optimization parameters and the text-image target optimization parameters, the corresponding text image hidden state and the image text hidden state are respectively obtained according to the image-text target optimization parameters and the text-image target optimization parameters; the text corresponding to the image to be converted is generated according to the image-text hidden state and the image-text output function, specifically, the image-text hidden state is substituted into the Softmax function to generate the text corresponding to the image to be converted; the image corresponding to the text to be converted is generated according to the text image hidden state and the text image output function, specifically, the text image hidden state is substituted into the Write function to generate the image corresponding to the text to be converted.
[0071] Figure 6 1 is a schematic block diagram of a graphic and text generating device 200 provided by an embodiment of the present invention. Figure 6 As shown, corresponding to the above image and text generation method, the present invention also provides an image and text generation device 200. The image and text generation device 200 includes a unit for executing the above image and text generation method, and the device can be configured in a server. Figure 6 The image and text generating device 200 includes an acquiring unit 201 , a first constructing unit 202 , a second constructing unit 203 , a first generating unit 204 and a second generating unit 205 .
[0072] Wherein, the acquisition unit 201 is used to acquire the image to be converted and the text to be converted; the first construction unit 202 is used to perform feature extraction on the image to be converted to obtain visual features and semantic features, and construct an image-text objective function based on the visual features, the semantic features, the text to be converted, and the text image hidden state, wherein the text to be converted is the description language corresponding to the image to be converted, and the text image hidden state is the hidden state in the text image LSTM network; the second construction unit 203 is used to perform feature extraction on the text to be converted to obtain text features, and construct a text image objective function based on the text features, the image to be converted after being adjusted to a preset size, and the image text hidden state, wherein the image text hidden state is the hidden state in the image text LSTM network;
[0073] The first generation unit 204 is used to construct an image-text objective function based on the image-text objective function and the text-image objective function, and generate image-text objective optimization parameters and text-image objective optimization parameters based on the image-text objective function after a preset number of iterations; the second generation unit 205 is used to generate text corresponding to the image to be converted and an image corresponding to the text to be converted respectively based on the image-text objective optimization parameters and the text-image objective optimization parameters.
[0074] In some embodiments, such as the present embodiment, Figure 7 As shown, the first construction unit 202 includes a first extraction unit 2021 , a first construction subunit 2022 , a second construction subunit 2023 and a third construction subunit 2024 .
[0075] Among them, the first extraction unit 2021 is used to extract features of the image to be converted through a convolutional neural network model to obtain visual features and semantic features; the first construction subunit 2022 is used to construct an image-text output function through the image-text LSTM network according to the visual features, the semantic features, the text to be converted and the hidden state of the image-text LSTM network; the second construction subunit 2023 is used to construct an image-text distance function according to the image-text hidden state and the text image hidden state; the third construction subunit 2024 is used to construct an image-text target function according to the image-text output function and the image-text distance function.
[0076] In some embodiments, such as the present embodiment, Figure 8 As shown, the second construction unit 203 includes a second extraction unit 2031 , a fourth construction subunit 2032 , a fifth construction subunit 2033 and a sixth construction subunit 2034 .
[0077] Among them, the second extraction unit 2031 is used to extract features of the text to be converted through a bidirectional recurrent neural network model to obtain text features; the fourth construction subunit 2032 is used to construct a text image output function through the text image LSTM network according to the text features, the image to be converted after adjusting to a preset size, and the text image hidden state; the fifth construction subunit 2033 is used to construct a text image distance function according to the text image hidden state and the image text hidden state; the sixth construction subunit 2034 is used to construct a text image target function according to the text image output function and the text image distance function.
[0078] In some embodiments, such as the present embodiment, Figure 9As shown, the first generating unit 204 includes a seventh constructing subunit 2041 , a first acquiring subunit 2042 , a first optimizing unit 2043 , a second optimizing unit 2044 and a first generating subunit 2045 .
[0079] Among them, the seventh construction subunit 2041 is used to represent the parameters in the image-text objective function and the text-image objective function as image-text parameters and text-image parameters respectively using preset symbols, and construct the image-text objective function based on the image-text parameters and the text-image parameters; the first acquisition subunit 2042 is used to respectively obtain the text-image hidden state and the image-text hidden state according to the image-text parameters and the text-image parameters in the image-text objective function; the first optimization unit 2043 is used to replace the value of the image-text hidden state with the value of the text-image hidden state and substitute it into the image-text output function and the image-text distance function to optimize the image-text parameters in the image-text objective function; the second optimization unit 2044 is used to replace the value of the text-image hidden state with the value of the image-text hidden state and substitute it into the text-image output function and the text-image distance function to optimize the text-image parameters in the text-image objective function; the first generation subunit 2045 is used to generate the image-text target optimization parameters and text-image target optimization parameters corresponding to the image-text parameters and the text-image parameters respectively after a preset number of generations.
[0080] In some embodiments, such as the present embodiment, Figure 10 As shown, the second generating unit 205 includes a second acquiring subunit 2051 , a second generating subunit 2052 and a third generating subunit 2053 .
[0081] Among them, the second acquisition subunit 2051 is used to obtain the corresponding text image hidden state and the image text hidden state according to the image text target optimization parameters and the text image target optimization parameters respectively; the second generation subunit 2052 is used to substitute the image text hidden state into the Softmax function to generate the text corresponding to the image to be converted; the third generation subunit 2053 is used to substitute the text image hidden state into the Write function to generate the image corresponding to the text to be converted.
[0082] The above-mentioned graphic and text generating device can be implemented in the form of a computer program. The computer program can be used in Figure 11 Runs on the computer equipment shown.
[0083] See also Figure 11 , Figure 113 is a schematic block diagram of a computer device provided in an embodiment of the present application. The computer device 300 is a server, specifically, the server can be an independent server or a server cluster composed of multiple servers.
[0084] See Figure 11 The computer device 300 includes a processor 302 , a memory, and a network interface 305 connected via a system bus 301 , wherein the memory may include a storage medium 303 and an internal memory 304 .
[0085] The storage medium 303 may store an operating system 3031 and a computer program 3032. When the computer program 3032 is executed, the processor 302 may execute a method for generating graphics and text.
[0086] The processor 302 is used to provide computing and control capabilities to support the operation of the entire computer device 300.
[0087] The internal memory 304 provides an environment for the operation of the computer program 3032 in the storage medium 303. When the computer program 3032 is executed by the processor 302, the processor 302 can execute a graphic and text generation method.
[0088] The network interface 305 is used to communicate with other devices through the network. Figure 11 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device 300 to which the solution of the present application is applied. The specific computer device 300 may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
[0089] The processor 302 is configured to run a computer program 3032 stored in a memory to implement the following steps: obtaining an image to be converted and a text to be converted; performing feature extraction on the image to be converted to obtain visual features and semantic features, and constructing an image-text objective function based on the visual features, the semantic features, the text to be converted, and the text image hidden state, wherein the text to be converted is a description language corresponding to the image to be converted, and the text image hidden state is a hidden state in a text-image LSTM network; performing feature extraction on the text to be converted to obtain text features, and constructing a text-image objective function based on the text features, the image to be converted after being adjusted to a preset size, and the image-text hidden state, wherein the image-text hidden state is a hidden state in an image-text LSTM network; constructing an image-text objective function based on the image-text objective function and the text-image objective function, and generating image-text objective optimization parameters and text-image objective optimization parameters based on the image-text objective function after a preset number of iterations; and generating text corresponding to the image to be converted and an image corresponding to the text to be converted respectively based on the image-text objective optimization parameters and the text-image objective optimization parameters.
[0090] In certain embodiments, such as the present embodiment, the processor 302, when implementing the step of performing feature extraction on the image to be converted to obtain visual features and semantic features, and constructing an image-text target function based on the visual features, the semantic features, the text to be converted, and the hidden state of the text image, specifically implements the following steps: performing feature extraction on the image to be converted through a convolutional neural network model to obtain visual features and semantic features; constructing an image-text output function through the image-text LSTM network based on the visual features, the semantic features, the text to be converted, and the hidden state of the image-text LSTM network; constructing an image-text distance function based on the image-text hidden state and the text image hidden state; and constructing an image-text target function based on the image-text output function and the image-text distance function.
[0091] In certain embodiments, such as the present embodiment, the processor 302, when implementing the step of extracting features from the text to be converted to obtain text features, and constructing a text image target function based on the text features, the image to be converted after adjusting to a preset size, and the image text hidden state, specifically implements the following steps: extracting features from the text to be converted through a bidirectional recurrent neural network model to obtain text features; constructing a text image output function through the text image LSTM network based on the text features, the image to be converted after adjusting to a preset size, and the text image hidden state; constructing a text image distance function based on the text image hidden state and the image text hidden state; and constructing a text image target function based on the text image output function and the text image distance function.
[0092] In certain embodiments, such as the present embodiment, when the processor 302 implements the steps of constructing an image-text objective function according to the image-text objective function and the text-image objective function, and generating image-text objective optimization parameters and text-image objective optimization parameters according to the image-text objective function after a preset number of iterations, the processor 302 specifically implements the following steps: representing the parameters in the image-text objective function and the text-image objective function as image-text parameters and text-image parameters using preset symbols, respectively, and constructing an image-text objective function according to the image-text parameters and the text-image parameters; respectively obtaining the text-image parameters according to the image-text parameters and the text-image parameters in the image-text objective function. This image hidden state and the image text hidden state; replacing the value of the image text hidden state with the value of the text image hidden state and substituting it into the image text output function and the image text distance function to optimize the image text parameters in the image text target function; replacing the value of the text image hidden state with the value of the image text hidden state and substituting it into the text image output function and the text image distance function to optimize the text image parameters in the text image target function; after a preset number of generations, generating the image text target optimization parameters and text image target optimization parameters corresponding to the image text parameters and the text image parameters respectively.
[0093] In certain embodiments, such as the present embodiment, when the processor 302 implements the step of generating the text corresponding to the image to be converted and the image corresponding to the text to be converted according to the image-text target optimization parameters and the text-image target optimization parameters, it specifically implements the following steps: obtaining the corresponding text image hidden state and the image text hidden state according to the image-text target optimization parameters and the text-image target optimization parameters; substituting the image text hidden state into the Softmax function to generate the text corresponding to the image to be converted; substituting the text image hidden state into the Write function to generate the image corresponding to the text to be converted.
[0094] It should be understood that in the embodiment of the present application, the processor 302 may be a central processing unit (CPU), and the processor 302 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0095] Those skilled in the art will appreciate that all or part of the steps in the method of the above-described embodiment can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. The computer program is executed by at least one processor in the computer system to implement the steps in the method of the above-described embodiment.
[0096] Therefore, the present invention further provides a storage medium. The storage medium may be a computer-readable storage medium. The storage medium stores a computer program. When the computer program is executed by a processor, the processor executes the following steps: obtaining an image to be converted and a text to be converted; performing feature extraction on the image to be converted to obtain visual features and semantic features, and constructing an image-text objective function based on the visual features, the semantic features, the text to be converted, and the text image hidden state, wherein the text to be converted is a description language corresponding to the image to be converted, and the text image hidden state is a hidden state in a text-image LSTM network; performing feature extraction on the text to be converted to obtain text features, and constructing a text-image objective function based on the text features, the image to be converted after being adjusted to a preset size, and the image-text hidden state, wherein the image-text hidden state is a hidden state in the image-text LSTM network; constructing an image-text objective function based on the image-text objective function and the text-image objective function, and generating image-text objective optimization parameters and text-image objective optimization parameters based on the image-text objective function after a preset number of iterations; and generating text corresponding to the image to be converted and an image corresponding to the text to be converted based on the image-text objective optimization parameters and the text-image objective optimization parameters, respectively.
[0097] In certain embodiments, such as the present embodiment, when the processor executes the computer program to implement the steps of extracting features from the image to be converted to obtain visual features and semantic features, and constructing an image-text target function based on the visual features, the semantic features, the text to be converted, and the hidden state of the text image, the following steps are specifically implemented: extracting features from the image to be converted through a convolutional neural network model to obtain visual features and semantic features; constructing an image-text output function through the image-text LSTM network based on the visual features, the semantic features, the text to be converted, and the hidden state of the image-text LSTM network; constructing an image-text distance function based on the image-text hidden state and the text image hidden state; and constructing an image-text target function based on the image-text output function and the image-text distance function.
[0098] In certain embodiments, such as the present embodiment, when the processor executes the computer program to implement the steps of extracting features from the text to be converted to obtain text features, and constructing a text image target function based on the text features, the image to be converted after adjusting to a preset size, and the image text hidden state, the processor specifically implements the following steps: extracting features from the text to be converted through a bidirectional recurrent neural network model to obtain text features; constructing a text image output function through the text image LSTM network based on the text features, the image to be converted after adjusting to a preset size, and the text image hidden state; constructing a text image distance function based on the text image hidden state and the image text hidden state; and constructing a text image target function based on the text image output function and the text image distance function.
[0099] In certain embodiments, such as the present embodiment, when the processor executes the computer program to implement the steps of constructing an image-text objective function according to the image-text objective function and the text-image objective function, and generating image-text objective optimization parameters and text-image objective optimization parameters according to the image-text objective function after a preset number of iterations, the processor specifically implements the following steps: respectively representing the parameters in the image-text objective function and the text-image objective function as image-text parameters and text-image parameters using preset symbols, and constructing an image-text objective function according to the image-text parameters and the text-image parameters; respectively generating image-text parameters according to the image-text parameters and the text-image parameters in the image-text objective function. Obtain the text image hidden state and the image text hidden state; replace the value of the image text hidden state with the value of the text image hidden state and substitute it into the image text output function and the image text distance function to optimize the image text parameters in the image text target function; replace the value of the text image hidden state with the value of the image text hidden state and substitute it into the text image output function and the text image distance function to optimize the text image parameters in the text image target function; generate the image text target optimization parameters and text image target optimization parameters corresponding to the image text parameters and the text image parameters respectively after a preset number of generations.
[0100] In certain embodiments, such as the present embodiment, when the processor executes the computer program to implement the steps of generating the text corresponding to the image to be converted and the image corresponding to the text to be converted according to the image-text target optimization parameters and the text-image target optimization parameters, the processor specifically implements the following steps: obtaining the corresponding text image hidden state and the image text hidden state according to the image-text target optimization parameters and the text-image target optimization parameters; substituting the image text hidden state into the Softmax function to generate the text corresponding to the image to be converted; substituting the text image hidden state into the Write function to generate the image corresponding to the text to be converted.
[0101] The storage medium may be any computer-readable storage medium that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a magnetic disk, or an optical disk.
[0102] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the composition and steps of each example according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0103] In the several embodiments provided herein, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the various units is merely a logical functional division, and actual implementation may employ other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be omitted or not implemented.
[0104] The steps in the methods of the embodiments of the present invention may be adjusted in order, combined, or deleted as needed. The units in the devices of the embodiments of the present invention may be combined, divided, or deleted as needed. Furthermore, the functional units in the various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit.
[0105] If this integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the existing technology, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes a number of instructions for causing a computer device (which can be a personal computer, terminal, or network device, etc.) to execute all or part of the steps of the method described in various embodiments of the present invention.
[0106] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0107] Obviously, those skilled in the art may make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, to the extent such changes and modifications fall within the scope of the claims and their equivalents, the present invention is intended to include such changes and modifications.
[0108] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and such modifications or substitutions are intended to be within the scope of protection of the present invention. Therefore, the scope of protection of the present invention shall be subject to the scope of protection of the claims.
Claims
1. A method for generating images and texts, characterized in that: include: Obtain the image to be converted and the text to be converted; Performing feature extraction on the image to be converted to obtain visual features and semantic features, and constructing an image-text objective function according to the visual features, the semantic features, the text to be converted, and the hidden state of the text image, wherein the text to be converted is a description language corresponding to the image to be converted, and the hidden state of the text image is a hidden state in a text image LSTM network; Performing feature extraction on the text to be converted to obtain text features, and constructing a text image objective function according to the text features, the image to be converted after being adjusted to a preset size, and the image text hidden state, wherein the image text hidden state is a hidden state in an image text LSTM network; Constructing an image-text objective function according to the image-text objective function and the text-image objective function, and generating an image-text objective optimization parameter and a text-image objective optimization parameter according to the image-text objective function after a preset number of iterations; The text corresponding to the image to be converted and the image corresponding to the text to be converted are generated respectively according to the image-text target optimization parameters and the text-image target optimization parameters.
2. The method according to claim 1, characterized in that The feature extraction of the image to be converted to obtain visual features and semantic features, and constructing an image-text objective function according to the visual features, the semantic features, the text to be converted and the hidden state of the text image, includes: The convolutional neural network model is used to extract features of the image to be converted to obtain visual features and semantic features; Constructing an image-text output function through the image-text LSTM network according to the visual features, the semantic features, the text to be converted, and the hidden state of the image-text LSTM network; Constructing an image-text distance function according to the image-text hidden state and the text-image hidden state; An image-text target function is constructed according to the image-text output function and the image-text distance function.
3. The method according to claim 2, characterized in that The feature extraction of the text to be converted is performed to obtain text features, and a text image objective function is constructed according to the text features, the image to be converted after being adjusted to a preset size, and the image text hidden state, including: Performing feature extraction on the text to be converted by using a bidirectional recurrent neural network model to obtain text features; Constructing a text image output function through the text image LSTM network according to the text features, the image to be converted after being adjusted to a preset size, and the hidden state of the text image; Constructing a text-image distance function according to the text-image hidden state and the image-text hidden state; A text image target function is constructed according to the text image output function and the text image distance function.
4. The method according to claim 3, characterized in that The step of constructing a text-image target function according to the text-image target function and the text-image target function, and generating an image-text target optimization parameter and a text-image target optimization parameter according to the text-image target function after a preset number of iterations, includes: Representing the parameters in the image-text objective function and the text-image objective function as image-text parameters and text-image parameters respectively using preset symbols, and constructing the image-text objective function according to the image-text parameters and the text-image parameters; According to the image text parameter and the text image parameter in the image-text objective function, respectively, the text image hidden state and the image text hidden state are obtained; The image-text target optimization parameter and the text-image target optimization parameter are respectively generated after a preset number of generations according to the text-image hidden state and the image-text hidden state.
5. The method according to claim 4, characterized in that The method of generating the image text target optimization parameter and the text image target optimization parameter respectively according to the text image hidden state and the image text hidden state after a preset number of generations includes: Replacing the value of the image text hidden state with the value of the text image hidden state and substituting it into the image text output function and the image text distance function to optimize the image text parameter in the image text objective function; Replacing the value of the hidden state of the text image with the value of the hidden state of the image text and substituting it into the text image output function and the text image distance function to optimize the text image parameters in the text image objective function; The image-text target optimization parameters and the text-image target optimization parameters corresponding to the image-text parameters and the text-image parameters are generated respectively after a preset number of generations.
6. The method according to claim 5, characterized in that The step of respectively generating the text corresponding to the image to be converted and the image corresponding to the text to be converted according to the image text target optimization parameter and the text image target optimization parameter comprises: According to the image text target optimization parameter and the text image target optimization parameter, respectively obtain the corresponding text image hidden state and the image text hidden state; The text corresponding to the image to be converted and the image corresponding to the text to be converted are generated respectively according to the image text hidden state and the image text output function, and the text image hidden state and the text image output function.
7. The method according to claim 6, characterized in that The generating of the text corresponding to the image to be converted and the image corresponding to the text to be converted respectively according to the image text hidden state and the image text output function, the text image hidden state and the text image output function comprises: Substituting the image text hidden state into the Softmax function to generate text corresponding to the image to be converted; The hidden state of the text image is substituted into the Write function to generate an image corresponding to the text to be converted.
8. A graphic and text generating device, characterized in that: include: An acquisition unit, used for acquiring an image to be converted and a text to be converted; A first construction unit is used to extract features of the image to be converted to obtain visual features and semantic features, and to construct an image-text objective function according to the visual features, the semantic features, the text to be converted, and the hidden state of the text image, wherein the text to be converted is a description language corresponding to the image to be converted, and the hidden state of the text image is a hidden state in a text image LSTM network; A second construction unit is used to extract features of the text to be converted to obtain text features, and to construct a text image objective function according to the text features, the image to be converted after being adjusted to a preset size, and the image text hidden state, wherein the image text hidden state is a hidden state in an image text LSTM network; A first generating unit is used to construct an image-text objective function according to the image-text objective function and the text-image objective function, and generate an image-text objective optimization parameter and a text-image objective optimization parameter according to the image-text objective function after a preset number of iterations; The second generating unit is used to generate text corresponding to the image to be converted and an image corresponding to the text to be converted according to the image text target optimization parameter and the text image target optimization parameter respectively.
9. A computer device, characterized in that: The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 can be implemented.
