Image segmentation model training method, image processing method and device

Through the consistency training and feature layer determination of the image segmentation model, the problem of poor rendering results when the shape of the target object is complex is solved, higher segmentation accuracy and stability are achieved, and the image quality is improved.

CN112529913BActive Publication Date: 2024-10-29BEIJING DAJIA INTERNET INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011476003.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-14
Publication Date
2024-10-29
Estimated Expiration
2040-12-14

AI Technical Summary

Technical Problem

In the existing technology, when the shape of the target object is complex, the image rendering effect is not realistic enough and the image quality is poor.

Method used

An image segmentation model training method is adopted. By obtaining the sample image and its affine transformation image, combined with the consistency training method, the cross-entropy loss function and the segmentation results of the affine transformation image are used for supervised learning to improve the segmentation accuracy of the model, and Conduct consistent training for multiple target neural network layers and determine designated feature layers to improve model stability and accuracy.

Benefits of technology

It significantly improves the segmentation accuracy and stability of the image segmentation model, can accurately segment and render complex-shaped target objects, and improves the realism and image quality of applications such as virtual hair dyeing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112529913B_ABST
    Figure CN112529913B_ABST
Patent Text Reader

Abstract

The present application provides an image segmentation model training method, an image processing method and a device. The training method includes, in the training stage of the image segmentation model, using the target segmentation result of the sample image and the affine transformation image of the sample image to train the image segmentation model to be trained. In the model training stage, not only the target segmentation result is used for supervised learning, but also the segmentation result of the affine transformation image is combined for consistency training and learning, thereby enabling the image segmentation model to be generalized, and segmentation results in different situations are learned, thereby improving the segmentation accuracy of the image segmentation model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to an image segmentation model training method, an image processing method and a device. Background Art

[0002] The Internet not only brings people closer together, but also allows people to find like-minded friends. The popularity of short videos allows people to use their spare time to learn about interesting things on the Internet, and they can also make their own short videos in their spare time to share with others.

[0003] Relying on the development of artificial intelligence technology, the cost for ordinary users to produce short videos is getting lower and lower, and many users' production ideas can be realized by relying on video production software.

[0004] For example, thanks to artificial intelligence technology, objects of interest can be segmented from the user's video images, and then image processing can be performed on the objects of interest. For example, the "sky replacement function" can segment the "sky area" from the real image taken by the user and then render rainbows, sunsets, etc. in the sky area.

[0005] Another typical application is virtual hair dyeing technology, which segments the user's hair area from the user's video image and then performs virtual hair dyeing on it. The user can view the hair dyeing effect by shooting a video. There are countless applications like this, which enrich people's Internet life.

[0006] In the related art, such applications mostly rely on artificial intelligence technology to achieve. The implementation steps can be summarized as first using a segmentation model to segment the target object to be rendered (such as the sky area, the hair area) from the real picture taken, and then performing image processing on the target object.

[0007] However, the inventors have found that when the target object has a complex shape, the rendering effect of the target object in the related art is still not realistic enough and the image quality is poor. Summary of the invention

[0008] The purpose of this application is to provide an image segmentation model training method, an image processing method and a device, which are used to solve the problem that when the shape of the target object is complex, the rendering effect of the target object in the related art is still not realistic enough and the image quality is poor.

[0009] In a first aspect, the present application provides a method for training an image segmentation model, wherein the segmentation model is used to segment a target object from an image, and the method comprises:

[0010] Acquire a sample image, an affine transformation image corresponding to the sample image, and a target segmentation result of a target object in the sample image, wherein the affine transformation image is obtained by affine transformation of the sample image;

[0011] Inputting the sample image and the affine transformed image into the image segmentation model to be trained respectively to segment the target object, thereby obtaining a first segmentation result of the target object in the sample image and a second segmentation result of the target object in the affine transformed image; wherein the first segmentation result is subjected to affine transformation to obtain a transformation result;

[0012] Determine a first loss value according to the first segmentation result and the target segmentation result, and determine a second loss value according to the transformation result and the second segmentation result;

[0013] Determining a total loss value according to the first loss value and the second loss value;

[0014] The image segmentation model to be trained is trained according to the total loss value to obtain a trained image segmentation model.

[0015] In some possible embodiments, the sample image is further associated with a similar image, and the similarity between the similar image and the sample image is less than a preset threshold. After acquiring the sample image, the method further includes:

[0016] Inputting the sample image and the similar image into the image segmentation model to be trained respectively, and obtaining the processing result of the sample image and the processing result of the similar image output by the specified feature layer in the image segmentation model to be trained;

[0017] Determining a third loss value according to the processing result of the sample image and the processing result of the similar image;

[0018] The using the first loss value and the second loss value to determine the total loss value includes:

[0019] The total loss value is determined using the first loss value, the second loss value, and the third loss value.

[0020] In some possible embodiments, before obtaining the processing result of the sample image and the processing result of the similar image output by the specified feature layer in the image segmentation model to be trained, the method further includes:

[0021] For each of the multiple target neural network layers in the image segmentation model to be trained, respectively execute:

