Training method and device for image foreground preservation model

By constructing a coding network and a feature enhancement network, combined with an attention network, and optimizing the picture foreground preservation model, the problem of foreground inconsistency and noise in the existing technology is solved, and the quality of new pictures is improved.

CN118195887BActive Publication Date: 2024-08-23北京衔远有限公司 +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410256988.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-06
Publication Date
2024-08-23
Estimated Expiration
2044-03-06

AI Technical Summary

Technical Problem

The picture foreground preservation method in the prior art cannot ensure the consistency of the foreground of the new picture and the original picture, resulting in noise in the area around the foreground and affecting the quality of the new picture.

Method used

Construct a coding network, a feature enhancement network and a decoding network, combine multiple coding networks, feature enhancement networks and attention networks to build a picture foreground preservation branch and an auxiliary branch, and optimize the picture foreground preservation model through the mean square error loss function to ensure that the foreground generated image is consistent with The loss between foreground-preserving graphs is minimized.

Benefits of technology

It improves the quality of new images, ensures foreground consistency, reduces noise in the area around the foreground, and improves the effect of image processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118195887B
    Figure CN118195887B
Patent Text Reader

Abstract

The present disclosure provides a training method and device for a picture foreground preservation model. The method includes: sequentially processing training pictures and mask segmentation maps through multiple coding networks in a picture foreground preservation branch to obtain picture coding features; sequentially processing the foreground preservation map through multiple coding networks and feature enhancement networks in an auxiliary branch to obtain picture auxiliary features output by multiple coding networks and feature enhancement networks respectively; assigning multiple picture auxiliary features as weights to the feature enhancement network and decoding network in the picture foreground preservation branch through an attention network in the auxiliary branch, so that the feature enhancement network and decoding network in the picture foreground preservation branch process the picture coding features according to the weights to obtain a foreground generation map; using a mean square error loss function to calculate the loss between the foreground generation map and the foreground preservation map, and optimizing the picture foreground preservation model according to the loss.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of image processing technology, and in particular to a method and device for training an image foreground preservation model. Background Art

[0002] In some scenarios, image generation tasks require that specific visual subjects be retained in the generated images. For example, in an image generation application where the background of a person image is replaced, the subject of the image needs to be retained, and only the background needs to be replaced. The person in the image is the foreground of the image, and other information other than the person is the background of the image (the background replaced in the person image is the background of the image). This application can be called image foreground preservation. Current methods for image foreground preservation cannot guarantee the consistency of the foreground in the new image and the original image, and cause the visual semantics of the new image to be expanded compared to the foreground surrounding area of ​​the original image (this type of expansion is equivalent to noise and affects the quality of the new image). Summary of the invention

[0003] In view of this, the embodiments of the present disclosure provide a training method, device, electronic device and computer-readable storage medium for an image foreground preservation model to solve the problem in the prior art that image foreground preservation cannot ensure foreground consistency and causes noise in the area around the foreground.

[0004] In a first aspect of an embodiment of the present disclosure, a method for training a picture foreground preservation model is provided, including: constructing a coding network, a feature enhancement network, and a decoding network corresponding to the coding network, using multiple coding networks, feature enhancement networks, and multiple decoding networks to construct a picture foreground preservation branch, and using multiple coding networks, feature enhancement networks, and attention networks to construct an auxiliary branch; using the picture foreground preservation branch and the auxiliary branch to construct a picture foreground preservation model; obtaining a training picture and a mask segmentation map and a foreground preservation map corresponding to the training picture, and inputting the training picture, the mask segmentation map, and the foreground preservation map into the picture foreground preservation model; processing the training picture through multiple coding networks in the picture foreground preservation branch in turn; The method comprises the following steps: a first step is to extract the image coding features from the image by using the image segmentation map and the mask segmentation map to obtain the image coding features; a second step is to process the foreground preservation map through the multiple encoding networks and the feature enhancement network in the auxiliary branch in turn to obtain the image auxiliary features output by the multiple encoding networks and the feature enhancement network respectively; a second step is to assign the multiple image auxiliary features as weights to the feature enhancement network and the decoding network in the image foreground preservation branch through the attention network in the auxiliary branch, so that the feature enhancement network and the decoding network in the image foreground preservation branch process the image coding features according to the weights to obtain the foreground generation map; a mean square error loss function is used to calculate the loss between the foreground generation map and the foreground preservation map, and a picture foreground preservation model is optimized according to the loss to complete the training of the picture foreground preservation model.

[0005] According to a second aspect of the disclosed embodiments, a training device for a picture foreground preservation model is provided, including: a construction module, configured to construct a coding network, a feature enhancement network, and a decoding network corresponding to the coding network, using multiple coding networks, feature enhancement networks, and multiple decoding networks to construct a picture foreground preservation branch, and using multiple coding networks, feature enhancement networks, and attention networks to construct an auxiliary branch; using the picture foreground preservation branch and the auxiliary branch to construct a picture foreground preservation model; an acquisition module, configured to acquire a training picture and a mask segmentation map and a foreground preservation map corresponding to the training picture, and input the training picture, the mask segmentation map, and the foreground preservation map into the picture foreground preservation model; an encoding module, configured to process the training picture through multiple encoding networks in the picture foreground preservation branch in sequence The auxiliary module is configured to process the foreground preservation map through multiple encoding networks and feature enhancement networks in the auxiliary branch in turn, and obtain the auxiliary features of the picture output by the multiple encoding networks and feature enhancement networks respectively; the decoding module is configured to assign the multiple auxiliary features of the picture as weights to the feature enhancement network and the decoding network in the picture foreground preservation branch through the attention network in the auxiliary branch, so that the feature enhancement network and the decoding network in the picture foreground preservation branch process the picture encoding features according to the weights to obtain the foreground generation map; the optimization module is configured to calculate the loss between the foreground generation map and the foreground preservation map by using the mean square error loss function, and optimize the picture foreground preservation model according to the loss to complete the training of the picture foreground preservation model.

