Template Generation Method, Apparatus, Storage Medium and Electronic Device
By training specific sample sets and random sample data on the target neural network model, the stability and creativity of the template generation model when there are insufficient samples are solved, and efficient and stable template generation is achieved.
Patent Information
- Application Number
- CN202111306954.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-05
- Publication Date
- 2025-07-11
- Estimated Expiration
- 2041-11-05
AI Technical Summary
In the prior art, the processing efficiency of the template generation model is low, especially when the sample data is insufficient, the generated template stability and creativity are difficult to balance.
The target neural network model is trained through at least one sample set, and a pre-trained template generation model is generated to ensure that the difference in the random sample data in each sample set is less than the threshold, and further trained through multiple random sample data to improve model stability.
While maintaining the creativeness of the template generation model, it significantly improves its stability and generation efficiency.
Smart Images

Figure CN114037883B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technologies, and in particular, to a template generation method, apparatus, storage medium, and electronic device. Background Art
[0002] Currently, in the field of image processing technologies, it is often necessary to first train a template generation model, and generate a corresponding template through the template generation model to improve the efficiency of image processing. The processing efficiency of the template generation model often depends on the training data set and training method thereof. How to improve the processing efficiency of the template generation model has become an urgent problem to be solved. Summary of the Invention
[0003] To overcome the problems existing in the related art, the present disclosure provides a template generation method, apparatus, storage medium, and electronic device.
[0004] According to a first aspect of an embodiment of the present disclosure, a template generation method is provided, and the method includes:
[0005] Generating random data in response to a received template generation instruction;
[0006] Inputting the random data into a pre-trained template generation model to output a target template;
[0007] Wherein, the template generation model is trained through the following method:
[0008] Training a target neural network model through at least one sample set to obtain a pre-trained template generation model, where the sample set includes a plurality of first random sample data and target template data, the first random sample data is determined according to initial random sample data, and the difference between any two of the first random sample data is less than or equal to a preset difference threshold;
[0009] Training the pre-trained template generation model through a plurality of second random sample data to obtain the template generation model.
[0010] In some embodiments, the training a target neural network model through at least one sample set to obtain a pre-trained template generation model includes:
[0011] Determining a current sample set;
[0012] According to the current sample set, circularly executing a first model training step until, when the trained target neural network model meets a first preset stop iteration condition, taking the trained target neural network model as the pre-trained template generation model; the first model training step includes:
[0013] Train the target neural network model with the current sample set;
[0014] In the case that the trained target neural network model does not meet the first preset iteration stop condition, determine a new current sample set.
[0015] In some embodiments, the current sample set is determined by the following method:
[0016] Generate the initial random sample data;
[0017] Obtain the target template data and the preset template noise;
[0018] Obtain a plurality of preset sample noises corresponding to the initial random sample data;
[0019] Determine a plurality of the first random sample data according to the initial random sample data and the plurality of preset sample noises;
[0020] Determine the noise template data according to the target template data and the preset template noise;
[0021] Determine the current sample set according to the plurality of the first random sample data and the noise template data.
[0022] In some embodiments, the obtaining of the target template data includes:
[0023] Obtain the target template data from a plurality of pre-stored template data in a specified order; or,
[0024] Randomly obtain the target template data from the plurality of template data.
[0025] In some embodiments, the training of the target neural network model with the current sample set includes:
[0026] Loop and execute the second model training step until the trained target neural network model meets the second preset iteration stop condition;
[0027] The second model training step includes:
[0028] Input the plurality of the first random sample data in the current sample set into the target neural network model, and output the predicted template data corresponding to each of the first random sample data;
[0029] Determine the target loss value according to the predicted template data and the noise template data, and update the parameters of the target neural network model according to the target loss value to obtain the trained target neural network model, and use the trained target neural network model as the new target neural network model.
[0030] In some embodiments, the generating of the random data includes:
[0031] Generating the random data according to the preset format corresponding to the model according to the template.
[0032] In some embodiments, the target neural network model includes a generator and a discriminator. The generator includes an encoder, an association module, and a decoder. Both the encoder and the decoder include three linear layers and a residual branch. The association module includes four self-attention modules. The discriminator includes three convolutional layers and two linear layers.
[0033] In some embodiments, the method further includes:
[0034] Generating a target template according to the template generation model;
[0035] Obtaining an element image corresponding to a target element in the target template;
[0036] Adding the element image to the target template to obtain an image to be color-matched;
[0037] Performing color matching on the image to be color-matched according to a preset color matching rule to obtain a target image.
[0038] According to a second aspect of the embodiments of the present disclosure, there is provided a template generation device, the device includes:
[0039] A data generation module, configured to generate random data in response to a received template generation instruction;
[0040] A template output module, configured to input the random data into a pre-trained template generation model and output a target template;
[0041] A model training module, configured to train a target neural network model through at least one sample set to obtain a pre-trained template generation model. The sample set includes a plurality of first random sample data and target template data. The first random sample data is determined according to initial random sample data, and the difference between any two of the first random sample data is less than or equal to a preset difference threshold; training the pre-trained template generation model through a plurality of second random sample data to obtain the template generation model.
[0042] In some embodiments, the model training module is further configured to:
[0043] Determine a current sample set;
[0044] According to the current sample set, the first model training step is cyclically executed until the trained target neural network model meets the first preset stop iteration condition, and then the trained target neural network model is used as the pre-training template generation model; the first model training step includes:
[0045] Training the target neural network model with the current sample set;
[0046] When the trained target neural network model does not meet the first preset stop iteration condition, determine a new current sample set.
[0047] In some embodiments, the model training module is further configured to:
[0048] Generate the initial random sample data;
[0049] Obtain the target template data and the preset template noise;
[0050] Obtain a plurality of preset sample noises corresponding to the initial random sample data;
[0051] Determine a plurality of the first random sample data according to the initial random sample data and the plurality of preset sample noises;
[0052] Determine the noise template data according to the target template data and the preset template noise;
[0053] Determine the current sample set according to the plurality of the first random sample data and the noise template data.
[0054] In some embodiments, the model training module is further configured to:
[0055] Obtain the target template data from a plurality of pre-stored template data in a specified order; or,
[0056] Randomly obtain the target template data from the plurality of template data.
[0057] In some embodiments, the model training module is further configured to:
[0058] Cyclically execute the second model training step until the trained target neural network model meets the second preset stop iteration condition;
[0059] The second model training step includes:
[0060] Input the plurality of the first random sample data in the current sample set into the target neural network model, and output the predicted template data corresponding to each of the first random sample data;
[0061] Determine a target loss value according to the predicted template data and the noise template data, update the parameters of the target neural network model according to the target loss value to obtain a trained target neural network model, and use the trained target neural network model as a new target neural network model.
[0062] In some embodiments, the data generation module is further configured to:
[0063] Generate the random data according to a preset format corresponding to the template generation model.
[0064] In some embodiments, the target neural network model includes a generator and a discriminator. The generator includes an encoder, an association module, and a decoder. Both the encoder and the decoder include three linear layers and one residual branch. The association module includes four self-attention modules. The discriminator includes three convolutional layers and two linear layers.
[0065] In some embodiments, the apparatus further includes:
[0066] A template generation module configured to generate a target template according to the template generation model;
[0067] An element image acquisition module configured to acquire an element image corresponding to a target element in the target template;
[0068] A to-be-colored image acquisition module configured to add the element image to the target template to obtain a to-be-colored image;
[0069] A target image acquisition module configured to perform color matching on the to-be-colored image according to a preset color matching rule to obtain a target image.
[0070] According to a third aspect of the embodiments of the present disclosure, there is provided a computer-readable storage medium having computer program instructions stored thereon, and when the program instructions are executed by a processor, the steps of the template generation method provided in the first aspect of the present disclosure are implemented.
[0071] According to a fourth aspect of the embodiments of the present disclosure, there is provided an electronic device, including:
[0072] A memory having a computer program stored thereon;
[0073] A processor configured to execute the computer program in the memory to implement the steps of the template generation method provided in the first aspect of the present disclosure.
[0074] The technical solutions provided by the embodiments of the present disclosure may include the following beneficial effects: generating random data in response to a received template generation instruction; inputting the random data into a pre-trained template generation model to output a target template; wherein, the template generation model is trained in the following manner: training a target neural network model through at least one sample set to obtain a pre-trained template generation model, the sample set includes a plurality of first random sample data and target template data, the first random sample data is determined according to initial random sample data, and the difference between any two of the first random sample data is less than or equal to a preset difference threshold; training the pre-trained template generation model through a plurality of second random sample data to obtain the template generation model. That is to say, the present disclosure first trains a target neural network model through at least one sample set to obtain a pre-trained template generation model. Each of the plurality of first random sample data in each sample set is determined according to the initial random sample data, and the difference between any two of the first random sample data is less than or equal to the preset difference threshold, so that the stability of the trained pre-trained template generation model is relatively high. Then, training the pre-trained template generation model through a plurality of second random sample data to obtain the template generation model. In this way, while ensuring the creativity of the template generation model, the stability of the template generation model can be improved.
[0075] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and cannot limit the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0076] The accompanying drawings herein are incorporated into the specification and constitute a part of this specification, showing embodiments consistent with the present disclosure, and are used together with the specification to explain the principles of the present disclosure.
[0077] Figure 1 is a flowchart of a template generation method shown according to an exemplary embodiment of the present disclosure;
[0078] Figure 2 is a flowchart of a training method of a template generation model shown according to an exemplary embodiment of the present disclosure;
[0079] Figure 3 is a flowchart of a first model training step shown according to an exemplary embodiment of the present disclosure;
[0080] Figure 4 is a block diagram of a template generation device shown according to an exemplary embodiment of the present disclosure;
[0081] Figure 5 is a block diagram of another template generation device shown according to an exemplary embodiment of the present disclosure;
[0082] Figure 6 It is a block diagram of an electronic device shown according to an exemplary embodiment of the present disclosure. Detailed implementation manners
[0083] Here, the exemplary embodiments will be described in detail, and the examples are shown in the drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementation manners described in the following exemplary embodiments do not represent all implementation manners consistent with the present disclosure. On the contrary, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0084] First, the application scenario of the present disclosure will be described. Template generation tasks often require data with special characteristics, such as posters, documents, advertisements, etc. Since the publicly available datasets cannot meet this requirement, to complete a specific template generation task, data needs to be collected separately, and the samples in the obtained dataset are often relatively few. In the related art, a template generation model can be trained based on GAN (Generative Adversarial Networks). The template generation model generated in this way is quite creative and can generate a relatively large number of template styles. However, when training the template generation model based on GAN, a large number of samples are required, and it is difficult to obtain a good model when the samples are few. For example, the types of frames in the templates generated by the template generation model are relatively few, sometimes even no frames are generated, or the number of generated templates is relatively small, resulting in relatively poor stability of the template generation model.
[0085] To overcome the above technical problems existing in the related art, the present disclosure provides a template generation method, device, storage medium, and electronic device. First, a pre-trained template generation model is obtained by training a target neural network model with at least one sample set. The multiple first random sample data in each sample set are all determined according to the initial random sample data, and the difference between any two first random sample data is less than or equal to a preset difference threshold, so that the stability of the trained pre-trained template generation model is relatively high. Then, the pre-trained template generation model is trained with multiple second random sample data to obtain a template generation model. In this way, while ensuring the creativity of the template generation model, the stability of the template generation model can be improved.
[0086] The following describes the present disclosure in combination with specific embodiments.
[0087] Figure 1 It is a flowchart of a template generation method shown according to an exemplary embodiment of the present disclosure, as Figure 1 shown. The method may include:
[0088] S101. Generate random data in response to the received template generation instruction.
[0089] In this step, the user can trigger the template generation instruction through the template generation platform. After receiving the template generation instruction, the template generation platform can generate random data according to the preset format corresponding to the template generation model. For example, the preset format can be an n*(m + 4)-dimensional vector, where n is the number of elements included in the template, and m is the number of labels corresponding to each element.
[0090] It should be noted that the above method for triggering the template generation instruction is only an example, and the template generation instruction can also be triggered by other methods in the prior art. The present disclosure does not limit this.
[0091] S102. Input the random data into the pre-trained template generation model and output the target template.
[0092] Among them, the template generation model is trained in the following way: the target neural network model is trained through at least one sample set to obtain the pre-trained template generation model. The sample set includes multiple first random sample data and target template data. The first random sample data is determined according to the initial random sample data, and the difference between any two first random sample data is less than or equal to the preset difference threshold; the pre-trained template generation model is trained through multiple second random sample data to obtain the template generation model. Among them, the target neural network model can include a generator and a discriminator. The generator includes an encoder, an association module, and a decoder. Both the encoder and the decoder include three linear layers and a residual branch. The association module includes four self-attention modules. The discriminator includes three convolutional layers and two linear layers. For example, the target neural network model can be a GAN.
[0093] In this step, the current sample set can be determined first. According to the current sample set, the first model training step is cyclically executed until the trained target neural network model meets the first preset stop iteration condition, and the trained target neural network model is used as the pre-trained template generation model. Among them, the first model training step includes: training the target neural network model through the current sample set; when the trained target neural network model does not meet the first preset stop iteration condition, determining a new current sample set.
[0094] Exemplarily, an initial random sample data can be obtained, and multiple initial noises are randomly generated. The multiple initial noises are all less than or equal to a preset noise threshold. After that, according to the initial random sample data and the multiple initial noises, multiple first random sample data corresponding to the initial random sample data can be determined, and the multiple first random sample data are used as the current sample set. After obtaining the current sample set, the target neural network model can be trained by the multiple first random sample data in the current sample set and the target template data to obtain the trained target neural network model. After that, it can be determined whether the trained target neural network model meets the first preset iteration stop condition. If the trained target neural network model meets the first preset iteration stop condition, the trained target neural network model is used as the pre-trained template generation model. If the trained target neural network model does not meet the first preset iteration stop condition, a new current sample set can be determined, and the trained target neural network model is trained by the multiple first random sample data in the new current sample set and the target template data until the trained target neural network model meets the first preset iteration stop condition. Among them, the first preset iteration stop condition can be that the number of iterations is greater than or equal to a first preset iteration number threshold. Exemplarily, the first preset iteration number can be 10, or other iteration stop conditions in the prior art. The present disclosure does not limit this.
[0095] Further, after training the target neural network model to obtain the pre-trained template generation model, multiple second random sample data can be randomly generated according to the preset format corresponding to the template generation model. After that, according to the model training method in the prior art, the pre-trained template generation model can be trained by the multiple second random sample data to obtain the template generation model, which will not be elaborated here.
[0096] By adopting the above method, the target neural network model is first trained by at least one sample set to obtain the pre-trained template generation model. The multiple first random sample data in each sample set are all determined according to the initial random sample data, and the difference between any two first random sample data is less than or equal to the preset difference threshold, so that the stability of the trained pre-trained template generation model is relatively high. Then, the pre-trained template generation model is trained by the multiple second random sample data to obtain the template generation model. In this way, while ensuring the creativity of the template generation model, the stability of the template generation model can be improved.
[0097] Figure 2 is a flowchart of a method for training a template generation model according to an exemplary embodiment of the present disclosure, as Figure 2 shown, the method may include:
[0098] S201. Determine the current sample set.
[0099] S202. According to the current sample set, repeatedly execute the first model training step until, when the trained target neural network model meets the first preset iteration stop condition, use the trained target neural network model as the pre-training template generation model.
[0100] Among them, the first model training step includes: training the target neural network model with the current sample set; when the trained target neural network model does not meet the first preset iteration stop condition, determine a new current sample set.
[0101] Figure 3 is a flowchart of a first model training step shown according to an exemplary embodiment of the present disclosure. As Figure 3 shown, the method may include:
[0102] S1. Generate initial random sample data.
[0103] In this step, initial random sample data may be generated according to the preset format corresponding to the template generation model. Exemplarily, the preset format may be an n*(m + 4)-dimensional vector, where n is the number of elements included in the template, and m is the number of labels corresponding to each element.
[0104] S2. Obtain target template data and preset template noise.
[0105] In this step, the preset template noise may be randomly generated according to a preset noise threshold, and the preset noise threshold may be obtained in advance through experiments. For example, the preset noise threshold may be 0.1. Then, according to the type of the template generation model, multiple template data may be obtained and stored in advance, and the target template data may be obtained from the multiple pre-stored template data in a specified order; or the target template data may be randomly obtained from the multiple template data. Exemplarily, if the type of the template generation model is an advertisement, multiple advertisement samples may be obtained, and then, according to the preset format, the template data corresponding to each advertisement sample may be obtained and multiple template data may be stored.
[0106] S3. Obtain multiple preset sample noises corresponding to the initial random sample data.
[0107] In this step, multiple preset sample noises corresponding to the initial random sample data may be randomly generated according to a preset noise threshold. It should be noted that in the present disclosure, the preset template noise may be obtained before obtaining the multiple preset sample noises corresponding to the initial random sample data, or the preset template noise may be obtained simultaneously when obtaining the multiple preset sample noises corresponding to the initial random sample data. The present disclosure does not make a limitation in this regard.
[0108] S4. Determine a plurality of first random sample data according to the initial random sample data and a plurality of preset sample noises.
[0109] In this step, after obtaining the initial random sample data and a plurality of preset sample noises, for each preset sample noise, the sum value of the initial random sample data and the preset sample noise can be calculated, and the sum value is used as the first random sample data.
[0110] S5. Determine noise template data according to the target template data and the preset template noise.
[0111] In this step, after obtaining the preset template noise, the sum value of the target template data and the preset template noise can be calculated, and the sum value is used as the noise template data.
[0112] S6. Determine the current sample set according to the plurality of first random sample data and the noise template data.
[0113] In this step, after obtaining the plurality of first random sample data and the noise template data, the plurality of first random sample data and the noise template data can be used as the current sample set.
[0114] S7. Train the target neural network model with the current sample set.
[0115] In this step, after obtaining the plurality of first random sample data and the noise template data in the current sample set, the second model training step can be repeatedly executed until the trained target neural network model meets the second preset stop iteration condition; the second model training step includes:
[0116] Input the plurality of first random sample data in the current sample set into the target neural network model, and output the predicted template data corresponding to each first random sample data; determine the target loss value according to the predicted template data and the noise template data, and update the parameters of the target neural network model according to the target loss value to obtain the trained target neural network model, and use the trained target neural network model as the new target neural network model. Among them, the loss function corresponding to the target neural network model can be any loss function in the prior art, and the present disclosure does not limit this. After obtaining the predicted template data corresponding to each first random sample data, the target loss value can be calculated according to the predicted template data and the noise template data through the loss function corresponding to the target neural network model.
[0117] It should be noted that the prediction template data is obtained from the first random sample data, and the first random sample data is the data obtained by adding a preset sample noise to the initial random sample data. Therefore, after adding a preset template noise to the target template data, the target loss value calculated based on the prediction template data and the noise template data is more accurate, thereby further improving the accuracy of the pre-trained template generation model.
[0118] Exemplarily, taking the target neural network model as a GAN for illustration, the GAN model includes a generator and a discriminator. After calculating the target loss value, the generator in the GAN can be trained through the target loss value. For the discriminator of the GAN, it can be trained by a general method in the prior art.
[0119] The second preset iteration stop condition may be that the preset iteration number is greater than or equal to a second preset iteration number threshold. The second preset iteration number threshold may be the same as the first preset iteration number threshold or different from the first preset iteration number threshold. Exemplarily, the second preset iteration number threshold may be 15, and the present disclosure does not limit this.
[0120] It should be noted that in the above steps S1 to S7, for each sample set, the generated initial random sample data, the obtained target template data, the multiple preset sample noises corresponding to the obtained initial random sample data, and the obtained preset template noise may all be different.
[0121] S8. Determine whether the trained target neural network model meets the first preset iteration stop condition. If the trained target neural network model meets the first preset iteration stop condition, execute step S9; if the trained target neural network model does not meet the first preset iteration stop condition, execute steps S1 to S8.
[0122] S9. Use the trained target neural network model as the pre-trained template generation model.
[0123] S203. Train the pre-trained template generation model with multiple second random sample data to obtain the template generation model.
[0124] S204. Generate a target template according to the template generation model.
[0125] In this step, random data can be generated according to a template generation instruction triggered by a user. After inputting the random data into the template generation model, the target template is obtained.
[0126] S205. Obtain the element image corresponding to the target element in the target template.
[0127] In this step, after obtaining the target template, the element information of each target element in the target template can be determined first. The element information may include the position and size. Then, according to the element information of the target element, an element image corresponding to the target element can be generated or collected.
[0128] S206. Add the element image to the target template to obtain an image to be color-matched.
[0129] In this step, after obtaining the element image corresponding to the target element, the element image can be inserted into the target template according to the position of the target element to obtain the image to be color-matched.
[0130] S207. Perform color matching on the image to be color-matched according to a preset color matching rule to obtain a target image.
[0131] In this step, after obtaining the image to be color-matched, the image to be color-matched can be color-matched according to a preset theme color according to a preset color matching rule to obtain the target image.
[0132] Using the above method, a plurality of first random sample data in the sample set are determined according to the initial random sample data and a plurality of preset sample noises. In this way, since the plurality of preset sample noises are all less than or equal to the preset noise threshold, the difference between the obtained plurality of first random sample data is relatively small, so that the stability of the pre-trained template generation model trained according to the plurality of first random sample data is relatively high. Then, the pre-trained template generation model is trained by a plurality of second random sample data to obtain a template generation model. In this way, while ensuring the creativity of the template generation model, the stability of the template generation model can be improved. Further, after obtaining the template generation model, a target template can be quickly generated by the template generation model, and a target image can be obtained according to the target template, improving the efficiency of image generation.
[0133] Figure 4 is a block diagram of a template generation device shown according to an exemplary embodiment of the present disclosure, as Figure 4 shown. The device may include:
[0134] A data generation module 401, configured to generate random data in response to a received template generation instruction;
[0135] A template output module 402, configured to input the random data into a pre-trained template generation model and output a target template;
[0136] The model training module 403 is configured to train a target neural network model through at least one sample set to obtain a pre-trained template generation model. The sample set includes a plurality of first random sample data and target template data. The first random sample data is determined according to initial random sample data, and the difference between any two pieces of the first random sample data is less than or equal to a preset difference threshold. The pre-trained template generation model is trained through a plurality of second random sample data to obtain the template generation model.
[0137] In some embodiments, the model training module 403 is further configured to:
[0138] Determine a current sample set;
[0139] According to the current sample set, the first model training step is cyclically executed until, when the trained target neural network model meets the first preset stop iteration condition, the trained target neural network model is used as the pre-trained template generation model. The first model training step includes:
[0140] Train the target neural network model through the current sample set;
[0141] When the trained target neural network model does not meet the first preset stop iteration condition, determine a new current sample set.
[0142] In some embodiments, the model training module 403 is further configured to:
[0143] Generate the initial random sample data;
[0144] Obtain the target template data and a preset template noise;
[0145] Obtain a plurality of preset sample noises corresponding to the initial random sample data;
[0146] According to the initial random sample data and the plurality of preset sample noises, determine the plurality of first random sample data;
[0147] According to the target template data and the preset template noise, determine noise template data;
[0148] According to the plurality of first random sample data and the noise template data, determine the current sample set.
[0149] In some embodiments, the model training module 403 is further configured to:
[0150] Obtain the target template data from a plurality of pre-stored template data in a specified order; or,
[0151] Randomly obtain the target template data from the plurality of template data.
[0152] In some embodiments, the model training module 403 is further configured to:
[0153] Iteratively execute the second model training step until the trained target neural network model meets the second preset iteration stop condition;
[0154] The second model training step includes:
[0155] Input multiple pieces of the first random sample data in the current sample set into the target neural network model, and output the predicted template data corresponding to each piece of the first random sample data;
[0156] Determine the target loss value according to the predicted template data and the noise template data, update the parameters of the target neural network model according to the target loss value to obtain the trained target neural network model, and use the trained target neural network model as the new target neural network model.
[0157] In some embodiments, the data generation module 402 is further configured to:
[0158] Generate the random data according to the preset format corresponding to the template generation model.
[0159] In some embodiments, the target neural network model includes a generator and a discriminator. The generator includes an encoder, an association module, and a decoder. Both the encoder and the decoder include three linear layers and a residual branch. The association module includes four self-attention modules. The discriminator includes three convolutional layers and two linear layers.
[0160] In some embodiments, Figure 5 is a block diagram of another template generation device shown according to an exemplary embodiment of the present disclosure. As Figure 5 shown, the device further includes:
[0161] A template generation module 404, configured to generate a target template according to the template generation model;
[0162] An element image acquisition module 405, configured to acquire the element image corresponding to the target element in the target template;
[0163] A to-be-colored image acquisition module 406, configured to add the element image to the target template to obtain a to-be-colored image;
[0164] A target image acquisition module 407, configured to perform color matching on the to-be-colored image according to a preset color matching rule to obtain a target image.
[0165] Through the above device, first, a pre-training template generation model is obtained by training a target neural network model with at least one sample set. Multiple first random sample data in each sample set are all determined based on the initial random sample data, and the difference between any two first random sample data is less than or equal to a preset difference threshold, so that the stability of the trained pre-training template generation model is relatively high. Then, the pre-training template generation model is trained with multiple second random sample data to obtain a template generation model. In this way, while ensuring the creativity of the template generation model, the stability of the template generation model can be improved.
[0166] Regarding the device in the above embodiment, the specific manners in which each module performs operations have been described in detail in the embodiment related to the method, and will not be elaborated herein.
[0167] The present disclosure also provides a computer-readable storage medium, on which computer program instructions are stored. When the program instructions are executed by a processor, the steps of the template generation method provided by the present disclosure are implemented.
[0168] In another exemplary embodiment, a computer program product is also provided. The computer program product includes a computer program that can be executed by a programmable device. The computer program has a code portion for executing the above template generation method when executed by the programmable device.
[0169] Figure 6 is a block diagram of an electronic device 600 shown according to an exemplary embodiment of the present disclosure. For example, the electronic device 600 can be provided as a server. Referring to Figure 6 , the electronic device 600 includes a processing component 622, which further includes one or more processors, and memory resources represented by a memory 632 for storing instructions executable by the processing component 622, such as application programs. The application programs stored in the memory 632 can include one or more modules each corresponding to a set of instructions. In addition, the processing component 622 is configured to execute instructions to perform the above template generation method.
[0170] The electronic device 600 may further include a power component 626 configured to perform power management of the electronic device 600, a wired or wireless network interface 650 configured to connect the electronic device 600 to a network, and an input / output (I / O) interface 658. The electronic device 600 can operate based on an operating system stored in the memory 632, such as Windows Server TM , Mac OS X TM , Unix TM , Linux TM , FreeBSD TMor the like.
[0171] Those skilled in the art will readily conceive of other embodiments of the present disclosure upon considering the specification and practicing the present disclosure. This application is intended to cover any variations, uses, or adaptations of the present disclosure, which follow the general principles of the present disclosure and include known common general knowledge or conventional technical means in the technical field not disclosed in the present disclosure. The specification and examples are only regarded as exemplary, and the true scope and spirit of the present disclosure are pointed out by the following claims.
[0172] It should be understood that the present disclosure is not limited to the exact structures already described and shown in the drawings, and various modifications and changes can be made without departing from its scope. The scope of the present disclosure is only limited by the appended claims.
Claims
1. A template generation method, characterized in that, The method includes: generating random data in response to a received template generation instruction; inputting the random data into a pre-trained template generation model to output a target template; wherein, the template generation model is obtained by training in the following manner: training a target neural network model through at least one sample set to obtain a pre-trained template generation model, the sample set includes a plurality of first random sample data and target template data, the first random sample data is determined according to initial random sample data, and the difference between any two of the first random sample data is less than or equal to a preset difference threshold; training the pre-trained template generation model through a plurality of second random sample data to obtain the template generation model, the second random sample data is randomly generated after obtaining the pre-trained template generation model; The generating random data includes: generating the random data according to a preset format corresponding to the template generation model.
2. The method according to claim 1, wherein The training the target neural network model through at least one sample set to obtain a pre-trained template generation model includes: determining a current sample set; according to the current sample set, repeatedly executing a first model training step until, when the trained target neural network model meets a first preset stop iteration condition, taking the trained target neural network model as the pre-trained template generation model; The first model training step includes: training the target neural network model through the current sample set; when the trained target neural network model does not meet the first preset stop iteration condition, determining a new current sample set.
3. The method according to claim 2, wherein The current sample set is determined by the following method: generating the initial random sample data; obtaining the target template data and a preset template noise; obtaining a plurality of preset sample noises corresponding to the initial random sample data; determining a plurality of the first random sample data according to the initial random sample data and the plurality of preset sample noises; determining noise template data according to the target template data and the preset template noise; determining the current sample set according to the plurality of the first random sample data and the noise template data.
4. The method according to claim 3, wherein The obtaining target template data includes: obtaining the target template data from a plurality of pre-stored template data in a specified order; or, randomly obtaining the target template data from the plurality of template data.
5. The method according to claim 3, characterized in that, The training the target neural network model through the current sample set includes: repeatedly executing a second model training step until the trained target neural network model meets a second preset stop iteration condition; The second model training step includes: inputting the plurality of the first random sample data in the current sample set into the target neural network model to output predicted template data corresponding to each of the first random sample data; Determine a target loss value according to the predicted template data and the noise template data, update the parameters of the target neural network model according to the target loss value to obtain a trained target neural network model, and use the trained target neural network model as a new target neural network model.
6. The method according to claim 1, characterized in that, The target neural network model includes a generator and a discriminator. The generator includes an encoder, an association module, and a decoder. Both the encoder and the decoder include three linear layers and a residual branch. The association module includes four self-attention modules. The discriminator includes three convolutional layers and two linear layers.
7. The method according to any one of claims 1-6, characterized in that, The method further includes: Generate a target template according to the template generation model; Obtain an element image corresponding to a target element in the target template; Add the element image to the target template to obtain an image to be color-matched; Perform color matching on the image to be color-matched according to a preset color-matching rule to obtain a target image.
8. A template generation device, characterized in that, The device includes: A data generation module configured to generate random data in response to a received template generation instruction; A template output module configured to input the random data into a pre-trained template generation model and output a target template; A model training module configured to train a target neural network model through at least one sample set to obtain a pre-trained template generation model. The sample set includes a plurality of first random sample data and target template data. The first random sample data is determined according to initial random sample data, and the difference between any two pieces of the first random sample data is less than or equal to a preset difference threshold; train the pre-trained template generation model through a plurality of second random sample data to obtain the template generation model. The second random sample data is randomly generated after the pre-trained template generation model is obtained; The data generation module is further configured to generate the random data according to a preset format corresponding to the template generation model.
9. A computer-readable storage medium having computer program instructions stored thereon, characterized in that, When the program instruction is executed by a processor, the steps of the method according to any one of claims 1-7 are implemented.
10. An electronic device, characterized in that, Including: A memory having a computer program stored thereon; A processor for executing the computer program in the memory to implement the steps of the method according to any one of claims 1-7.
Citation Information
Patent Citations
Poster arrangement model training method and poster generation method and device
CN111524208A