High-precision hair detection method based on boundary stable generative adversarial network model
By combining a boundary-stabilized generative adversarial network model and a rotating target detection model, the problems of low detection accuracy and cumbersome data annotation in hair detection are solved, achieving high-precision hair detection without manual labels, which is suitable for biomedical imaging and personal care product development.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG UNIV OF TECH
- Filing Date
- 2025-04-18
- Publication Date
- 2026-07-03
AI Technical Summary
Existing technologies for hair detection suffer from low detection accuracy and cumbersome data annotation, especially for the detection of slender objects such as hair, which are difficult to distinguish and locate accurately. Traditional methods require a large amount of labeled data, and style transfer models have difficulty preserving structural information on hair datasets.
A boundary-stabilized generative adversarial network model is adopted, which combines a style transfer module, a semantic segmentation module, a discriminator and a boundary enhancement module. A high-precision hair detection model is generated by training on a hair training set and a real hair image set. A rotating object detection model and a mean teacher framework are used for label-free training.
It improves the flexibility and accuracy of hair detection, enabling the generation of high-quality hair detection results without manual labels, and is suitable for scenarios such as biomedical imaging and personal care product development.
Smart Images

Figure CN120431601B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer vision, specifically relating to a high-precision hair detection method based on a boundary-stabilized generative adversarial network model. Background Technology
[0002] In the field of computer vision, the accurate detection and localization of slender objects (such as hair and fibers) has significant practical applications, particularly in biomedical imaging, dermatological examinations, and personal care product development. Scalp examinations often require manual counting of hair quantity and thickness, a tedious and time-consuming process. Meanwhile, current technologies use deep learning models to classify hair follicles and estimate the severity of hair loss. However, traditional object detection methods typically rely on large amounts of labeled data to train the model, which is particularly challenging for slender objects, as these often require fine-level annotations to capture their subtle features.
[0003] On the one hand, with the development of deep learning, convolutional neural networks play an important role. Because it is a common phenomenon for two or more hairs to grow from the same pore, although Kim et al. (Reference: Minki Kim, Sunwon Kang, and Byoung-Dai Lee. Evaluation of automated measurement of hairdensity using deep neural networks. Sensors. 22(2): 650, 2022) used a traditional object detection model to measure hair density, the hair needed to be cut short. Even so, because the publicly available dataset only has labels for hair follicle detection, the trained model does not have good distinguishability for hairs growing from the same pore, which has limitations in statistically analyzing the length and thickness of long hairs. In addition, due to the directional and elongated morphological characteristics of hair, even if a traditional object detection box uses a rectangle to enclose the entire hair, there will be a lot of blank information or even other hairs inside the box. Therefore, traditional methods are not entirely suitable for downstream tasks such as detection.
[0004] On the other hand, style transfer models have made significant progress in recent years, enabling the transformation of images into styles that more closely resemble real hair images, thus simulating a large amount of usable training data. However, most current style transfer models, especially diffusion-based methods such as the OSASIS method proposed by Cho and Lee (reference: Hansam Cho, Jonghyun Lee, Seunggyu Chang, and Yonghyun Jeong. One-shot structure-aware stylized image synthesis. In Proceedings of the IEEE / CVFConference on Computer Vision and Pattern Recognition, pages 8302-4948311, 2024.), while capable of training a good style transfer model using only a single image of the target style, typically involve pre-training on large-scale datasets followed by fine-tuning. The need for a large amount of data to train a high-quality diffusion model conflicts with the difficulty in obtaining large quantities of hair datasets due to the extremely tedious manual labeling process. Furthermore, if style-transferred images are to be used as training data for downstream tasks, the style transfer model must be able to preserve the structural information of the original images well, which is inconsistent with the tendency of diffusion models to produce diversity. Therefore, the application scenarios of existing technologies are limited and the detection accuracy is low. Summary of the Invention
[0005] The purpose of this invention is to address the above-mentioned problems by proposing a high-precision hair detection method based on a boundary-stable generative adversarial network model, which can improve the flexibility and accuracy of hair detection tasks and has a wide range of applications.
[0006] To achieve the above objectives, the technical solution adopted by the present invention is as follows:
[0007] This invention proposes a high-precision hair detection method based on a boundary-stabilized generative adversarial network model, comprising the following steps:
[0008] S1. Obtain the hair training set, which includes several data pairs (I... fusion I mask ,label), where I fusion To simulate hair images, I mask The image is a mask, and the label is a set of labels consisting of all the hairs.
[0009] S2. Establish a boundary-stable generative adversarial network (GAN) model and train it using a hair training set and a real hair image set. The boundary-stable GAN model includes a style transfer module G. A And both are related to the style transfer module G A Connected semantic segmentation module G B The discriminator D and the boundary enhancement module, the real hair image set includes several real hair images I real ;
[0010] S3. Input the hair training set and the real hair image set back into the trained boundary-stabilized generative adversarial network model to obtain the final stylized image set, which includes several final stylized images I. pp ;
[0011] S4. Establish a rotating target detection model. The rotating target detection model includes an anchorless target detection model and a rotation auxiliary module. The rotation auxiliary module is used to decode the encoded angle matrix output by the detection head in the anchorless target detection model to obtain the angle matrix. The angle matrix corresponds to the rotation angle of all rotating target detection boxes in the image.
[0012] S5. Based on the mean teacher framework, the rotating target detection model is trained using a set of real hair images, a set of final stylized images, and a set of corresponding labels. The trained rotating target detection model is the teacher model of the mean teacher framework.
[0013] S6. Using the teacher model with the trained mean teacher framework, target detection is performed on the hair image to be tested, and the rotated target detection box for each hair is the hair detection result.
[0014] Preferably, the style transfer module G A and semantic segmentation module G B All models use the ResNet network model, while the discriminator D uses the CNN network model.
[0015] Preferably, training is performed using a hair training set and a set of real hair images, as follows:
[0016] S21, simulate hair image I fusion Input style transfer module G A The corresponding output style transfer image I fake ;
[0017] S22. Transfer the style-transferred images I obtained in step S21 to each... fake and the corresponding real hair image I real Input discriminator D, obtain adversarial loss to iteratively update discriminator D, adversarial loss L D The calculation is as follows:
[0018] L D =L BCE (D(I domain ), TAG domain )
[0019] Among them, L BCE (·) represents the binary cross-entropy loss, D(I domain ) indicates that image I domain The classification prediction value output by the input discriminator D, TAG domain Representing the category label, when image I domain For style transfer image I fake At that time, TAG domain The value is 0 when image I domain For real hair images I real At that time, TAG domain The value is 1;
[0020] S23. Then transfer the style transfer image I fake Input semantic segmentation module G B The corresponding output segmentation result And through the mask image I mask Calculate the segmentation loss to iteratively update the semantic segmentation module G. B Segmentation loss L seg The calculation is as follows:
[0021]
[0022] Where L1(·) represents L1 loss;
[0023] S24, Gradient Inversion Adversarial Loss L D After the segmentation loss L seg Perform a weighted summation to obtain the style transfer module G. A The overall loss is obtained by iteratively updating the style migration module G. A Style transfer module G A Total loss The calculation is as follows:
[0024]
[0025] Where w1 is the resistance loss L D The weighting coefficients, w2 is the segmentation loss L seg The weighting coefficient, 1-TAG domain Indicates gradient reversal;
[0026] S25. Repeat steps S21 to S24 until the hair training set and the real hair image set have been traversed to obtain the trained style transfer module G. AAt the same time, a well-trained boundary-stabilized generative adversarial network model is formed.
[0027] Preferably, the hair training set and the real hair image set are input again into the trained boundary-stabilized generative adversarial network model to obtain the final stylized image set, as follows:
[0028] S31, simulate hair image I fusion Input to the trained style transfer module G A The corresponding output style transfer image I fake ;
[0029] S32, Transfer the style-transferred image I obtained in step S31 fake and the corresponding mask image I mask The input boundary enhancement module performs boundary enhancement, and the corresponding output is the final stylized image I. pp The boundary enhancement module performs the following operations:
[0030] S321. Based on the corresponding style transfer image I fake and mask image I mask The following formula is used to filter out problematic pixels:
[0031]
[0032] Among them, f error (·) indicates the filtering result of the problem pixels. Indicates the mask image I mask The normalized image matrix, Indicates the style transfer of image I fake The normalized image matrix, where c is the preset color value, τ fake Image I representing style transfer fake Error threshold, τ mask Represents mask image I mask Error threshold;
[0033] S322. After color shifting and adjusting each problematic pixel, Gaussian smoothing is performed to obtain the final stylized image I. pp The color shift adjustment formula is as follows:
[0034]
[0035] Among them, f fill (·) indicates the color translation adjustment result of the corresponding problem pixel, c xy c represents the pixel with coordinates (x, y). tThis represents the color value of the t-th pixel randomly sampled centered at coordinates (x, y), where t = 1, 2, ..., u, u is the number of random sampling points, and w fill This refers to the color shift coefficient;
[0036] S33. Repeat steps S31 to S32 until the hair training set and the real hair image set are traversed to obtain the final stylized image set.
[0037] Preferably, the rotation target detection model is trained using a set of real hair images, a set of final stylized images, and a corresponding label set based on the mean teacher framework. The trained rotation target detection model is the teacher model of the mean teacher framework, as follows:
[0038] S51, Using the final stylized image I pp The rotating target detection model was initially trained with the corresponding label set and used as the student model of the mean teacher framework;
[0039] S52. Replicate the student model in the mean teacher framework as the teacher model in the mean teacher framework;
[0040] S53, final stylized image I pp Input the student model with the mean teacher framework, obtain the first predicted value of the output, and calculate the supervision loss L between the first predicted value and the corresponding label set. sup The formula is as follows:
[0041] L sup =L1(student(I pp ), label)
[0042] Where L1(·) represents L1 loss, student(I pp ) indicates that the input is the final stylized image I pp The output of the student model;
[0043] S54, I will use a real hair image real Input the student model and teacher model of the mean teacher framework respectively, and output the second and third predicted values accordingly. Calculate the unsupervised loss L between the second and third predicted values. unsup The formula is as follows:
[0044] L unsup =L1(student(I real ), teacher(I real ))
[0045] Where L1(·) represents L1 loss, student(I real) indicates that the input is a real hair image I real The output of the student model, teacher(I) real ) indicates that the input is a real hair image I real The output of the teacher model;
[0046] S55, Regarding the monitoring loss L sup And unsupervised loss L unsup The average loss L is obtained by weighted summation. MeanTeacher and the average loss L MeanTeacher Backpropagation to the student model using the mean teacher framework, average loss L MeanTeacher The formula is as follows:
[0047] L MeanTeacher =ω sup L sup +ω unsup L unsup
[0048] Where, ω sup Indicates monitoring loss L sup The loss weight, ω unsup L represents unsupervised loss unsup Loss weights;
[0049] S56. The current iteration parameters of the student model based on the mean teacher framework are dynamically updated by weighting the parameters of the teacher model based on the mean teacher framework using an exponential moving average.
[0050] S57. Repeat steps S51 to S56 until the real hair image set, the final stylized image set and the corresponding label set are traversed to obtain the teacher model of the trained mean teacher framework.
[0051] Preferably, the target detection model without anchor boxes is the FCOS model, and the rotation assistance module is the PSC module.
[0052] Preferably, the process of obtaining the hair training set is as follows:
[0053] S11. Establish a Cartesian coordinate system oxy on the canvas and randomly generate the hair follicle location set P and hair whorl location O based on a two-dimensional Gaussian distribution function, where P = {P1, P2, ..., P...} j , ..., P m}, P j This represents the location of the j-th hair follicle, where j = 1, 2, ..., m, and m is the number of hair follicle locations.
[0054] S12. Connect each hair follicle location to the hair whorl location O, and denote the connection vector between the j-th hair follicle location and the hair whorl location O as follows: And view connection vector The angle between the hair and the pre-selected coordinate axis is the initial growth angle of the hair at the j-th hair follicle location. Pre-select the coordinate axis as the x-axis or y-axis;
[0055] S13. Randomly offset the initial growth angle of all hairs in all hair follicle locations to obtain the offset angle of the i-th hair. Where i = 1, 2, ..., n, n ≥ m, and n is the number of hairs;
[0056] S14. Simulate the shape and thickness of all hairs, and generate hair according to the offset angle of all hairs to obtain the mask image I. mask The tags for all hair, with a width of w, a length of h, and a rotation angle starting from the hair root. The rotating target detection bounding box, where w equals the average width of the hair, and h is less than or equal to the preset value H. lim ;
[0057] S15, Mask image I mask And bald head image I bg Image fusion is performed to obtain fused image I fusion This is a simulated hair image;
[0058] S16, convert the corresponding mask image I mask fused image I fusion The label set (label) formed by the labels of all hairs is used as a data pair (I fusion I mask The data (label) is included in the hair dataset, and the process returns to step S11 until a preset number of data pairs (I) are obtained. fusion I mask ,label), using the hair dataset as the hair training set.
[0059] Preferably, the shape and thickness of all hairs are simulated, and hair is generated according to the offset angle of all hairs to obtain a mask image I. mask The tags for all the hair are as follows:
[0060] S141. Establish the shape simulation formula for the i-th hair and perform sampling to obtain the sampling point set of the i-th hair. To simulate the shape of the corresponding hair, where the set of x-coordinates of the sampling points... Sampling point ordinate set This represents the x-axis coordinate of the k-th sampling point of the i-th hair. Let represent the y-axis coordinate of the k-th sampling point of the i-th hair, where k = 1, 2, ..., num, and num represents the number of sampling points for the i-th hair. The formula for simulating the shape of the i-th hair is as follows:
[0061]
[0062] in, Let x represent the shape of the i-th hair. i This represents the x-axis coordinate of the i-th hair. This represents the bending frequency of the randomly generated i-th hair. This represents the bending phase of the randomly generated i-th hair, length i This represents the length of the randomly generated i-th hair;
[0063] S142. Perform a rotation and translation operation on the sampling point set of the corresponding hair according to the offset angle of each hair to obtain the transformed sampling point set of the corresponding hair. Then the sampling point set of the i-th hair... The formulas for rotation and translation operations are as follows:
[0064]
[0065] in, This represents the x-axis coordinates of all sampled points after the corresponding hair has undergone a rotation and translation operation. This represents the y-axis coordinates of all sampled points after the corresponding hair has undergone a rotation and translation operation. That is, the set of transformed sampling points for the i-th hair, X T This represents the transpose of the set of x-coordinates of the sampled points before the rotation and translation operation on the corresponding hair, and Y represents the transpose of the set of x-coordinates. T This represents the transpose of the set of ordinates Y of the sampled points before the rotation and translation operation was performed on the corresponding hair. This represents the x-axis coordinate of the root of the i-th hair. This represents the y-axis coordinate of the root of the i-th hair;
[0066] S143. Based on the established formula for simulating the thickness of the i-th hair, obtain the width of all sampling points in the sampling point set of the corresponding hair to simulate the thickness of the corresponding hair. The formula for simulating the thickness of the i-th hair is as follows:
[0067]
[0068] in, It represents the width of the kth sampling point of the i-th hair, that is, the thickness of the kth sampling point of the i-th hair, and width0 represents the initial width of the randomly generated hair;
[0069] S144. Generate hair based on the conversion sampling point set of each hair and the width correspondence of all sampling points, and obtain the mask image I. mask And tags for all the hair.
[0070] Preferably, the image fusion formula is as follows:
[0071]
[0072] Among them, I fusion (·) represents the image fusion output result, i.e., the fused image I. fusion γ represents the hyperparameter.
[0073] Preferably, the hair follicle location set P and the hair whorl location O are obtained as follows:
[0074] Create a grid on the canvas;
[0075] Using each intersection point in the grid as a reference point, the position coordinates of the corresponding intersection points are randomly generated using a two-dimensional Gaussian distribution function as the hair follicle positions. All hair follicle positions together form the hair follicle position set P, and the reference point is the center point of the two-dimensional Gaussian distribution function.
[0076] Using the center point of the canvas as the reference point, the position O of the hair whorl is randomly generated using a two-dimensional Gaussian distribution function;
[0077] Before connecting each hair follicle location to the hair whorl location O, the following operations are performed:
[0078] A first preset number of hair follicle positions are randomly generated on the canvas to update the number of hair follicle positions m, which is m+l, where l is the first preset number;
[0079] The number of hairs at each hair follicle location is at least one. When there are multiple hairs at the corresponding hair follicle location, a second preset number of hair follicle locations are randomly selected from the hair follicle location set P and marked to indicate that multiple hairs are generated at the marked hair follicle locations.
[0080] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0081] 1) This method trains a boundary-stable generative adversarial network (GAN) model using a hair training set and a real hair image set. The boundary-stable GAN model includes a style transfer module, a semantic segmentation module, a discriminator, and a boundary enhancement module. The semantic segmentation module and the boundary enhancement module simultaneously ensure the stability of hair boundaries in the generated hair images, while the discriminator ensures the authenticity of the generated hair texture style. The trained boundary-stable GAN model is then used to align the texture features between the hair dataset and the real hair image set, including the number, thickness, and position of hair. Finally, a rotation target detection model is combined with a mean teacher framework to align the distribution differences between simulated hair images and real hair images. By combining simulated generation of hair images and style transfer, the training of a hair rotation target detection model without manual labeling is achieved. The trained teacher model of the mean teacher framework is used to perform target detection on the test hair images to generate hair detection results, thereby improving detection accuracy and efficiency and better adapting to application scenarios where training data is difficult to obtain.
[0082] 2) The hair training set generated by this method can provide training data for various hair detection models to achieve automatic statistical analysis of hair quantity and thickness, solving the training problem of hair detection models caused by insufficient labeled data in existing technologies. Specifically, by simulating real hair distribution, growth angle, hair shape, and thickness variations, and fusing images to generate realistic hair images, this method achieves random generation of images and their corresponding custom labels according to the natural distribution of hair on the scalp surface. This generates hair images and accurate label information that can be used by machine learning algorithms, thereby simulating a large amount of usable training data. This data can be used to promote the optimization of various hair detection models in supervised learning environments, improving the flexibility and accuracy of hair detection tasks. It is also convenient, fast, and widely applicable, such as in biomedical imaging, seborrheic alopecia analysis, and personal care product development. Attached Figure Description
[0083] Figure 1 This is a flowchart of the high-precision hair detection method based on a boundary-stabilized generative adversarial network model of the present invention;
[0084] Figure 2 This is a schematic diagram of the boundary-stabilized generative adversarial network model of the present invention;
[0085] Figure 3 This is a schematic diagram of the rotating target detection model of the present invention;
[0086] Figure 4 This is a schematic diagram of the mean teacher framework of the present invention;
[0087] Figure 5 This is a flowchart illustrating the process of obtaining the hair training set according to the present invention.
[0088] Figure 6 This is a schematic diagram of the mask image and the fused image generated by the present invention;
[0089] Figure 7 This is a schematic diagram of a real hair image. Detailed Implementation
[0090] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0091] It should be noted that when a component is referred to as being "connected" to another component, it can be directly connected to the other component or there may be an intervening component. Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art. The terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the scope of the application.
[0092] To address the challenges of detecting and locating long, thin hairs, particularly those lacking labels, this application proposes a high-precision hair detection method based on a boundary-stable generative adversarial network (GAN) model. Using a hair training set and a set of real hair images, the method leverages the boundary-stable GAN model to analyze simulated hair images from the hair training set. fusion The final stylized image I is obtained by performing the transformation. pp Is it a real hair image I real Images with similar texture features were used to form the unannotated training data for the FCOS+PSC rotating object detection model (final stylized image I). pp The system uses a label set (and a set of labels); finally, it combines FCOS+PSC with the mean teacher framework for training, achieving the goal of training without manual labels.
[0093] like Figures 1-7 As shown, a high-precision hair detection method based on a boundary-stabilized generative adversarial network model includes the following steps:
[0094] S1. Obtain the hair training set, which includes several data pairs (I... fusion I mask ,label), where I fusion To simulate hair images, I mask The image is a mask, and the label is a set of labels for all the hairs.
[0095] In one embodiment, the process of obtaining the hair training set is as follows:
[0096] S11. Establish a Cartesian coordinate system oxy on the canvas and randomly generate the hair follicle location set P and hair whorl location O based on a two-dimensional Gaussian distribution function, where P = {P1, P2, ..., P...} j , ..., P m}, P j This represents the location of the j-th hair follicle, where j = 1, 2, ..., m, and m is the number of hair follicle locations.
[0097] In one embodiment, the hair follicle location set P and the hair whorl location O are obtained as follows:
[0098] Create a grid on the canvas;
[0099] Using each intersection point in the grid as a reference point, the position coordinates of the corresponding intersection points are randomly generated using a two-dimensional Gaussian distribution function as the hair follicle positions. All hair follicle positions together form the hair follicle position set P, and the reference point is the center point of the two-dimensional Gaussian distribution function.
[0100] Using the center point of the canvas as the reference point, the position O of the hair whorl is randomly generated using a two-dimensional Gaussian distribution function;
[0101] Before connecting each hair follicle location to the hair whorl location O, the following operations are performed:
[0102] A first preset number of hair follicle positions are randomly generated on the canvas to update the number of hair follicle positions m, which is m+l, where l is the first preset number;
[0103] The number of hairs at each hair follicle location is at least one. When there are multiple hairs at the corresponding hair follicle location, a second preset number of hair follicle locations are randomly selected from the hair follicle location set P and marked to indicate that multiple hairs are generated at the marked hair follicle locations.
[0104] The canvas can be white. Generally, the upper left corner of the canvas is the origin o of the rectangular coordinate system oxy. The horizontal direction is the x-axis and the vertical direction is the y-axis. The horizontal and vertical axes of the grid are parallel to the x-axis and y-axis of the rectangular coordinate system oxy, respectively, and the grid is formed with the origin of the rectangular coordinate system oxy as the starting point. Alternatively, it can be set arbitrarily according to actual needs.
[0105] Specifically, based on general dermatological observations and common sense, while hair follicles on the same part of the same person are not strictly equidistant, their distances are usually relatively consistent. Therefore, based on the hair follicle distribution density of a real hair dataset, a probability cloud map based on a grid distribution (grid density: 6-7 rows and columns) is generated on a canvas using a two-dimensional Gaussian distribution function to randomly generate the initial position of each hair follicle, simulating a non-strictly equidistant distribution. Under normal circumstances, each hair follicle grows only one hair; however, occasionally multiple hairs may grow from a single follicle. This is called "multiple hair follicles" or "multiple hairs." Therefore, this application randomly selects several hair follicle positions (0-7 random numbers) based on the randomly generated positions using the two-dimensional Gaussian distribution function to indicate that multiple hairs will be generated within that follicle position. In addition, a small number of random positions (0-8 random numbers) are generated to increase the robustness of subsequent hair detection on the real hair dataset. The hair follicle position is... Figure 5 The cross in the grid diagram indicates the position; the hair whorl position O is... Figure 5 PointO in the grid diagram, the hexagon indicates the location.
[0106] S12. Connect each hair follicle location to the hair whorl location O, and denote the connection vector between the j-th hair follicle location and the hair whorl location O as follows: And view connection vector The angle between the hair and the pre-selected coordinate axis is the initial growth angle of the hair at the j-th hair follicle location. The pre-selected coordinate axis is either the x-axis or the y-axis.
[0107] S13. Randomly offset the initial growth angle of all hairs in all hair follicle locations to obtain the offset angle of the i-th hair. Where i = 1, 2, ..., n, n ≥ m, and n is the number of hairs.
[0108] For each hair generated, its initial growth angle is randomly offset to obtain the corresponding hair offset angle. The preferred random angle is a random number between -π / 5 and π / 5, which can be adjusted according to actual needs.
[0109] S14. Simulate the shape and thickness of all hairs, and generate hair according to the offset angle of all hairs to obtain the mask image I. mask The tags for all hair, with a width of w, a length of h, and a rotation angle starting from the hair root. The rotating target detection bounding box, where w equals the average width of the hair, and h is less than or equal to the preset value H. lim .
[0110] In one embodiment, the shape and thickness of all hairs are simulated, and hair is generated according to the offset angle of all hairs to obtain a mask image I. mask The tags for all the hair are as follows:
[0111] S141. Establish the shape simulation formula for the i-th hair and perform sampling to obtain the sampling point set of the i-th hair. To simulate the shape of the corresponding hair, where the set of x-coordinates of the sampling points... Sampling point ordinate set This represents the x-axis coordinate of the k-th sampling point of the i-th hair. Let represent the y-axis coordinate of the k-th sampling point of the i-th hair, where k = 1, 2, ..., num, and num represents the number of sampling points for the i-th hair. The formula for simulating the shape of the i-th hair is as follows:
[0112]
[0113] in, Let x represent the shape of the i-th hair. i This represents the x-axis coordinate of the i-th hair. This represents the bending frequency of the randomly generated i-th hair. This represents the bending phase of the randomly generated i-th hair, length i This represents the length of the randomly generated i-th hair;
[0114] S142. Perform a rotation and translation operation on the sampling point set of the corresponding hair according to the offset angle of each hair to obtain the transformed sampling point set of the corresponding hair. Then the sampling point set of the i-th hair... The formulas for rotation and translation operations are as follows:
[0115]
[0116] in, This represents the x-axis coordinates of all sampled points after the corresponding hair has undergone a rotation and translation operation. This represents the y-axis coordinates of all sampled points after the corresponding hair has undergone a rotation and translation operation. That is, the set of transformed sampling points for the i-th hair, X T This represents the transpose of the set of x-coordinates of the sampled points before the rotation and translation operation on the corresponding hair, and Y represents the transpose of the set of x-coordinates. T This represents the transpose of the set of ordinates Y of the sampled points before the rotation and translation operation was performed on the corresponding hair. This represents the x-axis coordinate of the root of the i-th hair. This represents the y-axis coordinate of the root of the i-th hair;
[0117] S143. Based on the established formula for simulating the thickness of the i-th hair, obtain the width of all sampling points in the sampling point set of the corresponding hair to simulate the thickness of the corresponding hair. The formula for simulating the thickness of the i-th hair is as follows:
[0118]
[0119] in, It represents the width of the kth sampling point of the i-th hair, that is, the thickness of the kth sampling point of the i-th hair, and width0 represents the initial width of the randomly generated hair;
[0120] S144. Generate hair based on the conversion sampling point set of each hair and the width correspondence of all sampling points, and obtain the mask image I. mask And tags for all the hair.
[0121] The average width *w* of the hair can be the average width of all sampling points of the corresponding hair, or it can be the average width of the generated hair as a whole. The label settings can also be adjusted according to actual needs. The hair root is the location of the hair follicle. The shape of the *i*th hair is simulated using the shape simulation formula of the *i*th hair, and the sampling point set is obtained after sampling. This represents the num sampling points that make up a single hair; finally, the sampling point set is adjusted according to the offset angle of the i-th hair. Rotation and translation are performed to obtain the transformation sampling point set for all hair strands. Hair is then generated based on the transformation sampling point set for each hair strand and the width of all sampling points. That is, each hair curve is drawn on a white canvas as a black curve with varying thickness. After simulating all hair curves, a mask image I is obtained. mask (Black and white image). Simultaneously, labels needed for training any subsequent model are generated at this stage. In this embodiment, It is randomly generated by a Gaussian function with a mean of 0.8 and a standard deviation of 0.3. for random number, length i The value is a random value within the range [0.1*meanHW, 0.7meanHW], and width0 is a random value within the range [10*meanHW / 2240, 35*meanHW / 2240]. meanHW = (canvas height + canvas width) / 2. Sampling is either uniform sampling or adjusted according to actual needs.
[0122] S15, Mask image I mask And bald head image I bg Image fusion is performed to obtain fused image I fusion This is a simulated hair image.
[0123] In one embodiment, the image fusion formula is as follows:
[0124]
[0125] Among them, I fusion (·) represents the image fusion output result, i.e., the fused image I. fusion γ represents the hyperparameter.
[0126] Among them, the mask image I is obtained through image fusion. mask (Black and white image) Using bald head image I bg Fill the background and blend it into a composite image that closely resembles the style of a realistic image. fusion This allows the subsequent hair detection model to better understand the image. In this embodiment, γ = 1.5 is used to determine the degree of blending between the two images.
[0127] S16, convert the corresponding mask image I mask fused image I fusion The label set (label) formed by the labels of all hairs is used as a data pair (I fusion I mask The data (label) is included in the hair dataset, and the process returns to step S11 until a preset number of data pairs (I) are obtained. fusion I mask ,label), using the hair dataset as the hair training set.
[0128] The hair training set is used as training data for subsequent models, and its generation process eliminates the need for manual labeling, significantly improving efficiency. Specifically, the mask image I... mask Black and white image of hair; simulated hair image I fusion Based on masked image I mask The image of hair after background filling; the label is a rotated target detection box extending from the hair root, with the average width of the hair as w and the length as h, i.e., when the hair length is greater than the preset value H. lim Afterwards, the length of the rotated target detection box is equal to H. lim Each data pair (I fusion I mask The label set label in (label) corresponds to the mask image I. mask Tags for all hair.
[0129] In this embodiment, 2500 data pairs (I) are generated. fusion I mask (label), such as Figure 6 As shown, the mask image I in two data pairs is displayed. mask and fused image I fusion ,in, Figure 6Image (a1) and image (b1) in the image correspond to a pair of mask images I. mask and fused image I fusion Figures (a2) and (b2) correspond to a pair of mask images I. mask and fused image I fusion It can be seen that the fused image I fusion Approaching Figure 7 The morphological features of hair in the real hair image shown. Figure 7 Images (a) and (b) are both real hair images. To meet the input size requirements of subsequent hair detection models, the generated mask image I can also be adjusted. mask fused image I fusion Image resolution, such as the generated simulated hair image I fusion and mask image I mask The image resolution is set to 1024×1024. Preset value H lim Simulated hair image I set to 0.07x. fusion Or mask image I mask The image resolution (e.g., 1024×1024 image resolution, with a value of 0.07*1024) is set in such a way that it can distinguish multiple hairs growing from the same hair follicle location and also frame each hair well, so as to better complete the subsequent model training.
[0130] The aforementioned method of obtaining hair training sets can also be used to provide training data for various hair detection models in existing technologies to achieve feature capture and automatic statistics on the quantity and thickness of hair. It can generate an unlimited number of hair images and custom labels for downstream model training, solving the training problem of hair detection models caused by a lack of sufficient labeled data in existing technologies. Specifically, by simulating real hair distribution, growth angle, hair shape, and thickness variations, and fusing images to generate realistic hair images, it achieves random generation of images and their corresponding custom labels according to the natural distribution of hair on the scalp surface. This generates hair images and accurate label information that can be used by machine learning algorithms, thereby simulating a large amount of usable training data. This can be used to promote the optimization of various hair detection models in supervised learning environments, improving the flexibility and accuracy of hair detection tasks. It is convenient, fast, and widely applicable, such as in biomedical imaging, seborrheic alopecia analysis, and personal care product development.
[0131] S2. Establish a boundary-stable generative adversarial network (GAN) model and train it using a hair training set and a real hair image set. The boundary-stable GAN model includes a style transfer module G. A And both are related to the style transfer module G A Connected semantic segmentation module G BThe discriminator D and the boundary enhancement module, the real hair image set includes several real hair images I real .
[0132] In one embodiment, the style transfer module G A and semantic segmentation module G B All models use the ResNet network model, while the discriminator D uses the CNN network model.
[0133] In one embodiment, training is performed using a hair training set and a set of real hair images, as follows:
[0134] S21, simulate hair image I fusion Input style transfer module G A The corresponding output style transfer image I fake ;
[0135] S22. Transfer the style-transferred images I obtained in step S21 to each... fake and the corresponding real hair image I real Input discriminator D, obtain adversarial loss to iteratively update discriminator D, adversarial loss L D The calculation is as follows:
[0136] L D =L BCE (D(I domain ), TAG domain )
[0137] Among them, L BCE (·) represents the binary cross-entropy loss, D(I domain ) indicates that image I domain The classification prediction value output by the input discriminator D, TAG domain Representing the category label, when image I domain For style transfer image I fake At that time, TAG domain The value is 0 when image I domain For real hair images I real At that time, TAG domain The value is 1;
[0138] S23. Then transfer the style transfer image I fake Input semantic segmentation module G B The corresponding output segmentation result And through the mask image I mask Calculate the segmentation loss to iteratively update the semantic segmentation module G. B Segmentation loss L seg The calculation is as follows:
[0139]
[0140] Where L1(·) represents L1 loss;
[0141] S24, Gradient Inversion Adversarial Loss L D After the segmentation loss L seg Perform a weighted summation to obtain the style transfer module G. A The overall loss is obtained by iteratively updating the style migration module G. A Style transfer module G A Total loss The calculation is as follows:
[0142]
[0143] Where w1 is the resistance loss L D The weighting coefficients, w2 is the segmentation loss L seg The weighting coefficient, 1-TAG domain Indicates gradient reversal;
[0144] S25. Repeat steps S21 to S24 until the hair training set and the real hair image set have been traversed to obtain the trained style transfer module G. A At the same time, a well-trained boundary-stabilized generative adversarial network model is formed.
[0145] Among them, the boundary-stable generative adversarial network model is as follows: Figure 2 As shown, it includes the style transfer module G. A Semantic segmentation module G B The system includes a discriminator (D) and a boundary enhancement module. The training process requires simulated hair images (I) from the hair training set. fusion Mask image I mask Real hair images from the real hair image set I real It is then trained. The style transfer module G is involved in the training process. A Semantic segmentation module G B Discriminator D and semantic segmentation module G B The discriminator D is an auxiliary module used when training a boundary-stable generative adversarial network model, where the semantic segmentation module G... B Used for the style transfer module G A Output style transfer image I fake Segmentation is performed, and its label is the mask image I. mask This can improve the stability of structural information; the discriminator D is the adversarial module of the boundary-stable generative adversarial network model, used to distinguish the style transfer module G. A Output style transfer image I fake and real hair images I real The module for determining whether an image is real or fake, i.e., used for style transfer images I.fake and real hair images I real Perform true / false classification training, when image I domain For style transfer image I fake At that time, TAG domain =0, when image I domain For real hair images I real At that time, TAG domain =1.1-TAG domain This is because the discriminator D is used as the style transfer module G. A The loss is calculated using an adversarial model, and this loss does not apply gradient descent to the discriminator D. The final trained style transfer module G is obtained. A Simultaneously, a well-trained boundary-stabilized generative adversarial network model is formed. During actual detection, the style transfer module G... A The boundary enhancement module is a key part of the boundary-stabilized generative adversarial network model (used for style transfer).
[0146] A boundary-stabilized generative adversarial network model was used, employing real hair images I. real and simulated hair image I fusion Mask image I mask For simulated hair image I fusion Style transfer allows you to adjust the texture of a drawn image to more closely resemble a real hair image, with almost no change to the hair structure.
[0147] S3. Input the hair training set and the real hair image set back into the trained boundary-stabilized generative adversarial network model to obtain the final stylized image set, which includes several final stylized images I. pp .
[0148] In one embodiment, the hair training set and the real hair image set are input again into the trained boundary-stabilized generative adversarial network model to obtain the final stylized image set, as follows:
[0149] S31, simulate hair image I fusion Input to the trained style transfer module G A The corresponding output style transfer image I fake ;
[0150] S32, Transfer the style-transferred image I obtained in step S31 fake and the corresponding mask image I mask The input boundary enhancement module performs boundary enhancement, and the corresponding output is the final stylized image I. pp The boundary enhancement module performs the following operations:
[0151] S321. Based on the corresponding style transfer image Ifake and mask image I mask The following formula is used to filter out problematic pixels:
[0152]
[0153] Among them, f error (·) indicates the filtering result of the problem pixels. Indicates the mask image I mask The normalized image matrix, Indicates the style transfer of image I fake The normalized image matrix, where c is the preset color value, τ fake Image I representing style transfer fake Error threshold, τ mask Represents mask image I mask Error threshold;
[0154] S322. After color shifting and adjusting each problematic pixel, Gaussian smoothing is performed to obtain the final stylized image I. pp The color shift adjustment formula is as follows:
[0155]
[0156] Among them, f fill (·) indicates the color translation adjustment result of the corresponding problem pixel, c xy c represents the pixel with coordinates (x, y). t This represents the color value of the t-th pixel randomly sampled centered at coordinates (x, y), where t = 1, 2, ..., u, u is the number of random sampling points, and w fill This refers to the color shift coefficient;
[0157] S33. Repeat steps S31 to S32 until the hair training set and the real hair image set are traversed to obtain the final stylized image set.
[0158] In the actual testing process, the style transfer module G A The boundary enhancement module is a key component of the boundary-stabilized generative adversarial network (GAN) model (used for style transfer). On the trained boundary-stabilized GAN model, the style transfer module G... A Simulated hair image I fusion Convert to style transfer image I fake Then, the style-transferred image I is further enhanced using the boundary enhancement module. fake Perform boundary enhancement and convert it into the final stylized image I pp This process requires using the simulated hair images I from the hair training set again. fusionMask image I mask Real hair images from the real hair image set I real .
[0159] The boundary enhancement module is an explicit, interpretable, and controllable module that adjusts the style-transferred image I. fake Becoming the final stylized image I pp While losing a small amount of style information, ensure the final stylized image I pp and mask image I mask Structural consistency. Specifically, for the style transfer module G A Output style transfer image I fake Combined with the corresponding mask image I mask , through f error (·) Identify obviously poorly predicted background pixels, i.e., filter out problem pixels. Then sample the area around these problem pixels and use f... fill (·) After color translation adjustment, Gaussian smoothing is performed at the corresponding position to reduce the loss of style information caused by color filling. Here, u represents the number of sampling points randomly sampled from neighboring positions within a preset Manhattan distance of the corresponding problem pixel. The smaller the Manhattan distance from the corresponding coordinate position (x, y), the higher the probability of sampling.
[0160] S4. Establish a rotating target detection model, which includes an anchorless target detection model and a rotation auxiliary module. The rotation auxiliary module is used to decode the encoded angle matrix output by the detection head in the anchorless target detection model to obtain the angle matrix, which corresponds to the rotation angle of all rotating target detection boxes in the image.
[0161] In one embodiment, the target detection model without anchor boxes is the FCOS model, and the rotation assistance module is the PSC module.
[0162] The rotated object detection model includes an anchorless object detection model (FCOS model) and a rotation auxiliary module (PSC module). FCOS (Fully Convolutional One-Stage Object Detection) is an object detection model; PSC (Phase-Shifting Coder: Predicting Accurate Orientation in Oriented Object Detection) is a rotation auxiliary module for this object detection model. Figure 3As shown. Both the FCOS model and the PSC module are technologies well-known to those skilled in the art. The FCOS model includes a Backbone (e.g., using a ResNet50 network), a Feature Pyramid (e.g., a five-layer feature pyramid), and a multi-scale target detection head. The detection head outputs a predicted class probability matrix (classification matrix), four distance matrices regressing from each point to the edge of the rotated target detection box (regression matrix), a center confidence matrix (center matrix), and the encoded angle matrix of the rotated target detection box (encoded angle matrix). The rotation assistance module, the PSC module, performs PSC decoding on the encoded angle matrix of the branch rotated target detection boxes to obtain the actual angle matrix of the rotated target detection boxes.
[0163] The FCOS model directly detects rotating objects by predicting a set of bounding boxes at each location, eliminating the need for pre-set fixed anchor boxes. This simplifies the detection process and improves efficiency and accuracy. The PSC module addresses the issue of abrupt changes in the angle of the rotating bounding box through trigonometric function mapping.
[0164] S5. Based on the mean teacher framework, the rotating target detection model is trained using a set of real hair images, a set of final stylized images, and a corresponding label set. The trained rotating target detection model is the teacher model of the mean teacher framework.
[0165] In one embodiment, the rotation target detection model is trained using a set of real hair images, a set of final stylized images, and a corresponding label set based on the mean teacher framework. The trained rotation target detection model is the teacher model of the mean teacher framework, as detailed below:
[0166] S51, Using the final stylized image I pp The rotating target detection model was initially trained with the corresponding label set and used as the student model of the mean teacher framework;
[0167] S52. Replicate the student model in the mean teacher framework as the teacher model in the mean teacher framework;
[0168] S53, final stylized image I pp Input the student model with the mean teacher framework, obtain the first predicted value of the output, and calculate the supervision loss L between the first predicted value and the corresponding label set. sup The formula is as follows:
[0169] L sup =L1(student(I pp ), label)
[0170] Where L1(·) represents L1 loss, student(I pp ) indicates that the input is the final stylized image I pp The output of the student model;
[0171] S54, I will use a real hair image real Input the student model and teacher model of the mean teacher framework respectively, and output the second and third predicted values accordingly. Calculate the unsupervised loss L between the second and third predicted values. unsup The formula is as follows:
[0172] L unsup =L1(student(I real ), teacher(I real ))
[0173] Where L1(·) represents L1 loss, student(I real ) indicates that the input is a real hair image I real The output of the student model, teacher(I) real ) indicates that the input is a real hair image I real The output of the teacher model;
[0174] S55, Regarding the monitoring loss L sup And unsupervised loss L unsup The average loss L is obtained by weighted summation. MeanTeacher and the average loss L MeanTeacher Backpropagation to the student model using the mean teacher framework, average loss L MeanTeacher The formula is as follows:
[0175] L Meanreacher =ω sup L sup +ω unsup L unsup
[0176] Where, ω sup Indicates monitoring loss L sup The loss weight, ω unsup L represents unsupervised loss unsup Loss weights;
[0177] S56. The current iteration parameters of the student model based on the mean teacher framework are dynamically updated by weighting the parameters of the teacher model based on the mean teacher framework using an exponential moving average.
[0178] S57. Repeat steps S51 to S56 until the real hair image set, the final stylized image set and the corresponding label set are traversed to obtain the teacher model of the trained mean teacher framework.
[0179] Among them, real hair images I real Final stylized image I pp The rotating object detection model is trained based on the mean teacher framework and the corresponding label set, which can align with the stylized image I. pp and real hair images I real The distribution characteristics further improved the final detection accuracy.
[0180] Specifically, when the input image is the final stylized image I pp If the image is identified as a labeled region, then the first predicted value obtained after forward propagation through the student model is used to calculate the supervised loss L using the label set. sup When the input image is a real hair image I real If so, the image is determined to be an unlabeled region, and the real hair image I is identified. real Simultaneously inputting both the teacher and student models, and using the third predicted value output by the teacher model as the pseudo-label for the student model, and calculating the unsupervised loss L using the second predicted value output by the student model. unsup The average teacher structure is as follows: Figure 4 As shown, the student model within the mean teacher framework and the teacher model within the mean teacher framework both have predicted output values. The first and second predicted values are denoted as output1, output2, and output3, respectively. The parameters of the teacher model within the mean teacher framework are dynamically updated using exponential moving averages (EMAs) based on the current iteration parameters of the student model. This is a technique well-known to those skilled in the art. The exponential moving average (EMA), also known as the EXPMA indicator, is a trend-following indicator; it is an exponentially weighted moving average.
[0181] S6. Using the teacher model with the trained mean teacher framework, target detection is performed on the hair image to be tested, and the rotated target detection box for each hair is the hair detection result.
[0182] For ease of understanding, the following detailed explanation is provided through specific embodiments.
[0183] In this embodiment, the real hair dataset was provided by 937 individuals, each contributing several images of hair from different head positions, totaling 2429 images. Each image has a resolution of 2560×1920 pixels. All images were taken at 50x magnification to ensure the capture of fine hair structure and texture features. Given the complexity of labeling, the real hair dataset only includes 24 manually labeled images. These labels precisely mark the location and thickness of each hair strand and are used only for model performance evaluation, not for model training. Therefore, this application does not use manual labels overall. This real hair dataset covers a wide range of hair types, including different hair colors, textures, and hairstyles, providing a rich and diverse sample for training and validating the model.
[0184] During the training phase of the boundary-stabilized generative adversarial network model, the image scaling size during model training is set to load_size = 512, and the random cropping size during the model data augmentation phase is set to crop_size = 512; the training style transfer module G is also set. A The weighting coefficients at time intervals are w1 = 1.0 and w2 = 10.0. In the boundary enhancement module, c = (0, 0, 0) is set empirically, and τ... mask =0.9, τ fake =0.4, to minimize the impact on style characteristics while improving the poor background.
[0185] In the object detection phase, the FCOS model was adaptively modified using the mmrotated framework from OpenMMLab, incorporating the mean teacher framework to facilitate subsequent experiments. Within the mmrotated framework, the FCOS model parameters were initialized using model parameters pre-trained on the DOTA 1.0 dataset, and ω was set during training using the mean teacher framework. sup =1.0, ω unsup =0.2. Other training parameters and iteration strategies all used the default mmrotated configuration to ensure fairness in subsequent comparative experiments.
[0186] Specifically, to verify the effectiveness of this method, six different downstream rotational object detection models (FCOS+PSC, KFIoU+Retinanet, SASM, Rotated FCOS, Rotated RepPoints, and Rotated-Retinanet) were combined in experiments on the CycleGAN network model (CG) and the boundary-stabilized generative adversarial network model (BS-GAN). Ablation analysis was performed on three components: style transfer model, mean teacher frame, and boundary enhancement module. Finally, the accuracy of the rotational object detection model was evaluated on a real hair image set, as shown in Table 1. mAP represents the mean accuracy of the model across all categories when the IoU threshold is 0.50.
[0187] As shown in Table 1, from the perspective of ablation experiments, the mAP accuracy of almost all combined models increases with the addition of each component, proving the effectiveness of the components. From the perspective of comparative experiments on style transfer models, the accuracy of all object detection models combined with BS-GAN is higher than that combined with CG, proving the effectiveness of the BS-GAN improvement. From the perspective of comparative experiments on rotated object detection models, the accuracy of the FCOS+PSC model used in this application as the base model is higher than that of all other object detection models, proving that using FCOS+PSC has better advantages.
[0188] Table 1
[0189]
[0190] Among them, FCOS+PSC is the rotating target detection model of this application. The FCOS module can be found in the following reference: Anchor-Free Object Detector. Fcos: a simple and strong anchor-free object detector. IEEE Transactions on Pattern Analysis and Machine Intelligence, 44(4), 2022. The PSC module can be found in the following reference: Yi Yu and Feipeng Da. Phase-shifting coder: Predicting ac-curate orientation in oriented object detection. In Proceedings of the IEEE / CVF Conference on Computer Vision and Pattern Recognition, pages 13354-13363, 2023.
[0191] Other rotating target detection models, such as SASM, Rotated FCOS, and Rotated RepPoints, are models from a model library. You can refer to the following link: https: / / github.com / open-mmlab / mmrotoate / tree / main?tab=readme-ov-file.
[0192] Reference for KFIoU: Xue Yang, Yue Zhou, Gefan Zhang, Jirui Yang, Wentao Wang, Junchi Yan, Xiaopeng Zhang, and Qi Tian. The kfiou loss for rotated object detection. arXiv preprint arXiv: 2201.12558, 2022.
[0193] Retinanet can refer to the literature: T-YLPG Ross and GKHP Dollar. Focal loss for dense object detection. In proceedings of the IEEE conference on computer vision and pattern recognition, pages 2980-2988, 2017.
[0194] Rotated-Retinanet can refer to the literature: T-YLPG Ross and GKHP Dollar.Focal loss for dense object detection.In proceedings of the IEEE conference on computervision and pattern recognition, pages 2980-2988, 2017.
[0195] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0196] The embodiments described above are merely specific and detailed examples of the embodiments described in this application, and should not be construed as limiting the scope of the application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these modifications and improvements all fall within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the appended claims.
Claims
1. A high-precision hair detection method based on boundary-stable generative adversarial network model, characterized by: Includes the following steps: S1. Obtain a hair training set, which includes several data pairs ( , , label), where, To simulate hair images, The image is a mask, and the label is a set of labels consisting of all the hairs. S2. Establish a boundary-stable generative adversarial network (GAN) model and train it using a hair training set and a real hair image set. The boundary-stable GAN model includes a style transfer module. And both are related to the style transfer module. Connected semantic segmentation module The discriminator D and the boundary enhancement module, the real hair image set includes several real hair images. ; S3. Input the hair training set and the real hair image set back into the trained boundary-stabilized generative adversarial network model to obtain the final stylized image set, which includes several final stylized images. ; S4. Establish a rotating target detection model, which includes an anchorless target detection model and a rotation auxiliary module. The rotation auxiliary module is used to decode the encoded angle matrix output by the detection head in the anchorless target detection model to obtain an angle matrix, which corresponds to the rotation angle of all rotating target detection boxes in the image. S5. Based on the mean teacher framework, the rotating target detection model is trained using a set of real hair images, a set of final stylized images, and a set of corresponding labels. The trained rotating target detection model is the teacher model of the mean teacher framework. S6. Using the teacher model with the trained mean teacher framework, target detection is performed on the hair image to be tested, and the rotated target detection box for each hair is the hair detection result.
2. The high-precision hair detection method based on a boundary-stabilized generative adversarial network model as described in claim 1, characterized in that: The style transfer module and semantic segmentation module All models use the ResNet network model, and the discriminator D uses the CNN network model.
3. The high-precision hair detection method based on a boundary-stabilized generative adversarial network model as described in claim 1, characterized in that: The training process, which uses a hair training set and a set of real hair images, is as follows: S21, simulate hair image Input style transfer module The corresponding output style transfer image ; S22. Transfer the style-transferred images obtained in step S21 to each... and corresponding real hair images Input discriminator D to obtain adversarial loss The adversarial loss is used to iteratively update the discriminator D. The calculation is as follows: ; in, This represents the binary cross-entropy loss. Indicates the image The classification prediction value output after inputting into the discriminator D. Representing category labels, when an image For style transfer images hour, The value is 0 when the image Real hair image hour, The value is 1; S23. Then transfer the style transfer image. Input semantic segmentation module The corresponding output segmentation result and through the mask image Calculate the segmentation loss to iteratively update the semantic segmentation module. The segmentation loss The calculation is as follows: ; in, Indicates L1 loss; S24, Gradient Inversion Adversarial Loss After and segmentation loss Perform a weighted summation to obtain the style transfer module. The overall loss is updated in the style migration module iteratively. The style transfer module Total loss The calculation is as follows: ; in, To combat losses The weighting coefficients, To divide the loss The weighting coefficients, Indicates gradient reversal; S25. Repeat steps S21~S24 until the hair training set and the real hair image set have been traversed to obtain the trained style transfer module. At the same time, a well-trained boundary-stabilized generative adversarial network model is formed.
4. The high-precision hair detection method based on a boundary-stabilized generative adversarial network model as described in claim 3, characterized in that: The hair training set and the real hair image set are then input again into the trained boundary-stabilized generative adversarial network model to obtain the final stylized image set, as detailed below: S31, simulate hair image Input to the trained style transfer module The corresponding output style transfer image ; S32. Transfer the style-transferred image obtained in step S31. and the corresponding mask image The input boundary enhancement module performs boundary enhancement, and the corresponding output is the final stylized image. The boundary enhancement module performs the following operations: S321. Based on the corresponding style transfer image and mask image The following formula is used to filter out problematic pixels: ; in, This indicates the filtering results for the problematic pixels. Represents the mask image The normalized image matrix, Indicates style transfer image The normalized image matrix, where c is the preset color value. Representing style transfer images The error threshold, Represents a mask image Error threshold; S322. After color shifting and adjusting each problematic pixel, perform Gaussian smoothing to obtain the final stylized image. The color shift adjustment is calculated using the following formula: ; in, This indicates the color translation adjustment result for the corresponding problematic pixel. The problem pixel represents the coordinate position (x, y). This represents the color value of the t-th pixel randomly sampled centered at coordinates (x, y). , This represents the number of sampling points used for random sampling. This refers to the color shift coefficient; S33. Repeat steps S31 to S32 until the hair training set and the real hair image set are traversed to obtain the final stylized image set.
5. The high-precision hair detection method based on a boundary-stabilized generative adversarial network model as described in claim 4, characterized in that: The mean-based teacher framework uses a set of real hair images, a set of final stylized images, and a corresponding label set to train the rotation target detection model. The trained rotation target detection model is the teacher model of the mean-based teacher framework, as detailed below: S51. Utilizing the final stylized image The rotating target detection model was initially trained with the corresponding label set and used as the student model of the mean teacher framework; S52. Replicate the student model in the mean teacher framework as the teacher model in the mean teacher framework; S53. Final stylized image Input the student model with the mean teacher framework, obtain the first predicted value of the output, and calculate the supervised loss between the first predicted value and the corresponding label set. The formula is as follows: ; in, Indicates L1 loss, This indicates that the input is the final stylized image. The output of the student model; S54, Use real hair images Input the student model and teacher model of the mean teacher framework respectively, and output the second and third predicted values respectively. Calculate the unsupervised loss between the second and third predicted values. The formula is as follows: ; in, Indicates L1 loss, This indicates that the input is a real hair image. The output of the student model, This indicates that the input is a real hair image. The output of the teacher model; S55, Regarding the loss of supervision and unsupervised losses Obtain the average loss by performing a weighted summation. and average loss Backpropagation to the student model using the mean teacher framework, the average loss The formula is as follows: ; in, Indicates monitoring loss loss weights, Indicates unsupervised loss Loss weights; S56. The current iteration parameters of the student model based on the mean teacher framework are dynamically updated by weighting the parameters of the teacher model based on the mean teacher framework using an exponential moving average. S57. Repeat steps S51 to S56 until the real hair image set, the final stylized image set and the corresponding label set are traversed to obtain the teacher model of the trained mean teacher framework.
6. The high-precision hair detection method based on a boundary-stabilized generative adversarial network model as described in claim 1, characterized in that: The target detection model without anchor boxes is the FCOS model, and the rotation assistance module is the PSC module.
7. The high-precision hair detection method based on a boundary-stabilized generative adversarial network model as described in claim 1, characterized in that: The process of obtaining the hair training set is as follows: S11. Establish a Cartesian coordinate system oxy on the canvas and randomly generate the hair follicle location set P and hair whorl location O based on a two-dimensional Gaussian distribution function, where, , This represents the location of the j-th hair follicle, where j = 1, 2, ..., m, and m is the number of hair follicle locations. S12. Connect each hair follicle location to the hair whorl location O, and denote the connection vector between the j-th hair follicle location and the hair whorl location O as follows: and view the connection vector The angle between the hair and the pre-selected coordinate axis is the initial growth angle of the hair at the j-th hair follicle location. The pre-selected coordinate axis is either the x-axis or the y-axis; S13. Randomly offset the initial growth angle of all hairs in all hair follicle locations to obtain the offset angle of the i-th hair. ,in, where n is the number of hairs; S14. Simulate the shape and thickness of all hairs, and generate hair according to the offset angle of all hairs to obtain a mask image. And a label for all the hair, the label being a hair root with a width of w, a length of h, and a rotation angle of [missing information]. The rotating target detection bounding box, where w equals the average width of the hair, and h is less than or equal to a preset value. ; S15. Mask image Images of bald heads Image fusion is performed to obtain a fused image. This is a simulated hair image; S16. Obtain the corresponding mask image. fused images The label set formed by the labels of all hairs is used as a data pair. , The data (label) is included in the hair dataset, and the process returns to step S11 until a preset number of data pairs are obtained. , , label), using the hair dataset as the hair training set.
8. The high-precision hair detection method based on a boundary-stabilized generative adversarial network model as described in claim 7, characterized in that: The process simulates the shape and thickness of all hairs, and generates hair based on the offset angle of all hairs to obtain a mask image. The tags for all the hair are as follows: S141. Establish the shape simulation formula for the i-th hair and perform sampling to obtain the sampling point set of the i-th hair. To simulate the shape of the corresponding hair, where the set of x-coordinates of the sampling points... = y-coordinate set of sampling points = , This represents the i-th hair. x-axis coordinates of each sampling point This represents the i-th hair. The y-axis coordinates of each sampling point num represents the number of sampling points for the i-th hair, and the shape simulation formula for the i-th hair is as follows: ; in, This represents the shape of the i-th hair. This represents the x-axis coordinate of the i-th hair. This represents the bending frequency of the randomly generated i-th hair. This represents the bending phase of the randomly generated i-th hair. This represents the length of the randomly generated i-th hair; S142. Perform a rotation and translation operation on the sampling point set of the corresponding hair according to the offset angle of each hair to obtain the transformed sampling point set of the corresponding hair. Then the sampling point set of the i-th hair... The formulas for rotation and translation operations are as follows: ; in, This represents the x-axis coordinates of all sampled points after the corresponding hair has undergone a rotation and translation operation. This represents the y-axis coordinates of all sampled points after the corresponding hair has undergone a rotation and translation operation. That is, the set of transformed sampling points for the i-th hair. This represents the set of x-coordinates of the sampled points before the corresponding hair undergoes a rotation and translation operation. transpose, This represents the set of ordinates of the sampled points before the corresponding hair undergoes a rotation and translation operation. transpose, This represents the x-axis coordinate of the root of the i-th hair. This represents the y-axis coordinate of the root of the i-th hair; S143. Based on the established formula for simulating the thickness of the i-th hair, obtain the width of all sampling points in the sampling point set of the corresponding hair to simulate the thickness of the corresponding hair. The formula for simulating the thickness of the i-th hair is as follows: ; in, This represents the width of the k-th sampling point of the i-th hair, i.e., the thickness of the k-th sampling point of the i-th hair. This represents the initial width of the randomly generated hair; S144. Generate hair based on the conversion sampling point set of each hair and the width correspondence of all sampling points, and obtain the mask image. And tags for all the hair.
9. The high-precision hair detection method based on a boundary-stabilized generative adversarial network model as described in claim 7, characterized in that: The image fusion formula is as follows: ; in, This represents the output result of image fusion, i.e., the fused image. , This represents hyperparameters.
10. The high-precision hair detection method based on a boundary-stabilized generative adversarial network model as described in claim 7, characterized in that: The hair follicle location set P and the hair whorl location O are obtained as follows: Create a grid on the canvas; Using each intersection point in the grid as a reference point, the position coordinates of the corresponding intersection points are randomly generated using a two-dimensional Gaussian distribution function as the hair follicle positions. All hair follicle positions together form the hair follicle position set P, and the reference point is the center point of the two-dimensional Gaussian distribution function. Using the center point of the canvas as the reference point, the position O of the hair whorl is randomly generated using a two-dimensional Gaussian distribution function; Before connecting each hair follicle location to the hair whorl location O, the following operation is also performed: A first preset number of hair follicle positions are randomly generated on the canvas to update the number of hair follicle positions m, which is m+l, where l is the first preset number; The number of hairs at each hair follicle location is at least one. When there are multiple hairs at the corresponding hair follicle location, a second preset number of hair follicle locations are randomly selected from the hair follicle location set P and marked to indicate that multiple hairs are generated at the marked hair follicle locations.
Citation Information
Patent Citations
Head decoration processing method and device based on artificial intelligence
CN111563868A
Portrait image hair removal method and device based on GAN network
CN114663274A