[0006] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.

[0007] According to a fourth aspect of the embodiments of the present disclosure, a computer-readable storage medium is provided, which stores a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.

[0008] Compared with the prior art, the disclosed embodiments have the following beneficial effects: constructing a coding network, a feature enhancement network, and a decoding network corresponding to the coding network; using multiple coding networks, feature enhancement networks, and multiple decoding networks to construct a picture foreground preservation branch; using multiple coding networks, feature enhancement networks, and attention networks to construct an auxiliary branch; using the picture foreground preservation branch and the auxiliary branch to construct a picture foreground preservation model; obtaining a training picture and a mask segmentation map and a foreground preservation map corresponding to the training picture, and inputting the training picture, the mask segmentation map, and the foreground preservation map into the picture foreground preservation model; processing the training picture and the mask segmentation map through the multiple coding networks in the picture foreground preservation branch in turn; Figure, get the picture coding features; process the foreground preservation map through multiple encoding networks and feature enhancement networks in the auxiliary branch in turn, get the picture auxiliary features output by multiple encoding networks and feature enhancement networks respectively; assign multiple picture auxiliary features as weights to the feature enhancement network and decoding network in the picture foreground preservation branch through the attention network in the auxiliary branch, so that the feature enhancement network and decoding network in the picture foreground preservation branch process the picture coding features according to the weights, and get the foreground generation map; use the mean square error loss function to calculate the loss between the foreground generation map and the foreground preservation map, and optimize the picture foreground preservation model according to the loss to complete the training of the picture foreground preservation model. The above technical means can solve the problem that the picture foreground preservation in the prior art cannot guarantee the foreground consistency and causes noise in the surrounding area of ​​the foreground, thereby improving the quality of the new picture. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] In order to more clearly illustrate the technical solutions in the embodiments of the present disclosure, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0010] Figure 1 It is a flowchart of a method for training a picture foreground preservation model provided by an embodiment of the present disclosure;

[0011] Figure 2 The embodiment of the present disclosure provides a method for suppressing the edge area of ​​a picture;

[0012] Figure 3 It is a structural schematic diagram of a training device for a picture foreground preservation model provided by an embodiment of the present disclosure;

[0013] Figure 4 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION

[0014] In the following description, specific details such as specific system structures and technologies are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present disclosure. However, it should be clear to those skilled in the art that the present disclosure may be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid unnecessary details that hinder the description of the present disclosure.

[0015] A method and device for training a picture foreground preservation model according to an embodiment of the present disclosure will be described in detail below with reference to the accompanying drawings.

[0016] Figure 1 It is a flowchart of a method for training a picture foreground preservation model provided by an embodiment of the present disclosure. Figure 1 The training method of the image foreground preservation model can be executed by a computer or a server, or by software on the computer or the server. Figure 1 As shown, the training method of the image foreground preservation model includes:

[0017] S101, constructing a coding network, a feature enhancement network, and a decoding network corresponding to the coding network, constructing a picture foreground preservation branch using multiple coding networks, feature enhancement networks, and multiple decoding networks, and constructing an auxiliary branch using multiple coding networks, feature enhancement networks, and an attention network; constructing a picture foreground preservation model using the picture foreground preservation branch and the auxiliary branch;

[0018] S102, obtaining a training image and a mask segmentation map and a foreground preservation map corresponding to the training image, and inputting the training image, the mask segmentation map and the foreground preservation map into an image foreground preservation model:

[0019] S103, sequentially processing the training image and the mask segmentation image through multiple encoding networks in the image foreground preservation branch to obtain image encoding features;

[0020] S104, sequentially processing the foreground preservation image through multiple encoding networks and feature enhancement networks in the auxiliary branch to obtain auxiliary features of the image output by the multiple encoding networks and feature enhancement networks respectively;

[0021] S105, allocating multiple auxiliary features of the image as weights to the feature enhancement network and the decoding network in the image foreground preservation branch through the attention network in the auxiliary branch, so that the feature enhancement network and the decoding network in the image foreground preservation branch process the image coding features according to the weights to obtain a foreground generation map;

[0022] S106, using the mean square error loss function to calculate the loss between the foreground generation image and the foreground preservation image, and optimizing the image foreground preservation model based on the loss to complete the training of the image foreground preservation model.

[0023] Multiple encoding networks, feature enhancement networks, and multiple decoding networks are sequentially connected to obtain a picture foreground preservation branch. Multiple encoding networks, feature enhancement networks, and attention networks are sequentially connected to obtain an auxiliary branch. The auxiliary branch is used as a parallel branch of the picture foreground preservation branch. The attention network of the auxiliary branch is connected to the feature enhancement network of the picture foreground preservation branch and multiple decoding networks, thereby constructing a picture foreground preservation model.

[0024] The embodiments of the present application are applicable to any application that needs to maintain the foreground of an image. The foreground of an image is the subject that needs to be retained in the image. For example, when changing the background of a person in a photo, the person in the photo is the foreground of the image and needs to be retained, and the background used in the photo needs to be replaced; for example, when changing the clothes of a person in a photo, the person in the photo is the foreground of the image and needs to be retained, and the clothes of the person in the photo need to be changed.