[0022] After the sample image and the similar image are respectively input into the image segmentation model to be trained, a feature map of the sample image and a feature map of the similar image output by the target neural network layer are obtained;

[0023] Obtaining a difference feature map according to a difference between the feature map of the sample image and the feature map of the similar image;

[0024] The designated feature layer is determined according to the difference feature maps corresponding to each target neural network layer, wherein the feature point values ​​of the difference feature map of the designated feature layer are greater than the difference threshold.

[0025] In some possible embodiments, determining the designated feature layer according to the difference feature maps corresponding to each target neural network layer includes:

[0026] Determine the average difference value of each feature point of the difference feature map of each target neural network layer;

[0027] The target neural network layer whose average difference value is greater than the difference threshold is determined as the designated feature layer.

[0028] In a second aspect, the present application provides an image processing method using any of the above segmentation models, the method comprising:

[0029] The image to be processed is input into a trained image segmentation model to obtain a segmentation result of the object to be processed in the image to be processed; the trained image segmentation model is trained according to the method of the first aspect provided in an embodiment of the present application.

[0030] In a possible embodiment, the image to be processed is a frame image in a video frame sequence, and after obtaining the segmentation result of the object to be processed in the image to be processed, the method further includes:

[0031] Based on the fact that the image to be processed is a non-first frame image in the video frame sequence, obtaining a segmentation result of the object to be processed of at least one frame of target image, wherein each frame of the target image in the at least one frame of target image is located before the image to be processed in the order of the frame sequence;

[0032] The segmentation result of the at least one frame of the target image is used to perform smoothing processing on the segmentation result of the image to be processed.

[0033] In a third aspect, the present application provides an image segmentation model training device, wherein the image segmentation model is used to segment a target object from an image, and the device comprises:

[0034] A sample image acquisition module is configured to acquire a sample image, an affine transformation image corresponding to the sample image, and a target segmentation result of a target object in the sample image, wherein the affine transformation image is obtained by affine transformation of the sample image;

[0035] The segmentation result determination module is configured to execute the segmentation of the target object by inputting the sample image and the affine transformation image into the image segmentation model to be trained, respectively, to obtain a first segmentation result of the target object in the sample image and a second segmentation result of the target object in the affine transformation image; wherein the first segmentation result is subjected to affine transformation to obtain a transformation result;

[0036] a loss value acquisition module, configured to determine a first loss value according to the first segmentation result and the target segmentation result, and determine a second loss value according to the transformation result and the second segmentation result;

[0037] a total loss determination module, configured to determine a total loss value according to the first loss value and the second loss value;

[0038] The model parameter adjustment module is configured to execute training of the image segmentation model to be trained according to the total loss value to obtain a trained image segmentation model.

[0039] In some possible embodiments, the sample image is further associated with a similar image, and the similarity between the similar image and the sample image is less than a preset threshold, and the device further includes:

[0040] A third loss acquisition module is configured to, after the sample image acquisition module acquires the sample image, input the sample image and the similar image into the image segmentation model to be trained, respectively, to obtain a processing result of the sample image and a processing result of the similar image output by a specified feature layer in the image segmentation model to be trained;

[0041] Determining a third loss value according to the processing result of the sample image and the processing result of the similar image;

[0042] The total loss determination module is configured to determine the total loss value by using the first loss value, the second loss value and the third loss value.

[0043] In some possible embodiments, before the third loss acquisition module obtains the processing result of the sample image and the processing result of the similar image output by the designated feature layer in the image segmentation model to be trained, the device further includes:

[0044] The network layer determination unit is configured to respectively perform, for each of the multiple target neural network layers in the image segmentation model to be trained:

[0045] After the sample image and the similar image are respectively input into the image segmentation model to be trained, a feature map of the sample image and a feature map of the similar image output by the target neural network layer are obtained;

[0046] Obtaining a difference feature map according to a difference between the feature map of the sample image and the feature map of the similar image;

[0047] The designated feature layer is determined according to the difference feature maps corresponding to each target neural network layer, wherein the feature point values ​​of the difference feature map of the designated feature layer are greater than the difference threshold.

[0048] In some possible embodiments, the network layer determination unit is configured to determine an average difference value of each feature point of the difference feature map of each target neural network layer;

[0049] The target neural network layer whose average difference value is greater than the difference threshold is determined as the designated feature layer.

[0050] In a fourth aspect, the present application provides an image processing device using any of the above segmentation models, the device comprising:

[0051] The image segmentation module is configured to input the image to be processed into a trained image segmentation model to obtain a segmentation result of the object to be processed in the image to be processed; the trained image segmentation model is trained according to the method of the first aspect provided in an embodiment of the present application.

[0052] In some possible embodiments, the image to be processed is a frame image in a video frame sequence, and the image processing module is configured to input the image to be processed into a trained image segmentation model to obtain a segmentation result of the object to be processed in the image to be processed, and the device further includes:

[0053] a smoothing processing module, configured to execute, based on the fact that the image to be processed is not the first frame image in the video frame sequence, obtaining a segmentation result of the object to be processed of at least one frame of target image, wherein each frame of the target image in the at least one frame of target image is located before the image to be processed in the order of the frame sequence;

