Landscape painting generation method, landscape painting model acquisition method, landscape painting model acquisition device and terminal equipment
Through the interactive distillation technology based on the generative adversarial network, the problems of unstable generation effect and large model occupancy in the existing landscape painting generation technology are solved, and an efficient landscape painting generation model is realized, which improves the inference speed and reduces the memory usage.
Patent Information
- Application Number
- CN202410789693.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-18
- Publication Date
- 2024-09-17
AI Technical Summary
Among the existing landscape painting generation technologies, the Unpaired data route generation effect is unstable and prone to artifacts. Although the Pix2pix route is stable, it cannot decouple style and content, and the model takes up a lot of video memory and is slow in inference.
A method based on generative adversarial networks is used to construct an initial network and train the student network through interactive distillation design. Combining style transfer and interactive knowledge distillation technology, the design of a lightweight landscape painting generative model is realized.
While maintaining high accuracy, it improves the inference speed of the landscape painting generation model and reduces the memory usage, achieving the effect of lightweight design.
Smart Images

Figure CN118657844A
Abstract
Description
Technical Field
[0001] The present application relates to the field of image generation technology, and in particular to a landscape painting generation method and a model acquisition method, device and terminal device thereof. Background Art
[0002] Landscape painting generation refers to using students' stick drawings to generate corresponding landscape paintings using generative techniques, such as Figure 1 As shown in Figure 1, its core technology route is style transfer, for example, it includes the generation technology CycleGAN based on unpaired data and the generation technology Pix2pix based on paired data. However, the generation effect of the unpaired data technology route is unstable and prone to artifacts and noise. Although the generation effect of the Pix2pix technology route can achieve a relatively stable generation effect, it cannot support the decoupling of style and content, and its model occupies more video memory, and the inference speed needs to be improved. Summary of the invention
[0003] In view of this, the embodiments of the present application provide a landscape painting generation method and a model acquisition method, device and terminal device thereof, which can effectively improve the inference speed of the landscape painting generation model and reduce the problem of video memory occupancy while ensuring high accuracy.
[0004] In a first aspect, an embodiment of the present application provides a method for acquiring a landscape painting generation model, comprising:
[0005] Based on the generative adversarial network, an initial network for generating landscape paintings is constructed and trained;
[0006] Using the initial network, a teacher network and a student network are constructed respectively;
[0007] Inputting the landscape painting training samples into the teacher network and the student network respectively for feature extraction, so as to obtain a first prediction feature map and an intermediate feature map output by the student network, and a second prediction feature map and an interactive feature map output by the teacher network; wherein the interactive feature map is obtained by inputting the intermediate feature maps extracted by the student network at different stages into the teacher network for processing;
[0008] Calculating a training loss based on a feature constraint between the first prediction feature graph and the second prediction feature graph and a feature constraint between the second prediction feature graph and each of the interaction feature graphs;
[0009] The training loss is used to adjust the parameters of the student network so as to use the trained student network as a landscape painting generation model.
[0010] In some embodiments, the generative adversarial network includes a generator and a discriminator, the generator includes a content encoding module, a feature combination module, a style feature encoding module and a content decoding module; the initial network for generating landscape paintings is constructed and trained based on the generative adversarial network, including:
[0011] Input the acquired stick drawing into the generator to process it by the content encoding module to obtain a content feature map, and process the target landscape painting by the style feature encoding module to obtain a style feature map; integrate the style feature map and the content feature map by the feature combination module, and then process them by the content decoding module to obtain a landscape painting image generated based on the stick drawing; discriminate the target landscape painting and the landscape painting image by the discriminator to obtain a discrimination result;
[0012] A learning loss is calculated based on the target landscape painting, the landscape painting image and the discrimination result, and the learning loss is used to adjust the parameters of the generative adversarial network so as to use the trained generative adversarial network as an initial network for generating landscape paintings.
[0013] In some embodiments, the step of using the initial network to construct a teacher network and a student network respectively includes:
[0014] A teacher network and a student network are constructed using the initial network; wherein the teacher network includes four stages, the four stages correspond to four modules in the generator, and the modules corresponding to each stage in the student network are block pruned and channel pruned.
[0015] In some embodiments, the teacher network and the student network each include four stages; the interactive feature map is obtained by inputting the intermediate feature maps extracted by the student network at different stages into the teacher network for processing, including:
[0016] Using the first intermediate feature map extracted from the first stage of the student network as the input of the second stage of the teacher network, the second intermediate feature map extracted from the second stage of the student network as the input of the third stage of the teacher network, and the third intermediate feature map extracted from the third stage of the student network as the input of the fourth stage of the teacher network;
[0017] After the teacher network processes each of the intermediate feature maps, the corresponding first interaction feature map, second interaction feature map and third interaction feature map are obtained.
[0018] In some embodiments, the training loss includes a first type of loss between the first predicted feature map and the second predicted feature map, and a second type of loss between the second predicted feature map and each of the interaction feature maps.
[0019] In some embodiments, the training loss is the sum of the first category loss and all the second category losses.
[0020] In some embodiments, the feature constraints include a structural similarity constraint between two feature maps for calculation, a content consistency constraint, a style consistency constraint, and a regularization term smoothness constraint, and each constraint is respectively constructed with a loss function for calculating the corresponding constraint loss.
[0021] In some embodiments, the loss between the two feature maps is the sum of the constraint losses.
[0022] In some embodiments, the loss function of the structural similarity constraint is constructed based on the similarity of brightness, contrast and structure between the two feature maps;
[0023] The loss function of the content consistency constraint is constructed based on the content similarity between the two feature maps;
[0024] The loss function of the style consistency constraint is constructed based on the difference in channel correlation between the two feature maps;
[0025] The loss function of the regularization term smoothness constraint is constructed based on the difference in gradient changes between the two feature maps.
[0026] In a second aspect, an embodiment of the present application provides a method for generating a landscape painting, comprising:
[0027] The target stick figure drawing is input into the trained landscape painting generation model to generate the corresponding landscape painting; wherein the landscape painting generation model is obtained by using the landscape painting generation model acquisition method.
[0028] In a third aspect, an embodiment of the present application provides a device for acquiring a landscape painting generation model, comprising:
[0029] An initial network acquisition module is used to construct and train an initial network for generating landscape paintings based on a generative adversarial network;
[0030] A distillation network construction module, used to use the initial network to construct a teacher network and a student network respectively;
[0031] Interactive distillation training module, including feature interactive learning unit, loss calculation unit and training output unit;
[0032] The feature interactive learning unit is used to input the landscape painting training samples into the teacher network and the student network for feature extraction, so as to obtain the first predicted feature map and the intermediate feature map output by the student network, and the second predicted feature map and the interactive feature map output by the teacher network; wherein the interactive feature map is obtained by inputting the intermediate feature map extracted by the student network at different stages into the teacher network for processing;
[0033] The loss calculation unit is used to calculate the training loss based on the feature constraint between the first prediction feature map and the second prediction feature map and the feature constraint between the second prediction feature map and each of the interaction feature maps;
[0034] The training output unit is used to adjust the parameters of the student network using the training loss, so as to use the trained student network as a landscape painting generation model.
[0035] In a fourth aspect, an embodiment of the present application provides a terminal device, comprising a processor and a memory, wherein the memory stores a computer program, and when the processor executes the computer program, the above-mentioned landscape painting generation model acquisition method or landscape painting generation method is implemented.
[0036] In some embodiments, the processor includes a central processing unit and / or an image processor; the terminal device is further used to deploy the landscape painting generation model on the image processor platform and perform inference engine acceleration through the TensorRT tool;
[0037] And / or, deploying the landscape painting generation model on the central processing unit platform and accelerating the inference engine through the Openvino tool.
[0038] In a fifth aspect, an embodiment of the present application provides a computer-readable storage medium storing a computer program, which, when executed on a processor, implements the landscape painting generation model acquisition method or landscape painting generation method.
[0039] The embodiments of the present application have the following beneficial effects:
[0040] The method for obtaining a landscape painting generation model proposed in this application first uses a generative adversarial network to construct and train an initial network for generating landscape paintings; then, a teacher network and a lightweight student network are constructed using the initial network, and the student network is trained based on the design of interactive distillation, so that the accuracy of the lightweight student network can meet the requirements. This application combines a generative adversarial network based on style transfer (i.e., StyleGAN) and interactive knowledge distillation technology to achieve a lightweight design of a landscape painting generation model, and while maintaining a certain accuracy, it also effectively improves the inference speed and reduces the memory usage. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0042] Figure 1 A schematic diagram of an application of generating a landscape painting from a stick drawing is shown;
[0043] Figure 2 A flow chart showing a method for acquiring a landscape painting generation model according to an embodiment of the present application is shown;
[0044] Figure 3 A schematic diagram showing an embodiment of the present application of constructing an initial network of landscape painting based on a generative adversarial network;
[0045] Figure 4 A schematic diagram of initial network training of landscape painting in an embodiment of the present application is shown;
[0046] Figure 5 A schematic diagram showing a landscape painting generation model trained based on an interactive distillation network in an embodiment of the present application is shown;
[0047] Figure 6 A schematic diagram of the structure of a landscape painting generation model acquisition device according to an embodiment of the present application is shown;
[0048] Figure 7 A structural schematic diagram of a terminal device according to an embodiment of the present application is shown.
[0049] Description of main component symbols:
[0050] 100 - device for acquiring a landscape painting generation model; 110 - initial network acquisition module; 120 - distillation network construction module; 130 - interactive distillation training module; 131 - feature interactive learning unit; 132 - loss calculation unit; 133 - training output unit; 10 - terminal device; 11 - processor; 12 - memory. DETAILED DESCRIPTION
[0051] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments.
[0052] The components of the embodiments of the present application generally described and shown in the drawings herein may be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0053] Hereinafter, the terms "including", "having" and their cognates that can be used in various embodiments of the present application are intended only to indicate specific features, numbers, steps, operations, elements, components or a combination of the foregoing items, and should not be understood as first excluding the existence of one or more other features, numbers, steps, operations, elements, components or a combination of the foregoing items or increasing the possibility of one or more features, numbers, steps, operations, elements, components or a combination of the foregoing items. In addition, the terms "first", "second", "third" and the like are only used to distinguish descriptions and cannot be understood as indicating or implying relative importance.
[0054] Unless otherwise defined, all terms (including technical terms and scientific terms) used herein have the same meanings as those generally understood by those skilled in the art to which the various embodiments of the present application belong. The terms (such as those defined in generally used dictionaries) will be interpreted as having the same meanings as the contextual meanings in the relevant technical field and will not be interpreted as having idealized meanings or overly formal meanings unless clearly defined in the various embodiments of the present application.
[0055] In conjunction with the accompanying drawings, some embodiments of the present application are described in detail below. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.
[0056] Figure 2 A flow chart of a method for obtaining a landscape painting generation model according to an embodiment of the present application is shown. Exemplarily, the method for obtaining a landscape painting generation model comprises the following steps:
[0057] S110, based on the generative adversarial network, construct and train an initial network for generating landscape paintings.
[0058] Among them, the generative adversarial network (GAN) includes a generator and a discriminator, which are trained through an adversarial process, and eventually the fake pictures generated by the generator become more and more like real pictures, and the discriminator can distinguish fake pictures that are very close to real pictures. In this embodiment, a generative adversarial network (StyleGAN) based on style transfer is used to obtain an initial network for generating landscape paintings with stable generation effects. Specifically, the generator in the trained StyleGAN is used to use the input stick figure to generate a generated image that is more in line with the content and style of the target landscape painting; and the discriminator is used to discriminate the generation effect of the generated image. It is worth noting that since random noise can bring diversity after being input into the generator, and style transfer is required in this embodiment, it does not need to be added.
[0059] Exemplarily, in one embodiment, the generator in StyleGAN includes a content encoding module, a feature combination module and a content decoding module connected in sequence, and a style feature encoding module connected to the feature combination module. Therefore, for the above step S110, it includes: first inputting the obtained stick figure into Figure 3 In the generator shown, the content encoding module (i.e. Figure 3 c_enc) shown in the figure is used to extract content features to obtain a content feature map; at the same time, the target landscape painting is encoded through a style feature encoding module (i.e. Figure 3 The style feature extraction process is performed on the s_enc shown in the figure to obtain a style feature map. Then, the style feature map and the content feature map are combined through a feature combination module (i.e. Figure 3 res) is fused and then passed through the content decoding module (i.e. Figure 3 It is worth noting that the output of the style feature encoding module will first be processed by adaptive instance normalization (AdaIN) and then input into the feature combination module for fusion processing.
[0060] It can be understood that in this embodiment, by using the content encoding module and the style feature encoding to respectively perform feature extraction first, and then using AdaIN to integrate the extracted style features into the landscape painting generation process, the decoupling of style and content can be achieved, and because AdaIN only needs to adjust the mean and variance of the content image to match the mean and variance of the style image, it can efficiently achieve style transfer.
[0061] Next, the target landscape painting and the landscape painting generated by the generator are input into the discriminator for discrimination, such as Figure 4Then, based on the target landscape painting, landscape painting image and the discrimination result, the constructed loss function is used to calculate the learning loss, and the learning loss is used for gradient back propagation to adjust the parameters of the generative adversarial network until the loss function converges and stops training, and the trained generative adversarial network is used as the initial network for generating landscape paintings.
[0062] In one embodiment, the loss function of the generative adversarial network is used to calculate two parts of loss, namely, the generative adversarial loss and the cycle consistency loss. It can be understood that the generative adversarial loss is to constrain the adversarial nature between the generator and the discriminator, while the cycle consistency loss is to constrain the original input sketch to be as consistent as possible with the reconstructed input.
[0063] For example, the generative adversarial loss can be constructed based on loss functions such as cross entropy. For example, it can be calculated by the following objective function:
[0064]
[0065] Where, L GAN To generate adversarial loss, G and D Y Denote the generator and discriminator respectively; X and Y denote the stick figure and the target landscape painting respectively, D Y (y) represents the discriminator’s discrimination result on the target landscape painting; D Y (G(x)) represents the discriminator’s judgment result on the generated image G(x); E y~Pdata(y) Indicates that y belongs to the real data P data (y) expectation; E x ~P data (x) means x belongs to the real data P data (x) expectations.
[0066] For example, the cycle consistency loss can be calculated by the following objective function:
[0067] L cyc (G, F) = E x~pdata(x) [||F(G(x)-x)||1];
[0068] Where, L CYC is the cycle consistency loss, F(G(x)) is the reconstruction result of the generated image G(x); ||*||1 means taking the 1-norm; F can be regarded as a reconstructor of the stick figure X based on the generated image G(x).
[0069] S120, using the initial network to construct a teacher network and a student network.
[0070] Demonstratively, a teacher network and a student network are constructed using the above-mentioned trained initial network. Furthermore, the teacher network is divided into four stages, which correspond to the four modules in the above-mentioned generator. For example, the content encoding module corresponds to the first stage, the style feature encoding module and the feature combination module correspond to the second and third stages, and the content decoding module corresponds to the fourth stage. It is worth noting that the stage division of the student network is the same as that of the teacher network, but the structure of the student network is simpler than that of the teacher network. Specifically, each module corresponding to each stage in the student network is block pruned and channel pruned, thereby achieving a lightweight design to ensure the effectiveness of its speed-up.
[0071] S130, input the landscape painting training samples into the teacher network and the student network respectively for feature extraction, so as to obtain a first predicted feature map and several intermediate feature maps output by the student network, and a second predicted feature map and an interactive feature map output by the teacher network; wherein the interactive feature map is obtained by inputting the intermediate feature maps extracted by the student network at different stages into the teacher network for processing.
[0072] Demonstratively, by inputting the same landscape painting training sample into the teacher network and the student network for processing, the prediction feature maps output by the teacher network and the student network can be obtained, namely, the first prediction feature map and the second prediction feature map mentioned above. In addition, since the structure of the student network has been pruned, in order to make the accuracy of the student network as consistent as possible with that of the teacher network, this embodiment adopts an interactive distillation design, that is, the intermediate feature maps extracted by the student network at different stages are input into the teacher network for processing, thereby obtaining the corresponding interactive feature map output by the teacher network.
[0073] For example, in one embodiment, Figure 5 As shown, the first intermediate feature map extracted by the first stage (stage1) of the student network is used as the input of the second stage (stage2) of the teacher network, the second intermediate feature map extracted by the second stage (stage2) of the student network is used as the input of the third stage of the teacher network, and the third intermediate feature map extracted by the third stage (stage3) of the student network is used as the input of the fourth stage of the teacher network; then, after the teacher network performs feature extraction on the corresponding intermediate feature map again, the corresponding first interaction feature map (i.e. Figure 5 The STTT feature map in the second interactive feature map (i.e. Figure 5 SSTT feature map in ) and the third interactive feature map (i.e. Figure 5In other words, STTT refers to the prediction result obtained by processing the first intermediate feature map through stage2-4 of the teacher network; SSTT refers to the prediction result obtained by processing the second intermediate feature map through stage3-4 of the teacher network; SSST refers to the prediction result obtained by processing the third intermediate feature map through stage4 of the teacher network.
[0074] S140, calculating the training loss based on the feature constraint between the first prediction feature map and the second prediction feature map, and the feature constraint between the second prediction feature map and each interaction feature map.
[0075] For example, in one embodiment, the above-mentioned feature constraints mainly include four aspects, namely, the structural similarity constraint between the two feature graphs used for calculation, the content consistency constraint, the style consistency constraint, and the regular term smoothness constraint, wherein each constraint is respectively constructed with a loss function for calculating the corresponding constraint loss value. It can be understood that the two feature graphs used for calculation can refer to the first predicted feature graph and the second predicted feature graph, or can refer to the second predicted feature graph and any interactive feature graph.
[0076] The loss function of the structural similarity constraint is constructed based on the similarity of brightness, contrast and structure between two feature maps. For example, the brightness, contrast and structure of the feature map can be represented by the image mean, standard deviation and covariance respectively.
[0077] For example, the two feature graphs used for calculation are recorded as x and y, and the structural similarity constraint is calculated by the following formula:
[0078]
[0079] Where SSIM(x,y) represents the structural similarity constraint loss between two feature graphs x and y, μ x and μ y Respectively represent the means of the two feature maps x and y, σ xy represents the covariance of two feature maps x and y, σ x 2 and σ y 2 Respectively represent the variances of the two feature maps x and y; C1 and C2 are preset constants used to avoid the situation where the denominator is 0.
[0080] The loss function of the content consistency constraint is constructed based on the content similarity between two feature maps. For example, the L1 loss function can be used to construct it, that is, it is calculated by the following formula:
[0081] L1_Loss(x,y)=‖xy‖;
[0082] Where L1_Loss represents the content consistency constraint loss between the two feature maps x and y.
[0083] Among them, the loss function of the style consistency constraint is constructed based on the difference in channel correlation between two feature maps. It can be understood that the style consistency constraint is mainly used to constrain the difference in style features between two feature images, such as color, texture, common patterns, etc.
[0084] In one embodiment, the difference between features predicted by using VGG16 pre-training can be calculated by using a Gram matrix. The Gram matrix can reflect the correlation of the predicted feature map channels, and the influence of channel correlation on style can be understood as that some channels predict mountains and some channels predict water. After establishing channel correlation, the seemingly unrelated objects of mountains and water can lay the tone of the style for landscape painting. For example, if described by a formula, there is:
[0085]
[0086] Where PerceptualLoss represents the style consistency constraint loss between two feature maps x and y, G represents the gram matrix, Represents the features predicted using VGG16 pre-training, and j represents the jth stage features.
[0087] Among them, the loss function of the regularization term smooth constraint is constructed based on the difference in gradient changes between the two feature maps. It can be understood that the regularization term smooth constraint can maintain the smoothness of the image by constraining the gradient. For example, if described by a formula, we have:
[0088] TV_Loss(x,y)=‖sum_diff(x)-sum_diff(y)‖;
[0089] Where TV_Loss(x,y) represents the regularization smoothing constraint loss between two feature maps x and y, sum_diff(x) represents the sum of the gradients of feature map x in the x-direction and y-direction; sum_diff(y) represents the sum of the gradients of feature map y in the x-direction and y-direction.
[0090] Based on the above four feature constraints and the corresponding loss functions, for the interactive distillation loss Loss between every two feature maps dist (x,y) can be calculated according to the following formula:
[0091] Loss dist (x,y)=SSIM(x,y)+L1_Loss(x,y)+PerceptualLoss(x,y)+
[0092] TV_Loss(x,y).
[0093] Exemplarily, the above training loss includes a first type of loss between the first prediction feature map and the second prediction feature map, and a second type of loss between the second prediction feature map and each interaction feature map. It can be understood that the number of second type losses is equal to the number of interaction feature maps. For example, taking three interaction feature maps as an example, three second type losses are included, namely: the loss between the second prediction feature map and the first interaction feature map, the second interaction feature map and the third interaction feature map.
[0094] For example, the sum of the first-category loss and all the second-category losses can be used as the above training loss. The first-category loss and each second-category loss can be calculated in the above manner. Finally, the total loss value Total_Loss of this training can be obtained by adding up the several loss values. If described by the formula, we have:
[0095] Total_Loss=
[0096] Loss dist (S,T)+Loss dist (STTT,T)+Loss dist (SSTT,T)+
[0097] Loss dist (SSST,T).
[0098] Of course, in some other implementations, corresponding weights may be set for the first type of loss and each second type of loss, and then the sum of the adjusted weights may be used as the above-mentioned total training loss, which is not limited here.
[0099] S150, adjusting parameters of the student network using the training loss, so as to use the trained student network as a landscape painting generation model.
[0100] Demonstratively, the training loss is used to perform gradient back propagation to continue training the student network until the preset conditions are met, and the trained student network is used as a landscape painting generation model.
[0101] Among them, the preset conditions are used to determine when to stop training, for example, may include but are not limited to, the latest total training loss value is less than a preset threshold, etc.; or, reaching a preset number of iterations, etc.; or, the total loss value and the number of iterations are satisfied at the same time, etc., which are not specifically limited here.
[0102] The landscape painting generation model obtained by the landscape painting generation model acquisition method of the present application adopts a lightweight design. At the same time, an interactive knowledge distillation method is used to ensure that the lightweight model maintains a certain accuracy. On the one hand, it can effectively improve the reasoning speed and reduce the memory occupancy. On the other hand, it provides a good foundation for deployment environment conditions (such as servers, etc.) and can also improve concurrency.
[0103] The present application also proposes a landscape painting generation method, which exemplarily includes: inputting a target stick figure into a trained landscape painting generation model to generate a corresponding landscape painting; wherein the landscape painting generation model is obtained by the method of the above embodiment. It can be understood that the target stick figure can be input by a user in the display interface of a terminal device, or can be obtained from other devices, which is not limited here.
[0104] It can be understood that the options in the above embodiment are also applicable to this embodiment, so they will not be described again here.
[0105] Figure 6 A schematic diagram of the structure of a landscape painting generation model acquisition device 100 according to an embodiment of the present application is shown. Exemplarily, the landscape painting generation model acquisition device 100 includes:
[0106] An initial network acquisition module 110 is used to construct and train an initial network for generating landscape paintings based on a generative adversarial network;
[0107] The distillation network construction module 120 is used to use the initial network to construct a teacher network and a student network respectively.
[0108] The interactive distillation training module 130 includes a feature interactive learning unit 131, a loss calculation unit 132 and a training output unit 133; wherein the feature interactive learning unit 131 is used to input the landscape painting training samples into the teacher network and the student network respectively for feature extraction, so as to obtain the first predicted feature map and the intermediate feature map output by the student network, and the second predicted feature map and the interactive feature map output by the teacher network; wherein the interactive feature map is obtained by inputting the intermediate feature map extracted by the student network at different stages into the teacher network for processing; the loss calculation unit 132 is used to calculate the training loss based on the feature constraints between the first predicted feature map and the second predicted feature map and the feature constraints between the second predicted feature map and each interactive feature map; the training output unit 133 is used to use the training loss to adjust the parameters of the student network so as to use the trained student network as a landscape painting generation model.
[0109] It can be understood that the device of this embodiment corresponds to the method for obtaining the landscape painting generation model of the above embodiment, and the optional items in the above embodiment are also applicable to this embodiment, so they will not be described repeatedly here.
[0110] Figure 7 A schematic diagram of the structure of a terminal device 10 of an embodiment of the present application is shown. Exemplarily, the terminal device 10 may be, but is not limited to, a desktop computer, an educational or entertainment robot, a portable electronic device, such as a tablet, a mobile phone, etc., and the specific existence form is not limited. In some embodiments, the terminal device 10 includes a processor 11 and a memory 12, wherein the memory 12 stores a computer program, and the processor 11 runs the computer program, so that the terminal device 10 executes the functions of each module in the above-mentioned landscape painting generation model acquisition method or the above-mentioned landscape painting generation model acquisition device.
[0111] Among them, the processor 11 can be an integrated circuit chip with signal processing capabilities. The processor can be a general-purpose processor, including a central processing unit (CPU), a graphics processing unit (GPU) and a network processor (NP), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. At least one of the general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc., which can implement or execute the disclosed methods, steps and logic block diagrams in the embodiments of the present application.
[0112] It is worth noting that since the trained landscape painting generation model adopts a lightweight design, some deployment strategies can be adopted during the deployment phase to achieve efficient deployment that allows high concurrency.
[0113] For example, in one embodiment, the processor 11 includes at least one central processing unit (CPU), so when the terminal device deploys the trained landscape painting generation model, the landscape painting generation model can be deployed in the central processing unit and accelerated by the inference engine through the Openvino tool. Openvino, namely Open Visual Inference and Neural Network Optimization, is an open visual inference and neural network optimization tool that can use the inference engine to deploy deep learning models on hardware.
[0114] For example, in another embodiment, the processor 11 includes at least one graphics processing unit (GPU). Therefore, when the terminal device deploys the trained landscape painting generation model, the landscape painting generation model can be deployed in the graphics processing unit and accelerated by the inference engine through the TensorRT tool. Similarly, TensorRT is a set of SDK tools developed by NVIDIA for high-performance inference of deep learning models on GPUs. After optimization using TensorRT, an optimized inference engine will be obtained, which can serialize the deep learning model to the hardware.
[0115] Alternatively, in another embodiment, the processor 11 includes at least one GPU and at least one CPU. For example, for some terminal devices with multi-core CPUs and graphics cards, multiple GPUs and / or CPUs can be enabled at the same time to execute the landscape painting generation model to improve resource utilization and maximize processor performance.
[0116] The memory 12 may be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable read-only memory (EEPROM), etc. The memory is used to store a computer program, and the processor may execute the computer program accordingly after receiving an execution instruction.
[0117] The present application also provides a computer-readable storage medium for storing the computer program used in the terminal device 10. For example, the computer-readable storage medium includes: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0118] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and structure diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in an alternative implementation, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the structure diagram and / or the flow diagram, and the combination of boxes in the structure diagram and / or the flow diagram, can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0119] In addition, the functional modules or units in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0120] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a smart phone, a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in the various embodiments of the present application.
[0121] The above description is only a specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application.
Claims
1. A method for obtaining a landscape painting generation model, characterized in that: include: Based on the generative adversarial network, an initial network for generating landscape paintings is constructed and trained; Using the initial network, a teacher network and a student network are constructed respectively; Inputting the landscape painting training samples into the teacher network and the student network respectively for feature extraction, so as to obtain a first prediction feature map and an intermediate feature map output by the student network, and a second prediction feature map and an interactive feature map output by the teacher network; wherein the interactive feature map is obtained by inputting the intermediate feature maps extracted by the student network at different stages into the teacher network for processing; Calculating a training loss based on a feature constraint between the first prediction feature graph and the second prediction feature graph and a feature constraint between the second prediction feature graph and each of the interaction feature graphs; The training loss is used to adjust the parameters of the student network so as to use the trained student network as a landscape painting generation model.
2. The method for acquiring a landscape painting generation model according to claim 1, characterized in that: The generative adversarial network includes a generator and a discriminator, and the generator includes a content encoding module, a feature combination module, a style feature encoding module and a content decoding module; the initial network for generating landscape paintings is constructed and trained based on the generative adversarial network, including: Input the acquired stick drawing into the generator to process it by the content encoding module to obtain a content feature map, and process the target landscape painting by the style feature encoding module to obtain a style feature map; integrate the style feature map and the content feature map by the feature combination module, and then process them by the content decoding module to obtain a landscape painting image generated based on the stick drawing; discriminate the target landscape painting and the landscape painting generated image by the discriminator to obtain a discrimination result; A learning loss is calculated based on the target landscape painting, the landscape painting image and the discrimination result, and the learning loss is used to adjust the parameters of the generative adversarial network so as to use the trained generative adversarial network as an initial network for generating landscape paintings.
3. The method for acquiring a landscape painting generation model according to claim 2, characterized in that: The method of using the initial network to construct a teacher network and a student network respectively includes: A teacher network and a student network are constructed using the initial network; wherein the teacher network includes four stages, the four stages correspond to four modules in the generator, and the modules corresponding to each stage in the student network are block pruned and channel pruned.
4. The method for acquiring a landscape painting generation model according to claim 1, characterized in that: The teacher network and the student network both include four stages; the interactive feature map is obtained by inputting the intermediate feature maps extracted by the student network at different stages into the teacher network for processing, including: Using the first intermediate feature map extracted from the first stage of the student network as the input of the second stage of the teacher network, the second intermediate feature map extracted from the second stage of the student network as the input of the third stage of the teacher network, and the third intermediate feature map extracted from the third stage of the student network as the input of the fourth stage of the teacher network; After the teacher network processes each of the intermediate feature maps, the corresponding first interaction feature map, second interaction feature map and third interaction feature map are obtained.
5. The method for acquiring a landscape painting generation model according to claim 1, characterized in that: The training loss includes a first type of loss between the first prediction feature map and the second prediction feature map, and a second type of loss between the second prediction feature map and each of the interaction feature maps; The training loss is the sum of the first type of loss and all the second type of losses.
6. The method for acquiring a landscape painting generation model according to claim 1, characterized in that: The feature constraints include a structural similarity constraint between two feature maps for calculation, a content consistency constraint, a style consistency constraint, and a regular term smoothness constraint, and each constraint is respectively constructed with a loss function for calculating the corresponding constraint loss; The loss between the two feature maps is the sum of the constraint losses.
7. The method for acquiring a landscape painting generation model according to claim 6, characterized in that: The loss function of the structural similarity constraint is constructed based on the similarity of brightness, contrast and structure between the two feature maps; The loss function of the content consistency constraint is constructed based on the content similarity between the two feature maps; The loss function of the style consistency constraint is constructed based on the difference in channel correlation between the two feature maps; The loss function of the regularization term smoothness constraint is constructed based on the difference in gradient changes between the two feature maps.
8. A method for generating a landscape painting, characterized in that: include: Input the target stick figure drawing into the trained landscape painting generation model to generate the corresponding landscape painting; wherein the landscape painting generation model is obtained by the method described in any one of claims 1-7.
9. A landscape painting generation model acquisition device, characterized in that: include: An initial network acquisition module is used to construct and train an initial network for generating landscape paintings based on a generative adversarial network; A distillation network construction module, used to use the initial network to construct a teacher network and a student network respectively; Interactive distillation training module, including feature interactive learning unit, loss calculation unit and training output unit; The feature interactive learning unit is used to input the landscape painting training samples into the teacher network and the student network for feature extraction, so as to obtain the first predicted feature map and the intermediate feature map output by the student network, and the second predicted feature map and the interactive feature map output by the teacher network; wherein the interactive feature map is obtained by inputting the intermediate feature map extracted by the student network at different stages into the teacher network for processing; The loss calculation unit is used to calculate the training loss based on the feature constraint between the first prediction feature map and the second prediction feature map and the feature constraint between the second prediction feature map and each of the interaction feature maps; The training output unit is used to adjust the parameters of the student network using the training loss, so as to use the trained student network as a landscape painting generation model.
10. A terminal device, characterized in that: The terminal device comprises a processor and a memory, wherein the memory stores a computer program, and when the processor executes the computer program, the method according to any one of claims 1 to 8 is implemented.
11. The terminal device according to claim 10, characterized in that: The processor includes a central processing unit and / or an image processor; the terminal device is also used to deploy the landscape painting generation model in the image processor and perform inference engine acceleration through the TensorRT tool; And / or, deploying the landscape painting generation model in the central processing unit and accelerating the inference engine through the Openvino tool.
12. A computer-readable storage medium, characterized in that: The computer program stores a computer program which, when executed on a processor, implements the method according to any one of claims 1 to 8.