[0025] Assuming that the embodiment of the present application is to change the background of the characters in the picture, the mask segmentation graph corresponding to the training picture is a mask graph about the characters in the training picture, and the mask graph is a picture in which the outline of the characters in the training picture is retained and the other parts are all black, which is equivalent to removing the detailed information of the characters in the training picture and other information except the characters, and only retaining the general outline of the characters. The foreground retention graph corresponding to the training picture is a picture in which all the information of the characters in the training picture is retained and the other parts are all black, which is equivalent to removing the other information except the characters in the training picture. The mask segmentation graph can be obtained by processing the training picture using a picture mask segmentation method. Picture mask segmentation is an image processing technology that divides an image into different areas by using a mask so that they can be processed separately.

[0026] The encoding network and decoding network in the image foreground preservation branch correspond to each other. The encoding network is used for encoding, and the decoding network is used for decoding. The number of encoding networks and decoding networks in the image foreground preservation branch is the same. The multiple encoding networks and feature enhancement networks used by the auxiliary branch are the same as those used by the image foreground preservation branch.

[0027] The auxiliary features of the image output by the feature enhancement network are assigned as weights to the feature enhancement network in the image foreground preservation branch through the attention network in the auxiliary branch, so that the feature enhancement network in the image foreground preservation branch processes the image coding features according to the weights. The auxiliary features of the image output by each encoding network are assigned as weights to each decoding network in the image foreground preservation branch (one encoding network corresponds to one decoding network) through the attention network in the auxiliary branch, so that each decoding network in the image foreground preservation branch processes the output of the feature enhancement network in the image foreground preservation branch according to the weights.

[0028] The foreground preservation map is a picture corresponding to the reserved part of the training picture obtained by processing the training picture in advance (equivalent to the annotation in regular training). The foreground preservation map is equivalent to the label corresponding to the training picture and the mask segmentation map. The foreground generation map is the picture corresponding to the part of the training picture that needs to be retained predicted by the image foreground preservation model.

[0029] According to the embodiment of the present application, a technical solution is provided to construct a coding network, a feature enhancement network and a decoding network corresponding to the coding network, use multiple coding networks, feature enhancement networks and multiple decoding networks to construct a picture foreground preservation branch, and use multiple coding networks, feature enhancement networks and attention networks to construct an auxiliary branch; use the picture foreground preservation branch and the auxiliary branch to construct a picture foreground preservation model; obtain a training picture and a mask segmentation map and a foreground preservation map corresponding to the training picture, and input the training picture, the mask segmentation map and the foreground preservation map into the picture foreground preservation model: sequentially process the training picture and the mask segmentation map through multiple coding networks in the picture foreground preservation branch to obtain picture coding features; sequentially process the foreground preservation map through multiple coding networks and feature enhancement networks in the auxiliary branch to obtain picture auxiliary features output by each of the multiple coding networks and feature enhancement networks; assign multiple picture auxiliary features as weights to the feature enhancement network and the decoding network in the picture foreground preservation branch through the attention network in the auxiliary branch, so that the feature enhancement network and the decoding network in the picture foreground preservation branch process the picture coding features according to the weights to obtain a foreground generation map; use the mean square error loss function to calculate the loss between the foreground generation map and the foreground preservation map, and optimize the picture foreground preservation model according to the loss to complete the training of the picture foreground preservation model. The above technical means can solve the problem in the prior art that the foreground of an image cannot be kept consistent and causes noise in the area around the foreground, thereby improving the quality of the new image.

[0030] Furthermore, an encoding network, a feature enhancement network, and a decoding network corresponding to the encoding network are constructed, including: sequentially connecting a convolutional layer, a maximum pooling layer, a batch normalization layer, a convolutional layer, and an upsampling layer to obtain an encoding network and a decoding network, wherein the encoding network and the decoding network have the same network structure, the encoding network is trained for encoding, and the decoding network is trained to complete the inverse operation decoding of encoding; sequentially connecting a convolutional layer, a residual unit, a global average pooling layer, and a fully connected layer to obtain a feature enhancement network, wherein the feature enhancement network is trained to extract more feature information from the output of the encoding network.

[0031] It should be noted that there may be multiple network layers used in the encoding network and the decoding network (the number of each network layer can be selected according to the specific situation), such as connecting multiple convolutional layers, maximum pooling layers and batch normalization layers, multiple convolutional layers and upsampling layers in sequence to obtain the encoding network and the decoding network. There may be multiple network layers used in the feature enhancement network, such as connecting multiple convolutional layers, residual units, global average pooling layers, and multiple fully connected layers in sequence to obtain a feature enhancement network. The feature enhancement network is trained to enrich the information contained in the output of the encoding network. Convolutional layers, maximum pooling layers and batch normalization layers, convolutional layers, upsampling layers, residual units, global average pooling layers, and fully connected layers are all commonly used networks and will not be described in detail here.

[0032] Furthermore, an encoding network, a feature enhancement network, and a decoding network corresponding to the encoding network are constructed, including: using U-Net as the encoding network and the decoding network, wherein the network structures of the encoding network and the decoding network are the same, the encoding network is trained for encoding, and the decoding network is trained to complete the inverse operation decoding of encoding; using the residual network as the feature enhancement network, wherein the feature enhancement network is trained to extract more feature information from the output of the encoding network.

[0033] U-Net is a U-shaped neural network, and its full name is Unified Network for Biomedical Image Segmentation. The residual network can be ResNet50.