[0054] The segmentation result of the at least one frame of the target image is used to perform smoothing processing on the segmentation result of the image to be processed.

[0055] In the fifth aspect, another embodiment of the present application also provides an electronic device, comprising at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method of the first aspect and / or the second aspect provided in the embodiment of the present application.

[0056] In the sixth aspect, another embodiment of the present application further provides a computer storage medium, wherein the computer storage medium stores a computer program, and the computer program is used to enable a computer to execute the method of the first aspect and / or the second aspect provided by the embodiment of the present application.

[0057] In the embodiment of the present application, during the training stage of the image segmentation model, not only the annotated labels (i.e., the target segmentation results representing the correct position distribution of the target object in the sample image) are used to train the image segmentation model to be trained, but also the consistency training method is combined to train the image segmentation model to improve the accuracy of the image segmentation model. That is, the sample image is affine transformed to obtain an affine transformed image, and the segmentation result of the original sample image will learn from the segmentation result of the affine transformed image after the same affine transformation. Therefore, in the model training stage, not only the labels are used for supervised learning, but also the segmentation results of the affine transformed image are combined for learning, so that the model can be generalized and the segmentation results in different situations can be learned, thereby improving the segmentation accuracy of the image segmentation model. The image segmentation model trained in the embodiment of the present application can not only accurately perform dark dyeing on the hair area in the virtual hair dyeing scene, but also accurately segment and render the hair area in the light hair dyeing scene.

[0058] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or be understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0060] Figure 1a This is a schematic diagram of a hair tail region frame according to an embodiment of the present application;

[0061] Figure 1bThis is a schematic diagram of an undyed hair edge area according to one embodiment of the present application;

[0062] Figure 2a is a schematic diagram of an application environment according to an embodiment of the present application;

[0063] Figure 2b A schematic diagram of a flow chart of a segmentation training model method according to an embodiment of the present application;

[0064] Figure 2c A schematic diagram of a mask for segmenting a hair region of a portrait according to an embodiment of the present application;

[0065] Figure 2d A schematic diagram of a consistency training method according to an embodiment of the present application;

[0066] Figure 2e A schematic diagram of output results of a specified network layer according to an embodiment of the present application;

[0067] Figure 3 is an overall flow chart of an image processing method according to an embodiment of the present application;

[0068] Figure 4 A schematic diagram of an image segmentation model training device according to an embodiment of the present application;

[0069] Figure 5 is a schematic diagram of an image processing device according to an embodiment of the present application;

[0070] Figure 6 A schematic diagram of an electronic device for training an image segmentation model according to an embodiment of the present application. DETAILED DESCRIPTION

[0071] The technical solutions in the embodiments of the present application will be described clearly and in detail below in conjunction with the accompanying drawings. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in the text is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.

[0072] In the description of the embodiments of the present application, unless otherwise specified, the term "multiple" refers to two or more, and other quantifiers are similar and should be understood. The preferred embodiments described herein are only used to illustrate and explain the present application, and are not used to limit the present application. In addition, the embodiments of the present application and the features therein may be combined with each other if there is no conflict.

[0073] To further illustrate the technical solution provided by the embodiment of the present application, this is described in detail below in conjunction with the accompanying drawings and specific implementation methods. Although the embodiment of the present application provides the method operation steps as shown in the following embodiments or drawings, more or fewer operation steps may be included in the method based on routine or no creative labor. In the steps where there is no necessary causal relationship logically, the execution order of these steps is not limited to the execution order provided by the embodiment of the present application. The method can be executed in the order of the method shown in the embodiment or drawings or in parallel during the actual processing process or when the control device is executed.

[0074] Taking virtual hair dyeing as an example, this technology needs to first segment the hair area of ​​the portrait from the image through an image segmentation model, then dye the hair area, and render the dyeing result to show it to the user. The inventors found that the existing virtual hair dyeing technology is mostly based on detection and segmentation. Due to the inaccurate detection of the hair area of ​​the portrait, the border of the hair tail area is obvious (such as Figure 1a A rectangular gray area appears at the bottom edge of the image. In addition, due to inaccurate segmentation of the hair area, it is easy to cause the edge area of ​​the portrait hair to be undyed (such as Figure 1b The hair area near the face is shown not being successfully lightened, resulting in the hair area near the face remaining in its original dark color).

[0075] Therefore, when the segmentation result of the segmentation model for the hair area is inaccurate, the subsequent image processing results are likely to lead to poor dyeing effects and lack of realism.

[0076] In view of this, the embodiments of the present application provide an image segmentation model training method and an image processing method. The image segmentation model provided in the embodiments of the present application can be applied to the segmentation of any target, for example, it can be a hair area in an image (such as human hair, animal hair), or any object such as trees, flowers, animals, etc., that is, the target object of the segmentation can be determined according to actual needs.

[0077] In addition, the segmentation model provided in the embodiments of the present application can be a semantic segmentation model, an instance segmentation model, and a panoramic segmentation model.

[0078] The inventive concept of the present application is as follows: a sample image as a training sample is associated with a pre-labeled label, and the label is a target segmentation result used to represent the position distribution of the target object in the sample image. The first loss value is determined by the target segmentation result and the segmentation result of the sample image by the segmentation model. Furthermore, in order to improve the segmentation accuracy of the target object by the segmentation model, the sample image is affine transformed to obtain an affine transformed image, and the segmentation results of the sample image and the affine transformed image are subjected to consistency training so that the segmentation result of the sample image can learn from the segmentation result of the affine transformed image. When performing consistency training, a second loss value can be obtained through the segmentation results of the sample image and the affine transformed image. The segmentation model of the image to be trained is trained and learned based on the first loss value and the second loss value, so as to improve the segmentation accuracy of the image segmentation model.

[0079] In order to make the output results of the segmentation model more accurate, this application not only uses sample images and affine transformed images for consistency training, but also uses sample images and similar images for consistency training, so as to further improve the stability and accuracy of the model's processing results for similar images.

[0080] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or be understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings.

[0081] The image segmentation model training method and image processing method in the embodiments of the present application are described in detail below with reference to the accompanying drawings.

[0082] See also Figure 2a , is a schematic diagram of an application environment according to an embodiment of the present application, including a network 100 , at least one terminal device 101 and a server 102 .

[0083] Among them, at least one terminal device 101 communicates with the server 102 through the network 100, and the network 100 can be a wired network 100 or a wireless network 100. The image segmentation model training method and the image segmentation method can be executed by the terminal device 101, or by the server 102, or by at least one terminal device 101 and the server 102 in collaboration.

[0084] After the segmentation model is trained, the segmentation model is sent to the terminal device 101. During implementation, taking the short video platform and virtual hair dyeing as an example, the user shoots a short video through the terminal device 101. When shooting, the virtual hair dyeing function is selected to perform virtual hair dyeing on the captured image. The terminal device 101 can segment the hair area of ​​the user's portrait in real time through the segmentation model to obtain the hair area of ​​the user's portrait, and then dye the segmented hair area and display the hair dyeing effect. After the user saves the virtual hair dyeing video, it can be uploaded to the server 102 and published on the network for other users to watch.

[0085] In another embodiment, the video shot by the user can be uploaded to the server 102 in real time for hair area segmentation and hair dyeing, and the hair dyeing result can be transmitted back to the terminal device 101 in real time for display.

[0086] It should be noted that the terminal device 101 can be, but is not limited to, various desktop computers, laptop computers, smart phones, tablet computers and portable wearable devices, or special equipment for generating images to be segmented or image samples to be segmented, such as CT (Computed Tomography) equipment, MRI (Magnetic Resonance Imaging) equipment or electrocardiographs in the medical field. The server 102 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services.

[0087] Below through Figure 2b The image segmentation model training method provided in the embodiment of the present application is described in detail, including the following steps:

[0088] Step 201: Acquire a sample image, an affine transformation image corresponding to the sample image, and a target segmentation result of a target object in the sample image, wherein the affine transformation image is obtained by affine transformation of the sample image.

[0089] In a possible embodiment, more experimental sample data are obtained by adding noise (such as Gaussian, Gaussian noise, Poisson, Poisson noise, Salt, salt and pepper noise) to the sample image and performing affine transformation processing such as translation, scaling, shearing and rotation on the sample image. The obtained experimental sample data is used to perform consistency training on the segmentation model to facilitate correction of the output result of the segmentation model.

[0090] Step 202: Input the sample image and the affine transformed image into the image segmentation model to be trained respectively to segment the target object, and obtain a first segmentation result of the target object in the sample image and a second segmentation result of the target object in the affine transformed image; wherein the first segmentation result is obtained after affine transformation.

[0091] Step 203: Determine a first loss value according to the first segmentation result and the target segmentation result, and determine a second loss value according to the transformation result and the second segmentation result.

[0092] During implementation, the present application may use a semantic segmentation model to segment images. Due to the complexity of the image and the small edge ends, when semantically segmenting a target object, there are technical problems such as high segmentation difficulty and obvious linear jitter of the segmentation mask. For example, when semantically segmenting the hair area of ​​a portrait, there are often problems such as inaccurate hair segmentation mask and obvious linear jitter of the hair segmentation mask. The present application uses a cross entropy loss function to train the semantic segmentation model. For example, a sample image is input into the segmentation model to obtain a segmentation mask of the hair area of ​​the portrait (such as Figure 2c The figure shows the hair area identified by the semantic segmentation model. The obtained hair area is then compared with the pre-labeled label to obtain the first cross entropy loss value.

[0093] In the training stage of the semantic segmentation model, in order to enable the semantic segmentation model to output more stable segmentation results, on the basis of using the cross entropy function to calibrate the segmentation model, consistency training is further used to obtain more relevant parameters for calibrating the segmentation model. Figure 2d As shown in the figure, the semantic segmentation model is the image segmentation model to be trained.

[0094] First, the sample image is input into the image segmentation model to be trained to obtain a first segmentation result. Then, the first segmentation result is subjected to affine transformation processing such as translation, scaling, shearing and rotation to obtain a transformation result of the first segmentation result after affine transformation processing. Next, the affine transformation image associated with the sample image is input into the image segmentation model to be trained to obtain a segmentation mask of the affine transformation image, and the segmentation mask of the affine transformation image is used as the second segmentation result. Finally, the second segmentation result is learned from the transformation result obtained after affine transformation processing of the first segmentation result using the L2 loss function in the cross entropy loss function. For example, the subsequent steps 204, 205 and 206 can be executed to complete consistency training.

[0095] Step 204: Determine a first loss value according to the first segmentation result and the target segmentation result, and determine a second loss value according to the transformation result and the second segmentation result.

[0096] Step 205: Determine a total loss value according to the first loss value and the second loss value.

[0097] Step 206: Train the image segmentation model to be trained according to the total loss value to obtain a trained image segmentation model.

[0098] During the consistency training phase of the image segmentation model to be trained, in addition to supervising the segmentation mask of the sample image and the segmentation mask of the associated affine transformed image (i.e., using the cross entropy function to correct the model parameters), the sample image and similar images are also used for consistency training.

[0099] That is, when images are similar, their segmentation masks should be similar. If the segmentation masks of similar images are very different, it means that the segmentation result of the image segmentation model to be trained for the target image is not stable and accurate enough. Therefore, in the embodiment of the present application, in order to further improve the segmentation accuracy of the image segmentation model for the target object, the present application proposes to perform consistency training on the neural network layer of the intermediate layer of the image segmentation model to be trained.

[0100] In order to determine which neural network layers (hereinafter referred to as designated feature layers) need to be trained for consistency, the present application embodiment provides the following two implementation methods for determining the designated feature layers:

[0101] Method 1: After the sample image and the similar image associated with the sample image are input into the image segmentation model to be trained, the feature maps of the sample image and the similar image in each target neural network layer are obtained. The difference information at each feature position between the feature maps of the sample image and the similar image is determined to obtain a feature difference map.

[0102] During implementation, first input the sample image and the similar image into the image segmentation model to be trained, record the output results of the two images in each target neural network layer, and visualize the recorded results for easy observation. Finally, compare the visualized output results of each target neural network layer to determine which neural network layers are designated as the feature layers. This method can be used to manually judge the feature points on the difference feature map, and intuitively and accurately obtain the designated feature layers with large segmentation results in the image segmentation model to be trained. The visualization results of the output results are shown in the figure below. Figure 2e As shown, row H1 is a visualization of the output result features of the sample image at the target neural network layer (i.e., the above-mentioned feature map). Row H2 is a visualization of the output result features of the similar image at the target neural network layer. Row H3 is a visualization of the difference between the output result features corresponding to the sample image and the similar image (i.e., the above-mentioned difference feature map).

[0103] The visualization can be implemented based on the segmentation mask. For example, each pixel in the segmentation mask corresponds to a probability value, which is used to indicate the probability that the corresponding pixel is the target object. After obtaining the probability value of each pixel, each probability value can be arranged according to the position of the pixel to obtain the initial mask map; in addition, the probability value of each pixel can be converted into a corresponding grayscale value. For example, a probability value of 1 is converted into a grayscale value of 255, a probability value of 0.5 is converted into a grayscale value of 127, and a probability value of 0 is converted into a grayscale value of 0. In this way, a grayscale image corresponding to the probability value (i.e., the visualization result) can be output for display.

[0104] Method 2: In order to automatically locate the specified feature layer for consistency training. In the embodiment of the present application, the difference features of the sample image and the similar image in the output results of each target neural network layer can be extracted, and the average difference value can be obtained through the difference features. The average difference value is compared with the preset threshold to screen out the specified feature layer.

[0105] During implementation, the sample image and the similar image are first input into each target neural network layer in the image segmentation model to be trained, and the segmentation results of the sample image and the similar image are outputted in each target neural network layer. Then, the pixel points of the portrait hair area are extracted from the obtained segmentation results of the sample image and the segmentation results of the similar image, and a difference operation is performed. The average difference value of the portrait hair area in each difference feature map is obtained through the obtained difference value, and the target neural network layer whose average difference value is greater than the preset difference threshold is determined as the designated feature layer.

[0106] After determining the designated feature layer in the image segmentation model to be trained in the above manner, the segmentation mask of the sample image and the segmentation mask of the similar image obtained in the designated feature layer are subtracted to obtain a third loss value for training the image segmentation model to be trained, and the image segmentation model to be trained is trained using the first loss value, the second loss value and the third loss value.

[0107] During implementation, the first loss value, the second loss value, and the third loss value can be weighted and summed according to preset weights to obtain a total loss value for training the image segmentation model to be trained. The image segmentation model to be trained is trained according to the obtained total loss value to achieve the purpose of correcting the model output result.

[0108] Based on the same inventive concept, the present application also provides an image processing method using a segmentation model trained by an embodiment of the present application, such as Figure 3 Shown is a flow chart of the method, comprising the following steps:

[0109] Step 301: inputting an image to be processed into a trained image segmentation model to obtain a segmentation result of an object to be processed in the image to be processed.

[0110] The trained image segmentation model is trained according to the above-mentioned image segmentation model training method. The image processing operation can be set according to actual needs, such as "changing the sky", "virtual hair dyeing", adding virtual hair accessories for users, changing facial features for users, etc.

[0111] In order to further improve the image processing effect, the embodiment of the present application selects a preset frame image of the image to be processed forward along the time axis and obtains the segmentation result of the preset frame image. The segmentation result is smoothed by the segmentation result of the image to be processed to optimize the segmentation mask of the target object, so that the segmentation mask has a certain motion continuity in the time domain, thereby weakening the jitter phenomenon of the image processing effect.

[0112] In order to facilitate the operation during implementation, the previous frame of the image to be processed may be selected to perform smoothing on the segmentation mask of the image to be processed.

[0113] In addition, in another embodiment, in order to cope with complex scenes, such as the situation where multiple people may enter the same video during the production stage, portrait tracking can be performed on each target to complete accurate image processing of each target. It can be implemented as follows: portrait tracking is performed on the same target in the frame sequence of the video to obtain the position information of the same target in each frame, and then the segmentation result of the target object of the same target in the at least one frame target image is obtained based on the position information of the same target. For each target, the segmentation result of the target is smoothed using the segmentation results of multiple consecutive frames of images of the target, and then subsequent image processing operations are performed.

[0114] For example, when a user records a video of himself with the virtual hair dyeing function turned on, he records other people during the recording process and then records himself again. Since the person in the previous frame image is not the user, if the previous frame image is used as the target image at this time, the dyeing of the user's hair area (i.e., the segmentation mask of the above-mentioned image to be processed) after smoothing will not achieve the expected effect. Therefore, in order to ensure that the person in the target image used for smoothing is the same as the person in the image to be processed. Before performing the smoothing operation, a portrait tracking operation is also required. To ensure that the segmentation mask for smoothing is the segmentation mask of the same person.

[0115] Based on the same inventive concept, the present application also provides an image segmentation model training device 400, such as Figure 4 As shown, the device comprises:

[0116] The sample image acquisition module 401 is configured to execute acquisition of a sample image, an affine transformation image corresponding to the sample image, and a target segmentation result of a target object in the sample image. The affine transformation image is obtained by affine transformation of the sample image.

[0117] The segmentation result determination module 402 is configured to execute segmentation of the target object by respectively inputting the sample image and the affine transformation image into the image segmentation model to be trained, thereby obtaining a first segmentation result of the target object in the sample image and a second segmentation result of the target object in the affine transformation image; wherein the first segmentation result is obtained after affine transformation.

[0118] A loss value acquisition module 403 is configured to determine a first loss value according to the first segmentation result and the target segmentation result, and determine a second loss value according to the transformation result and the second segmentation result;

[0119] The total loss determination module 404 is configured to determine a total loss value according to the first loss value and the second loss value.

[0120] The model parameter adjustment module 405 is configured to train the image segmentation model to be trained according to the total loss value to obtain a trained image segmentation model.

[0121] In some possible embodiments, the sample image is further associated with a similar image, and the similarity between the similar image and the sample image is less than a preset threshold, and the device further includes:

[0122] A third loss acquisition module is configured to, after the sample image acquisition module acquires the sample image, input the sample image and the similar image into the image segmentation model to be trained, respectively, to obtain a processing result of the sample image and a processing result of the similar image output by a specified feature layer in the image segmentation model to be trained;

[0123] Determining a third loss value according to the processing result of the sample image and the processing result of the similar image;

[0124] The total loss determination module is configured to determine the total loss value by using the first loss value, the second loss value and the third loss value.

[0125] In some possible embodiments, before the third loss acquisition module obtains the processing result of the sample image and the processing result of the similar image output by the designated feature layer in the image segmentation model to be trained, the device further includes:

[0126] The network layer determination unit is configured to respectively perform, for each of the multiple target neural network layers in the image segmentation model to be trained:

[0127] After the sample image and the similar image are respectively input into the image segmentation model to be trained, a feature map of the sample image and a feature map of the similar image output by the target neural network layer are obtained;

[0128] Obtaining a difference feature map according to a difference between the feature map of the sample image and the feature map of the similar image;

[0129] The designated feature layer is determined according to the difference feature maps corresponding to each target neural network layer, wherein the feature point values ​​of the difference feature map of the designated feature layer are greater than the difference threshold.

[0130] In some possible embodiments, the network layer determination unit is configured to determine an average difference value of each feature point of the difference feature map of each target neural network layer;

[0131] The target neural network layer whose average difference value is greater than the difference threshold is determined as the designated feature layer.

[0132] In addition, the present application also provides an image processing device 500 using any of the above segmentation models, such as Figure 5 As shown, the device comprises:

[0133] The image segmentation module 501 is configured to input the image to be processed into a trained image segmentation model to obtain a segmentation result of the object to be processed in the image to be processed; wherein the trained image segmentation model is trained according to the above-mentioned image segmentation model training method.

[0134] In some possible embodiments, the image to be processed is a frame image in a video frame sequence, and the image processing module is configured to input the image to be processed into a trained image segmentation model to obtain a segmentation result of the object to be processed in the image to be processed, and the device further includes:

[0135] a smoothing processing module, configured to execute, based on the fact that the image to be processed is not the first frame image in the video frame sequence, obtaining a segmentation result of the object to be processed of at least one frame of target image, wherein each frame of the target image in the at least one frame of target image is located before the image to be processed in the order of the frame sequence;

[0136] The segmentation result of the at least one frame of the target image is used to perform smoothing processing on the segmentation result of the image to be processed.

[0137] After introducing the device provided by this application, refer to Figure 6 The electronic device 130 according to this embodiment of the present application is described. Figure 6 The electronic device 130 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0138] like Figure 6 As shown, the electronic device 130 is in the form of a general electronic device. The components of the electronic device 130 may include but are not limited to: the at least one processor 131, the at least one memory 132, and a bus 133 connecting different system components (including the memory 132 and the processor 131).

[0139] Bus 133 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, a processor, or a local bus using any of a variety of bus architectures.

[0140] The memory 132 may include a readable medium in the form of a volatile memory, such as a random access memory (RAM) 1321 and / or a cache memory 1322 , and may further include a read-only memory (ROM) 1323 .

[0141] The memory 132 may also include a program / utility 1325 having a set (at least one) of program modules 1324, such program modules 1324 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.

[0142] The electronic device 130 may also communicate with one or more external devices 134 (e.g., keyboards, pointing devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 130, and / or communicate with any device that enables the electronic device 130 to communicate with one or more other electronic devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 135. Furthermore, the electronic device 130 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 136. As shown, the network adapter 136 communicates with other modules for the electronic device 130 via a bus 133. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 130, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0143] In some possible implementations, various aspects of an image segmentation model training method or an image processing method provided by the present application may also be implemented in the form of a program product, which includes a program code. When the program product is run on a computer device, the program code is used to enable the computer device to execute the steps of an image segmentation model training method or an image processing method according to various exemplary implementations of the present application described above in this specification.

[0144] The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0145] The program product for the image segmentation model training method or the image processing method of the embodiment of the present application can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on an electronic device. However, the program product of the present application is not limited to this. In this document, the readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.