[0034] Furthermore, the image foreground preservation branch is composed of three encoding networks, a feature enhancement network, and three decoding networks in sequence; the auxiliary branch is composed of three encoding networks, a feature enhancement network, and an attention network in sequence.

[0035] Furthermore, the training picture and the mask segmentation map are processed in sequence through multiple coding networks in the picture foreground keeping branch to obtain picture coding features, including: inside the picture foreground keeping branch: processing the training picture and the mask segmentation map through the first coding network to obtain the first coding feature; processing the first coding feature through the second coding network to obtain the second coding feature; processing the second coding feature through the third coding network to obtain the picture coding feature.

[0036] The first coding network processes the training image and the mask segmentation map to obtain the first coding feature. The first coding network can process the training image and the mask segmentation map separately to obtain the coding feature of the training image and the coding feature of the mask segmentation map, and then fuse the coding feature of the training image and the coding feature of the mask segmentation map to obtain the first coding feature. The fusion can be a conventional processing method such as multiplication.

[0037] Furthermore, the foreground preservation map is processed in sequence through multiple encoding networks and feature enhancement networks in the auxiliary branch to obtain auxiliary features of the picture output by each of the multiple encoding networks and feature enhancement networks, including: within the auxiliary branch: the foreground preservation map is processed by the first encoding network to obtain the first picture auxiliary feature; the first picture auxiliary feature is processed by the second encoding network to obtain the second picture auxiliary feature; the second picture auxiliary feature is processed by the third encoding network to obtain the third picture auxiliary feature; the third picture auxiliary feature is processed by the feature enhancement network to obtain the fourth picture auxiliary feature.

[0038] Furthermore, multiple image auxiliary features are assigned as weights to the feature enhancement network and the decoding network in the image foreground holding branch through the attention network in the auxiliary branch, so that the feature enhancement network and the decoding network in the image foreground holding branch process the image coding features according to the weights to obtain a foreground generation map, including: assigning the fourth image auxiliary feature as a weight to the feature enhancement network in the image foreground holding branch through the attention network, so that the feature enhancement network in the image foreground holding branch processes the image coding features according to the weights to obtain image enhancement features; assigning the third image auxiliary feature as a weight to the first decoding network in the image foreground holding branch through the attention network, so that the first decoding network in the image foreground holding branch processes the image enhancement features according to the weights to obtain a first decoding feature map; assigning the second image auxiliary feature as a weight to the second decoding network in the image foreground holding branch through the attention network, so that the second decoding network in the image foreground holding branch processes the first decoding feature according to the weight to obtain a second decoding feature map; assigning the first image auxiliary feature as a weight to the third decoding network in the image foreground holding branch through the attention network, so that the third decoding network in the image foreground holding branch processes the second decoding feature according to the weight to obtain a foreground generation map.

[0039] The feature enhancement network in the auxiliary branch corresponds to the feature enhancement network in the picture foreground holding branch, and the fourth picture auxiliary feature output by the feature enhancement network in the auxiliary branch is used as the weight of the picture coding feature processed by the feature enhancement network in the picture foreground holding branch. The weight may be first multiplied by the picture coding feature, and then the feature enhancement network in the picture foreground holding branch processes the multiplication result. The third encoding network in the auxiliary branch corresponds to the first decoding network in the picture foreground holding branch, and the third picture auxiliary feature output by the third encoding network in the auxiliary branch is used as the weight of the picture enhancement feature processed by the first decoding network in the picture foreground holding branch. The second encoding network in the auxiliary branch corresponds to the second decoding network in the picture foreground holding branch, and the second picture auxiliary feature output by the second encoding network in the auxiliary branch is used as the weight of the first decoding feature processed by the second decoding network in the picture foreground holding branch. The first encoding network in the auxiliary branch corresponds to the third decoding network in the picture foreground holding branch, and the first picture auxiliary feature output by the first encoding network in the auxiliary branch is used as the weight of the second decoding feature processed by the third decoding network in the picture foreground holding branch.

[0040] The first image auxiliary feature is assigned as a weight to the third decoding network in the image foreground holding branch through the attention network, so that the third decoding network in the image foreground holding branch processes the second decoding feature according to the weight to obtain the foreground generation map. Among them, the third decoding network processes the second decoding feature, which can be regarded as obtaining the third decoding feature. Because the elements in the feature represent the information of the pixels in the image, when the third decoding feature is obtained, the foreground generation map is obtained. The image itself can be regarded as a feature matrix.

[0041] It should be noted that the number of encoding networks and decoding networks in the picture foreground keeping branch can be adjusted as desired; the number of encoding networks in the auxiliary branch and the number of encoding networks in the picture foreground keeping branch can be kept consistent.

[0042] In some embodiments, the picture foreground preservation branch is composed of four encoding networks, a feature enhancement network, and four decoding networks in sequence; the auxiliary branch is composed of four encoding networks, a feature enhancement network, and an attention network in sequence.

[0043] The training image and the mask segmentation map are processed sequentially through multiple coding networks in the image foreground preservation branch to obtain image coding features, including: inside the image foreground preservation branch: the training image and the mask segmentation map are processed through the first coding network to obtain the first coding feature; the first coding feature is processed through the second coding network to obtain the second coding feature; the second coding feature is processed through the third coding network to obtain the third coding feature; the third coding feature is processed through the fourth coding network to obtain the image coding feature.

[0044] The foreground preservation map is processed by multiple encoding networks and feature enhancement networks in the auxiliary branch in turn to obtain auxiliary features of the pictures output by the multiple encoding networks and feature enhancement networks, including: inside the auxiliary branch: the foreground preservation map is processed by the first encoding network to obtain the first picture auxiliary feature; the first picture auxiliary feature is processed by the second encoding network to obtain the second picture auxiliary feature; the second picture auxiliary feature is processed by the third encoding network to obtain the third picture auxiliary feature; the third picture auxiliary feature is processed by the fourth encoding network to obtain the fourth picture auxiliary feature; the fourth picture auxiliary feature is processed by the feature enhancement network to obtain the fifth picture auxiliary feature.

[0045] The method comprises: allocating a plurality of auxiliary features of an image as weights to a feature enhancement network and a decoding network in a picture foreground holding branch through an attention network in an auxiliary branch, so that the feature enhancement network and the decoding network in the picture foreground holding branch process the picture coding features according to the weights, and obtain a foreground generation map, including: allocating a fifth auxiliary feature of the image as a weight to a feature enhancement network in a picture foreground holding branch through an attention network, so that the feature enhancement network in the picture foreground holding branch processes the picture coding features according to the weights, and obtains picture enhancement features; allocating a fourth auxiliary feature of the image as a weight to a first decoding network in a picture foreground holding branch through an attention network, so that the first decoding network in the picture foreground holding branch processes the picture enhancement features according to the weights, and obtains a fourth auxiliary feature of the image A decoding feature map; assigning the third picture auxiliary feature as a weight to the second decoding network in the picture foreground holding branch through the attention network, so that the second decoding network in the picture foreground holding branch processes the first decoding feature according to the weight to obtain a second decoding feature map; assigning the second picture auxiliary feature as a weight to the third decoding network in the picture foreground holding branch through the attention network, so that the third decoding network in the picture foreground holding branch processes the second decoding feature according to the weight to obtain a third decoding feature; assigning the first picture auxiliary feature as a weight to the fourth decoding network in the picture foreground holding branch through the attention network, so that the fourth decoding network in the picture foreground holding branch processes the third decoding feature according to the weight to obtain a foreground generation map.

[0046] In some embodiments, after optimizing the picture foreground preservation model based on the loss to complete the training of the picture foreground preservation model, the method also includes: removing the auxiliary branches of the trained picture foreground preservation model through network pruning technology to streamline the structure of the picture foreground preservation model; obtaining the target picture to be processed and the mask segmentation map corresponding to the target picture, and inputting the target picture and the mask segmentation map into the picture foreground preservation model: sequentially processing the target picture and its mask segmentation map through multiple encoding networks, feature enhancement networks and multiple decoding networks in the picture foreground preservation branch to obtain a foreground generation map of the target picture.

[0047] Figure 2 FIG. 1 is a flow chart of a method for suppressing edge areas of a picture provided by an embodiment of the present disclosure. Figure 2 As shown, the method includes:

[0048] S201, performing an expansion operation on the mask segmentation map of the target image to obtain an expanded mask map;

[0049] S202, calculating a difference image between the dilated mask image and the target image, where the difference image represents an outer edge region of a main object in the target image;

[0050] S203, multiplying the difference image by a learnable enhancement coefficient to obtain a weighted enhanced mask image;

[0051] S204, multiplying the weighted enhanced mask map with the foreground generation map of the target image to suppress the area around the main object in the target image.

[0052] The learnable enhancement coefficient is equivalent to a penalty coefficient, and a suitable penalty coefficient can be obtained through training optimization. For example, a weight enhancement mask corresponding to a difference map is annotated, and the learnable enhancement coefficient is optimized by comparing the weight enhancement mask obtained by multiplying the difference map by the learnable enhancement coefficient and the annotated weight enhancement mask. The learnable enhancement coefficient can also be a fixed penalty coefficient.

[0053] All the above-mentioned optional technical solutions can be arbitrarily combined to form optional embodiments of the present application, which will not be described one by one here.

[0054] The following are embodiments of the device disclosed herein, which can be used to execute the method embodiments disclosed herein. For details not disclosed in the device embodiments disclosed herein, please refer to the method embodiments disclosed herein.

[0055] Figure 3 FIG. 1 is a schematic diagram of a training device for a picture foreground preservation model provided by an embodiment of the present disclosure. Figure 3 As shown, the training device of the picture foreground preservation model includes:

[0056] A construction module 301 is configured to construct a coding network, a feature enhancement network, and a decoding network corresponding to the coding network, construct a picture foreground preservation branch using multiple coding networks, feature enhancement networks, and multiple decoding networks, and construct an auxiliary branch using multiple coding networks, feature enhancement networks, and an attention network; and construct a picture foreground preservation model using the picture foreground preservation branch and the auxiliary branch;

[0057] The acquisition module 302 is configured to acquire a training image and a mask segmentation map and a foreground preservation map corresponding to the training image, and input the training image, the mask segmentation map and the foreground preservation map into the image foreground preservation model:

[0058] The encoding module 303 is configured to process the training image and the mask segmentation image in sequence through multiple encoding networks in the image foreground preservation branch to obtain image encoding features;

[0059] The auxiliary module 304 is configured to process the foreground preservation image in sequence through the multiple encoding networks and feature enhancement networks in the auxiliary branch to obtain the image auxiliary features output by the multiple encoding networks and feature enhancement networks respectively;

[0060] The decoding module 305 is configured to assign multiple auxiliary features of the picture as weights to the feature enhancement network and the decoding network in the picture foreground preservation branch through the attention network in the auxiliary branch, so that the feature enhancement network and the decoding network in the picture foreground preservation branch process the picture coding features according to the weights to obtain a foreground generation map;