[0146] The readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, wherein the readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The readable signal medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0147] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.

[0148] The program code for performing the operations of the present application can be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java, C++, etc., and also conventional procedural programming languages ​​such as "C" language or similar programming languages. The program code can be executed entirely on the user electronic device, partially on the user device, as an independent software package, partially on the user electronic device and partially on the remote electronic device, or entirely on the remote electronic device or server. In the case of a remote electronic device, the remote electronic device can be connected to the user electronic device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external electronic device (for example, using an Internet service provider to connect through the Internet).

[0149] It should be noted that, although several units or subunits of the device are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more units described above can be embodied in one unit. Conversely, the features and functions of one unit described above can be further divided into multiple units to be embodied.

[0150] In addition, although the operations of the method of the present application are described in a specific order in the drawings, this does not require or imply that the operations must be performed in this specific order, or that all the operations shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.

[0151] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0152] The present application is described with reference to the flowchart and / or block diagram of the method, device (system) and computer program product according to the embodiment of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, and the combination of the process and / or box in the flowchart and / or block diagram can be realized by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device produce a device for realizing the function specified in one process or multiple processes in the flowchart and / or one box or multiple boxes in the block diagram.

[0153] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device that implements the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0154] These computer program instructions may also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, whereby the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0155] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.

[0156] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A method for training an image segmentation model, characterized in that: The method comprises: Acquire a sample image, an affine transformation image corresponding to the sample image, a similar image associated with the sample image, and a target segmentation result of a target object in the sample image, wherein the affine transformation image is obtained by affine transformation of the sample image; and the similarity between the similar image and the sample image is less than a preset threshold; Input the sample image and the affine transformed image into the image segmentation model to be trained respectively to segment the target object, and obtain a first segmentation result of the target object in the sample image and a second segmentation result of the target object in the affine transformed image; input the sample image and the similar image into the image segmentation model to be trained respectively, and obtain a processing result of the sample image and a processing result of the similar image output by a specified feature layer in the image segmentation model to be trained; wherein the first segmentation result is subjected to affine transformation to obtain a transformation result; Determine a first loss value according to the first segmentation result and the target segmentation result, and determine a second loss value according to the transformation result and the second segmentation result; determine a third loss value according to the processing result of the sample image and the processing result of the similar image; Determine a total loss value by weighted summing the first loss value, the second loss value, and the third loss value with preset weights; The image segmentation model to be trained is trained according to the total loss value to obtain a trained image segmentation model.