[0061] The optimization module 306 is configured to calculate the loss between the foreground generation map and the foreground preservation map using the mean square error loss function, and optimize the image foreground preservation model according to the loss to complete the training of the image foreground preservation model.

[0062] According to the embodiment of the present application, a technical solution is provided to construct a coding network, a feature enhancement network and a decoding network corresponding to the coding network, use multiple coding networks, feature enhancement networks and multiple decoding networks to construct a picture foreground preservation branch, and use multiple coding networks, feature enhancement networks and attention networks to construct an auxiliary branch; use the picture foreground preservation branch and the auxiliary branch to construct a picture foreground preservation model; obtain a training picture and a mask segmentation map and a foreground preservation map corresponding to the training picture, and input the training picture, the mask segmentation map and the foreground preservation map into the picture foreground preservation model: sequentially process the training picture and the mask segmentation map through multiple coding networks in the picture foreground preservation branch to obtain picture coding features; sequentially process the foreground preservation map through multiple coding networks and feature enhancement networks in the auxiliary branch to obtain picture auxiliary features output by each of the multiple coding networks and feature enhancement networks; assign multiple picture auxiliary features as weights to the feature enhancement network and the decoding network in the picture foreground preservation branch through the attention network in the auxiliary branch, so that the feature enhancement network and the decoding network in the picture foreground preservation branch process the picture coding features according to the weights to obtain a foreground generation map; use the mean square error loss function to calculate the loss between the foreground generation map and the foreground preservation map, and optimize the picture foreground preservation model according to the loss to complete the training of the picture foreground preservation model. The above technical means can solve the problem in the prior art that the foreground of an image cannot be kept consistent and causes noise in the area around the foreground, thereby improving the quality of the new image.

[0063] In some embodiments, the construction module 301 is also configured to sequentially connect the convolution layer, the maximum pooling layer and the batch normalization layer, the convolution layer and the upsampling layer to obtain the encoding network and the decoding network, wherein the network structure of the encoding network and the decoding network is the same, the encoding network is trained for encoding, and the decoding network is trained to complete the inverse operation of encoding, decoding; sequentially connect the convolution layer, the residual unit, the global average pooling layer, and the fully connected layer to obtain the feature enhancement network, wherein the feature enhancement network is trained to extract more feature information from the output of the encoding network.

[0064] In some embodiments, the construction module 301 is also configured to use U-Net as the encoding network and the decoding network, wherein the network structures of the encoding network and the decoding network are the same, the encoding network is trained for encoding, and the decoding network is trained to complete the inverse operation of encoding, decoding; and use the residual network as a feature enhancement network, wherein the feature enhancement network is trained to extract more feature information from the output of the encoding network.

[0065] The image foreground preservation branch is composed of three encoding networks, a feature enhancement network, and three decoding networks; the auxiliary branch is composed of three encoding networks, a feature enhancement network, and an attention network.

[0066] In some embodiments, the encoding module 303 is also configured to, within the picture foreground preservation branch: process the training picture and the mask segmentation map through a first encoding network to obtain a first encoding feature; process the first encoding feature through a second encoding network to obtain a second encoding feature; and process the second encoding feature through a third encoding network to obtain a picture encoding feature.

[0067] In some embodiments, the auxiliary module 304 is also configured to, within the auxiliary branch: process the foreground preservation map through a first encoding network to obtain a first image auxiliary feature; process the first image auxiliary feature through a second encoding network to obtain a second image auxiliary feature; process the second image auxiliary feature through a third encoding network to obtain a third image auxiliary feature; and process the third image auxiliary feature through a feature enhancement network to obtain a fourth image auxiliary feature.

[0068] In some embodiments, the decoding module 305 is also configured to assign the fourth picture auxiliary feature as a weight to the feature enhancement network in the picture foreground holding branch through the attention network, so that the feature enhancement network in the picture foreground holding branch processes the picture encoding feature according to the weight to obtain the picture enhancement feature; assign the third picture auxiliary feature as a weight to the first decoding network in the picture foreground holding branch through the attention network, so that the first decoding network in the picture foreground holding branch processes the picture enhancement feature according to the weight to obtain the first decoding feature map; assign the second picture auxiliary feature as a weight to the second decoding network in the picture foreground holding branch through the attention network, so that the second decoding network in the picture foreground holding branch processes the first decoding feature according to the weight to obtain the second decoding feature map; assign the first picture auxiliary feature as a weight to the third decoding network in the picture foreground holding branch through the attention network, so that the third decoding network in the picture foreground holding branch processes the second decoding feature according to the weight to obtain the foreground generation map.

[0069] In some embodiments, the picture foreground preservation branch is composed of four encoding networks, a feature enhancement network, and four decoding networks in sequence; the auxiliary branch is composed of four encoding networks, a feature enhancement network, and an attention network in sequence.

[0070] In some embodiments, the encoding module 303 is also configured to, within the picture foreground preservation branch: process the training picture and the mask segmentation map through the first encoding network to obtain a first encoding feature; process the first encoding feature through the second encoding network to obtain a second encoding feature; process the second encoding feature through the third encoding network to obtain a third encoding feature; and process the third encoding feature through the fourth encoding network to obtain a picture encoding feature.

[0071] In some embodiments, the auxiliary module 304 is also configured to, within the auxiliary branch: process the foreground preservation map through the first encoding network to obtain a first image auxiliary feature; process the first image auxiliary feature through the second encoding network to obtain a second image auxiliary feature; process the second image auxiliary feature through the third encoding network to obtain a third image auxiliary feature; process the third image auxiliary feature through the fourth encoding network to obtain a fourth image auxiliary feature; and process the fourth image auxiliary feature through the feature enhancement network to obtain a fifth image auxiliary feature.

[0072] In some embodiments, the decoding module 305 is further configured to assign the fifth picture auxiliary feature as a weight to the feature enhancement network in the picture foreground holding branch through the attention network, so that the feature enhancement network in the picture foreground holding branch processes the picture coding feature according to the weight to obtain the picture enhancement feature; assign the fourth picture auxiliary feature as a weight to the first decoding network in the picture foreground holding branch through the attention network, so that the first decoding network in the picture foreground holding branch processes the picture enhancement feature according to the weight to obtain the first decoding feature map; assign the third picture auxiliary feature as a weight to the second decoding network in the picture foreground holding branch through the attention network, so that the second decoding network in the picture foreground holding branch processes the first decoding feature according to the weight to obtain the second decoding feature map; assign the second picture auxiliary feature as a weight to the third decoding network in the picture foreground holding branch through the attention network, so that the third decoding network in the picture foreground holding branch processes the second decoding feature according to the weight to obtain the third decoding feature; assign the first picture auxiliary feature as a weight to the fourth decoding network in the picture foreground holding branch through the attention network, so that the fourth decoding network in the picture foreground holding branch processes the third decoding feature according to the weight to obtain the foreground generation map.

[0073] In some embodiments, the optimization module 306 is also configured to remove auxiliary branches of the trained image foreground preservation model through network pruning technology to streamline the structure of the image foreground preservation model; obtain the target image to be processed and the mask segmentation map corresponding to the target image, and input the target image and the mask segmentation map into the image foreground preservation model: process the target image and its mask segmentation map through multiple encoding networks, feature enhancement networks and multiple decoding networks in the image foreground preservation branch in turn to obtain a foreground generation map of the target image.

[0074] In some embodiments, the optimization module 306 is further configured to perform an expansion operation on the mask segmentation map of the target image to obtain an expanded mask map; calculate a difference map between the expanded mask map and the target image, wherein the difference map represents the outer edge area of ​​the main object in the target image; multiply the difference map by a learnable enhancement coefficient to obtain a weighted enhanced mask map; and multiply the weighted enhanced mask map by the foreground generation map of the target image to suppress the area around the main object in the target image.

[0075] It should be understood that the sequence numbers of the steps in the above embodiments do not imply a sequence of execution. The execution sequence of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present disclosure.

[0076] Figure 4 FIG. 4 is a schematic diagram of an electronic device 4 provided in an embodiment of the present disclosure. Figure 4As shown, the electronic device 4 of this embodiment includes: a processor 401, a memory 402, and a computer program 403 stored in the memory 402 and capable of running on the processor 401. When the processor 401 executes the computer program 403, the steps in the above-mentioned method embodiments are implemented. Alternatively, when the processor 401 executes the computer program 403, the functions of each module / unit in the above-mentioned device embodiments are implemented.

[0077] The electronic device 4 may be a desktop computer, a notebook, a PDA, a cloud server, or other electronic device. The electronic device 4 may include, but is not limited to, a processor 401 and a memory 402. Those skilled in the art will appreciate that Figure 4 The electronic device 4 is merely an example and does not limit the electronic device 4 , which may include more or fewer components than those shown in the figure, or different components.

[0078] The processor 401 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.

[0079] The memory 402 may be an internal storage unit of the electronic device 4, for example, a hard disk or memory of the electronic device 4. The memory 402 may also be an external storage device of the electronic device 4, for example, the electronic device 4 is equipped with a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. The memory 402 may also include both an internal storage unit of the electronic device 4 and an external storage device. The memory 402 is used to store computer programs and other programs and data required by the electronic device.

[0080] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, only the above-mentioned functional units and module divisions are used as examples for illustration. In practical applications, the above-mentioned functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. In the embodiment, each functional unit and module can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit, and the above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units.

[0081] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present disclosure implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the above-mentioned various method embodiment steps when executed by the processor. The computer program may include computer program code, and the computer program code may be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electric carrier signals and telecommunication signals.

[0082] The above embodiments are only used to illustrate the technical solutions of the present disclosure, rather than to limit them. Although the present disclosure has been described in detail with reference to the aforementioned embodiments, it should be understood by those skilled in the art that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in the protection scope of the present disclosure.

Claims

1. A method for training a picture foreground preservation model, characterized in that: include: Constructing an encoding network, a feature enhancement network, and a decoding network corresponding to the encoding network, using multiple encoding networks, the feature enhancement network, and multiple decoding networks to construct a picture foreground preservation branch, and using multiple encoding networks, the feature enhancement network, and an attention network to construct an auxiliary branch; Constructing a picture foreground preservation model using the picture foreground preservation branch and the auxiliary branch; Obtain a training picture and a mask segmentation map and a foreground preservation map corresponding to the training picture, and input the training picture, the mask segmentation map and the foreground preservation map into the picture foreground preservation model: Processing the training image and the mask segmentation image sequentially through a plurality of encoding networks in the image foreground preservation branch to obtain image encoding features; Processing the foreground preservation image sequentially through a plurality of encoding networks and feature enhancement networks in the auxiliary branch to obtain auxiliary features of the image outputted by the plurality of encoding networks and feature enhancement networks respectively; Allocating multiple auxiliary features of the picture as weights to the feature enhancement network and the decoding network in the picture foreground holding branch through the attention network in the auxiliary branch, so that the feature enhancement network and the decoding network in the picture foreground holding branch process the picture coding features according to the weights to obtain a foreground generation map; The loss between the foreground generation map and the foreground preservation map is calculated using a mean square error loss function, and the picture foreground preservation model is optimized according to the loss to complete the training of the picture foreground preservation model.