2. The method according to claim 1, characterized in that: Before obtaining the processing result of the sample image and the processing result of the similar image output by the designated feature layer in the image segmentation model to be trained, the method further includes: For each of the multiple target neural network layers in the image segmentation model to be trained, respectively execute: After the sample image and the similar image are respectively input into the image segmentation model to be trained, a feature map of the sample image and a feature map of the similar image output by the target neural network layer are obtained; Obtaining a difference feature map according to a difference between the feature map of the sample image and the feature map of the similar image; The designated feature layer is determined according to the difference feature maps corresponding to each target neural network layer, wherein the feature point values ​​of the difference feature map of the designated feature layer are greater than the difference threshold.

3. The method according to claim 2, characterized in that The step of determining the designated feature layer according to the difference feature maps respectively corresponding to the target neural network layers includes: Determine the average difference value of each feature point of the difference feature map of each target neural network layer; The target neural network layer whose average difference value is greater than the difference threshold is determined as the designated feature layer.

4. An image processing method, characterized in that: The method comprises: Inputting the image to be processed into the trained image segmentation model to obtain the segmentation result of the object to be processed in the image to be processed; The trained image segmentation model is trained according to the image segmentation model training method according to any one of claims 1-3.

5. The method according to claim 4, characterized in that The image to be processed is a frame image in a video frame sequence. After obtaining the segmentation result of the object to be processed in the image to be processed, the method further includes: Based on the fact that the image to be processed is a non-first frame image in the video frame sequence, obtaining a segmentation result of the object to be processed of at least one frame of target image, wherein each frame of the target image in the at least one frame of target image is located before the image to be processed in the order of the frame sequence; The segmentation result of the at least one frame of the target image is used to perform smoothing processing on the segmentation result of the image to be processed.