2. The method according to claim 1, characterized in that: Constructing an encoding network, a feature enhancement network, and a decoding network corresponding to the encoding network, including: Connecting the convolution layer, the maximum pooling layer and the batch normalization layer, the convolution layer and the upsampling layer in sequence to obtain the encoding network and the decoding network, wherein the encoding network and the decoding network have the same network structure, the encoding network is trained for encoding, and the decoding network is trained to complete the inverse operation decoding of the encoding; The convolutional layer, the residual unit, the global average pooling layer, and the fully connected layer are sequentially connected to obtain the feature enhancement network, wherein the feature enhancement network is trained to extract more feature information from the output of the encoding network.

3. The method according to claim 1, characterized in that: Constructing an encoding network, a feature enhancement network, and a decoding network corresponding to the encoding network, including: Using U-Net as the encoding network and the decoding network, wherein the encoding network and the decoding network have the same network structure, the encoding network is trained for encoding, and the decoding network is trained to complete the inverse operation decoding of the encoding; The residual network is used as the feature enhancement network, wherein the feature enhancement network is trained to extract more feature information from the output of the encoding network.

4. The method according to claim 1, characterized in that: The picture foreground preservation branch is composed of three encoding networks, the feature enhancement network, and three decoding networks in sequence; The auxiliary branch is composed of three encoding networks, the feature enhancement network and the attention network in sequence.

5. The method according to claim 4, characterized in that: The training image and the mask segmentation map are processed sequentially through a plurality of encoding networks in the image foreground preservation branch to obtain image encoding features, including: Inside the foreground holding branch of the picture: Processing the training image and the mask segmentation map through a first encoding network to obtain a first encoding feature; Processing the first coding feature through a second coding network to obtain a second coding feature; The second coding feature is processed by a third coding network to obtain a picture coding feature.

6. The method according to claim 4, characterized in that: The foreground preservation image is processed sequentially through multiple encoding networks and feature enhancement networks in the auxiliary branch to obtain auxiliary features of the image output by each of the multiple encoding networks and feature enhancement networks, including: Inside the auxiliary branch: Processing the foreground preservation image through a first encoding network to obtain a first image auxiliary feature; Processing the first image auxiliary feature through a second encoding network to obtain a second image auxiliary feature; Processing the second image auxiliary feature through a third encoding network to obtain a third image auxiliary feature; The third image auxiliary feature is processed by the feature enhancement network to obtain a fourth image auxiliary feature.

7. The method according to claim 6, characterized in that: The method allocates a plurality of auxiliary features of the picture as weights to a feature enhancement network and a decoding network in the picture foreground holding branch through the attention network in the auxiliary branch, so that the feature enhancement network and the decoding network in the picture foreground holding branch process the picture coding features according to the weights to obtain a foreground generation map, including: Allocating the fourth image auxiliary feature as a weight to the feature enhancement network in the image foreground preservation branch through the attention network, so that the feature enhancement network in the image foreground preservation branch processes the image coding feature according to the weight to obtain an image enhancement feature; Allocating the third picture auxiliary feature as a weight to the first decoding network in the picture foreground keeping branch through the attention network, so that the first decoding network in the picture foreground keeping branch processes the picture enhancement feature according to the weight to obtain a first decoding feature map; Allocating the second picture auxiliary feature as a weight to the second decoding network in the picture foreground keeping branch through the attention network, so that the second decoding network in the picture foreground keeping branch processes the first decoding feature according to the weight to obtain a second decoding feature map; The first image auxiliary feature is assigned as a weight to the third decoding network in the image foreground keeping branch through the attention network, so that the third decoding network in the image foreground keeping branch processes the second decoding feature according to the weight to obtain a foreground generation map.

8. A training device for a picture foreground preservation model, characterized in that: include: A construction module is configured to construct an encoding network, a feature enhancement network, and a decoding network corresponding to the encoding network, use multiple encoding networks, the feature enhancement network, and multiple decoding networks to construct a picture foreground preservation branch, and use multiple encoding networks, the feature enhancement network, and an attention network to construct an auxiliary branch; Constructing a picture foreground preservation model using the picture foreground preservation branch and the auxiliary branch; The acquisition module is configured to acquire a training picture and a mask segmentation map and a foreground preservation map corresponding to the training picture, and input the training picture, the mask segmentation map and the foreground preservation map into the picture foreground preservation model: An encoding module is configured to process the training image and the mask segmentation map through multiple encoding networks in the image foreground preservation branch in sequence to obtain image encoding features; An auxiliary module is configured to process the foreground preservation image through multiple encoding networks and feature enhancement networks in the auxiliary branch in sequence to obtain auxiliary features of the image output by the multiple encoding networks and feature enhancement networks respectively; A decoding module is configured to assign multiple auxiliary features of the picture as weights to a feature enhancement network and a decoding network in the picture foreground holding branch through the attention network in the auxiliary branch, so that the feature enhancement network and the decoding network in the picture foreground holding branch process the picture encoding features according to the weights to obtain a foreground generation map; The optimization module is configured to calculate the loss between the foreground generation map and the foreground preservation map using a mean square error loss function, and optimize the image foreground preservation model according to the loss to complete the training of the image foreground preservation model.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.