6. An image segmentation model training device, characterized in that: The image segmentation model is used to segment a target object from an image, and the device comprises: A sample image acquisition module is configured to acquire a sample image, an affine transformation image corresponding to the sample image, and a target segmentation result of a target object in the sample image, wherein the affine transformation image is obtained by affine transformation of the sample image; The segmentation result determination module is configured to execute the segmentation of the target object by inputting the sample image and the affine transformation image into the image segmentation model to be trained, respectively, to obtain a first segmentation result of the target object in the sample image and a second segmentation result of the target object in the affine transformation image; wherein the first segmentation result is subjected to affine transformation to obtain a transformation result; a loss value acquisition module, configured to determine a first loss value according to the first segmentation result and the target segmentation result, and determine a second loss value according to the transformation result and the second segmentation result; A third loss acquisition module is configured to, after the sample image acquisition module acquires the sample image, input the sample image and a similar image associated with the sample image into the image segmentation model to be trained, respectively, to obtain a processing result of the sample image and a processing result of the similar image output by a specified feature layer in the image segmentation model to be trained; determine a third loss value according to the processing result of the sample image and the processing result of the similar image; and the similarity between the similar image and the sample image is less than a preset threshold; a total loss determination module, configured to perform weighted summation according to the first loss value, the second loss value and the third loss value with preset weights to determine a total loss value; The model parameter adjustment module is configured to execute training of the image segmentation model to be trained according to the total loss value to obtain a trained image segmentation model.

7. The device according to claim 6, characterized in that Before the third loss acquisition module obtains the processing result of the sample image and the processing result of the similar image output by the designated feature layer in the image segmentation model to be trained, the device further includes: The network layer determination unit is configured to respectively perform, for each of the multiple target neural network layers in the image segmentation model to be trained: After the sample image and the similar image are respectively input into the image segmentation model to be trained, a feature map of the sample image and a feature map of the similar image output by the target neural network layer are obtained; Obtaining a difference feature map according to a difference between the feature map of the sample image and the feature map of the similar image; The designated feature layer is determined according to the difference feature maps corresponding to each target neural network layer, wherein the feature point values ​​of the difference feature map of the designated feature layer are greater than the difference threshold.

8. The device according to claim 7, characterized in that The network layer determination unit is configured to determine the average difference value of each feature point of the difference feature map of each target neural network layer; The target neural network layer whose average difference value is greater than the difference threshold is determined as the designated feature layer.

9. An image processing device, characterized in that: The device comprises: An image segmentation module is configured to input the image to be processed into a trained image segmentation model to obtain a segmentation result of the object to be processed in the image to be processed; The trained image segmentation model is trained according to the image segmentation model training method according to any one of claims 1-3.

10. The device according to claim 9, characterized in that The image to be processed is a frame image in a video frame sequence, and the image processing module is configured to input the image to be processed into a trained image segmentation model, and after obtaining the segmentation result of the object to be processed in the image to be processed, the device further includes: a smoothing processing module, configured to execute, based on the fact that the image to be processed is not the first frame image in the video frame sequence, obtaining a segmentation result of the object to be processed of at least one frame of target image, wherein each frame of the target image in the at least one frame of target image is located before the image to be processed in the order of the frame sequence; The segmentation result of the at least one frame of the target image is used to perform smoothing processing on the segmentation result of the image to be processed.

11. An electronic device, characterized in that: It comprises at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method as described in any one of claims 1-5.

12. A computer storage medium, characterized in that: The computer storage medium stores a computer program, and the computer program is used to make a computer execute the method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Network training method and device and image processing method and device

    CN111242303A

  • Mural image color restoration method and device

    CN111681183A