This application is claims priority to Chinese Application No. 202011379566.1, filed on Nov. 30, 2020, which is incorporated herein by reference in its entirety.
The present disclosure relates to a field of artificial intelligence technology, and in particular to computer vision and deep learning technologies.
In a field of artificial intelligence technology, a technical solution has been proposed to process an image containing a character for a computer vision and deep learning technologies. Specifically, in fields of beauty, hairdressing, medical beauty, image processing, etc., different hairstyles (such as long hair, short hair, straight hair, curly hair, etc.) may be designed for the user, in order to find a most suitable hairstyle for a user. At present, technical solutions to change the hairstyle based on a neural network technology are proposed, but performances of these technical solutions are not satisfactory. At this time, how to change the hairstyle of the character in a simpler and more effective way has become a technical challenge.
According to the example embodiments of the present disclosure, a scheme for changing a hairstyle of a character is provided.
In a first aspect of the present disclosure, a method for changing a hairstyle of a character is provided. The method includes: determining an original feature vector of an original image containing the character, in which the character in the original image has an original hairstyle; acquiring a boundary vector associated with the original hairstyle and a target hairstyle based on a hairstyle classification model; determining a target feature vector corresponding to the target hairstyle based on the original feature vector and the boundary vector; and generating a target image containing the character based on the target feature vector, in which the character in the target image has the target hairstyle.
In a second aspect of the present disclosure, an electronic device is provided. The device includes: one or more processors; 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, when executed by the at least one processor, cause the at least one processor to implement the method according to the first aspect of the present disclosure.
In a third aspect of the present disclosure, a computer-readable storage medium storing computer instructions for a computer to implement the method according to the first aspect of the present disclosure is provided.
It should be understood that the content described in the summary is not intended to limit the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will be easily understood by the following description.
The above mentioned and other features, advantages and aspects of various embodiments of the present disclosure will become more apparent in combination with the accompanying drawings and with reference to the following detailed description. In the accompanying drawings, the same or similar reference signs indicate the same or similar elements, in which:
Hereinafter, the embodiments of the present disclosure will be described in more detail with reference to the accompanying drawings. Although some embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure may be implemented in various forms, and should not be construed as being limited to the embodiments set forth herein. On the contrary, these embodiments are provided for a more thorough and complete understanding of the present disclosure. It should be understood that the accompanying drawings and embodiments of the present disclosure are only used for exemplary purposes, and are not used to limit the protection scope of the present disclosure.
In the description of the embodiments of the present disclosure, the term “including” and its similar terms may be understood as open inclusion, namely “including but not limited to”. The term “based” may be understood as “at least partially based”. A term “an embodiment” or “the embodiment” may be understood as “at least one embodiment”. The terms “first”, “second” and so on may refer to different objects or a same object. Other clear and implied definitions may also be included below.
In the field of artificial intelligence technology, a technical solution of processing an image of a character for computer vision and deep learning technologies is provided. Specifically, in fields of beauty, hairdressing, medical beauty, image processing, etc., tools for designing different hairstyles (such as long hair, short hair, straight hair, curly hair, etc.) for the characters are provided. These tools may be used to find a most suitable hairstyle for a user. First, a process for changing the hairstyle is introduced with reference to
Technical solutions of changing a hairstyle based on a neural network technology are provided. However, these technical solutions require a large amount of training data, and the quality of training data seriously affects an effect of the changed hairstyle. In addition, existing hairstyle changing models can only use preset hair models, such as for changing long hair to short hair, changing curly hair to straight hair, etc., and cannot achieve a conversion between any hairstyles.
In order to at least partially solve shortcomings in the above-mentioned technical solutions, a technical solution for changing a hairstyle of a character is provided according to the exemplary embodiments of the present disclosure. According to the exemplary embodiments of the present disclosure, a feature vector of an image may be extracted from the original image 110, and the target image 120 related to a target hairstyle may be generated by adjusting the feature vector. Specifically, a concept of a boundary vector is proposed, and the boundary vector may represent a boundary between two hairstyles (for example, an original hairstyle “curly hair” and a target hairstyle “straight hair”). That is, for a feature vector of any image, a hairstyle of a character in the image may be changed to any of the two hairstyles based on the boundary vector. For example, the hairstyle of the character may be changed to the straight hair by determining a sum of the feature vector and the boundary vector; and the hairstyle of the character may be changed to the curly hair by determining a difference between the feature vector and the boundary vector.
According to the exemplary embodiments of the present disclosure, instead of obtaining a perfect hairstyle changing model by using a large amount of training images, a hairstyle classification model may be obtained based on less training images. Furthermore, one or more boundary vectors between different types of hairstyles may be obtained. In this way, by using various boundary vectors, a simple and effective conversion between different types of hairstyles may be achieved.
Hereinafter, the technical solution will be described briefly in
According to the exemplary embodiments of the present disclosure, a conversion between various hairstyles may be achieved. It should be understood that the hairstyle may involve multiple attributes. For example, attributes regarding curl degree may include straight hair and curly hair. Further, curly hair may be subdivided into more curling grades. For another example, attributes regarding color may include black hair, brown hair, yellow hair, white hair, etc. Thus, according to the exemplary embodiments of the present disclosure, the hairstyle may include at least one of the following attributes: a length, a curl degree, a color, a hair parting style, and a bangs style, etc.
According to the exemplary embodiments of the present disclosure, the number of attributes of the hairstyle to be changed is not limited, and the change may involve one or more attributes. In an example, the original hairstyle 210 may include short curly hair, and the target hairstyle 220 may include short straight hair, and in this case, the change only involves the curl degree and does not involve the length. In another example, the original hairstyle 210 may include short curly hair, and the target hairstyle 220 may include long straight hair, and in this case, the change for the hairstyle may involve both the length and the curl degree. In the following, the change of hairstyle involving one attribute will be described first.
In the following, more details of the method according to the exemplary embodiments of the present disclosure will be described with reference to
According to the exemplary embodiments of the present disclosure, the original image 110 may be divided into a plurality of regions according to a body structure of the character. In the following, more details about the division of regions will be described with reference to
According to the exemplary embodiments of the present disclosure, a head region 420 (as shown in a solid line region) may be determined from the foreground region of the original image 110 based on a head detection model, and a remaining portion of the foreground region may be regarded as a body region 430. The head detection model may be a model generated based on an existing mature technology. For example, the head detection model may be trained based on a machine learning technology. In this way, the head region 420 may be recognized from the original image 110 in a convenient and effective manner.
Further, a hairstyle region 450 may be determined in the head region 420 based on a key-point detection model. It should be understood that, the key-point detection model may be a model generated based on an existing mature technology. For example, the key-point detection model may be trained based on a machine learning technology. The model may detect key-points related to a hairline, a nose, eyes, and a mouth. Based on the detected key-points, the head region 420 may be divided into a hairstyle region 450, a face region 460, an eye region 470, a nose region 480, and a mouth region 490. In this way, the hairstyle region 450 and other regions of the face may be recognized from the original image 110 in a convenient and effective manner.
According to the exemplary embodiments of the present disclosure, in order to ensure that the generated original feature vector 230 may reflect an appearance of the character as accurately as possible, a normalization may be performed for the head region 420 in the original image 110 to eliminate an influence of illumination in an environment in which the character is located. For example, a mean value and/or a variance value of various pixels in the head region 420 may be determined, and the normalization may be performed based on the mean value and/or the variance value described above. In this way, the influence of ambient light on the head region 420 of the character may be eliminated, and a difference in brightness of the image caused by the unevenness of light and dark in part of the image may be reduced.
According to the exemplary embodiments of the present disclosure, a plurality of feature sub-vectors may be generated for the plurality of regions, respectively. Specifically, a feature sub-vector corresponding to each region may be generated, and the original feature vector 230 may be determined based on the plurality of feature sub-vectors. In the following, more details about generating feature vectors will be described with reference to
According to the exemplary embodiments of the present disclosure, the feature extraction model 510 may include convolutional layers 512, . . . , and 514. The above-mentioned convolutional layers may be used to determine a sub-feature for each region, respectively. Further, the feature extraction model 510 may include a pooling layer 516, and the pooling layer 516 may perform region-related pooling operations based on the plurality of regions marked in the region image 410, so as to generate the final original feature vector 230.
According to the exemplary embodiments of the present disclosure, the original feature vector 230 may be generated based on the sub-features for the plurality of regions.
It should be understood that
The specific process for obtaining the original feature vector 230 from the original image 110 is described above with reference to
A plurality of training images associated with the original hairstyle 210 and the target hairstyle 220 may be acquired respectively, and the character in each training image may have the original hairstyle 210 or the target hairstyle 220. It should be noted that the training image containing the character in this embodiment may come from a public data set. According to the exemplary embodiments of the present disclosure, a large number of training images are not required, and a small number (for example, dozens or other number) of images including a plurality of hairstyles may be used. Specifically,
Each training image may be processed in accordance with the method shown above referring to
According to the exemplary embodiments of the present disclosure, the hairstyle classification model 240 may be generated based on a machine learning technology currently available and/or to be developed in the future. The hair classification model 240 obtained by training may classify an input image into curly hair or straight hair based on a feature vector of the input image. A boundary vector indicating a boundary between the curly hair and the straight hair may be acquired from the hairstyle classification model 240. In other words, a feature vector on a side of a high-dimensional curved surface represented by the boundary vector is classified into curly hair, and a feature vector on another side of the high-dimensional curved surface represented by the boundary vector will be classified into straight hair.
At this time, for a feature vector of any image, a sum of the feature vector and the boundary vector may correspond to a hairstyle (for example, straight hair), and a difference between the feature vector and the boundary vector may correspond to another hairstyle (for example, curly hair). In this way, any hairstyle may be converted into curly hair or straight hair based on the boundary vector.
It should be understood that the above description only schematic illustrates the case that the curl degree includes two classes, i.e. the curly hair and the straight hair. According to the exemplary embodiments of the present disclosure, the curl degree may also include more grades. Assuming that the curl degree is divided into N grades, a hair classification model may be generated by using sets of training images containing hairstyles with different curl degrees based on the method described above. In this case, the generated hair classification model may classify the hairstyle of the character into N curling grades, and N-1 boundary vectors may be obtained.
It should be understood that the above description takes only the curly hair and the straight hair as examples to describe how to determine the boundary vector between the curly hair and the straight hair. According to the exemplary embodiments of the present disclosure, other attributes included in the hairstyle may also be processed. For example, the hair classification model 240 may be generated based on a set of training images contain characters having long hair and a set of training images contain characters having short hair respectively, so as to obtain a boundary vector between long hair and short hair. For a feature vector of any image, a sum of the boundary vector between long hair and short hair and the feature vector may correspond to a hairstyle (for example, short hair), and a difference between the feature vector and the boundary vector may correspond to another hairstyle (for example, long hair). In this way, any hairstyle may be converted into long hair or short hair based on the boundary vector.
For example, the hair classification model 240 may be generated based on a set of training image sets containing characters having black hair and a set of training image sets containing characters having brown hair respectively, so as to obtain a boundary vector between black hair and brown hair. For example, the hair classification model 240 may also be trained according to the hair parting style (for example, left side parting, central parting, right side parting, etc.). The hairstyle classification model may be trained according the bangs style (for example, no bangs, short bangs, long bangs, etc.). In this way, any hairstyle may be converted to include a specified color, hair parting style, and bangs style based on the boundary vector. A boundary vector between any two of the plurality of hairstyles may be determined in the manner as described above.
The case that the boundary vector relates to one attribute is described above. According to the exemplary embodiments of the present disclosure, the boundary vector may relate to varying of multiple attributes. Two sets of training images may include differences among multiple attributes. Characters A set of training images may contain characters having black curly hair, and another set of training images may contain characters having brown straight hair. In this case, a boundary vector between black curly hair and brown straight hair may be acquired based on the hair classification model.
The specific process for acquiring the boundary vector 250 based on the hairstyle classification model 240 is described above with reference to
According to the exemplary embodiments of the present disclosure, assuming that the original feature vector 230 includes 2048 dimensions and a hairstyle sub-vector occupies dimensions 1 to 512, it is just required to change the data in the 1st to 512th dimensions based on the boundary vector 250. Specifically, the data in the 1st to 512th dimensions of the original feature vector 230 may be summed up with the boundary vector, thereby obtaining the target feature vector 260.
It should be understand that although only the process for changing one attribute included in the hairstyle is described above, multiple attributes included in the hairstyle may be changed at a time according to the exemplary embodiments of the present disclosure. For example, the curl degree and the color of the character's hair may be changed at the same time. Assuming that the character in the original image 110 has black curly hair, and the target hairstyle 220 may be set to brown straight hair. In this case, the original feature vector 230 may be updated based on the boundary vector between curly hair and straight hair and the boundary vector between black hair and brown hair, so as to obtain the target feature vector 260 corresponding to the brown straight hair. For example, the target feature vector 260 corresponding to brown straight hair may be determined based on the boundary vectors involving multiple attributes described above.
At block 340 of
As shown in
According to the exemplary embodiments of the present disclosure, noise data may be introduced to add variance in the original image 110. Specifically, the target image 120 may be generated based on both a noise vector for adjusting the target image and the target feature vector 260. It should be understood that the noise vector here may be used to adjust just a portion related to the hairstyle region 450. Alternatively and/or additionally, the noise vector may be used to adjust all regions of the image. As shown in
It should be understood that as a character gets older, a hair loss may occur and lead to a change of a hairline. According to the exemplary embodiments of the present disclosure, the change of the hairline of the character may be simulated, to provide target images 120 containing hairlines with different heights. Specifically, an original hairline of the character in the original image 110 may be determined based on the hairstyle region 450. A position of a target hairline may be received, and a target hairline mask may be generated based on the original hairline and the target hairline. The hairline mask may control a region in which the changed hair is located. Further, the target image 120 may be generated based on the target feature vector 260 and the target hairline mask. As an example, in the target image 120, the hairline moving upward as the character getting older may be simulated. As another example, in the target image 120, the hairline returning to a young state after hair transplantation may be simulated.
The specific process of various steps for changing the hairstyle of the character is described above with reference to
According to the exemplary embodiments of the present disclosure, a boundary vector between any two of the plurality of hairstyles may be obtained. Based on the above-mentioned boundary vector, any hairstyle of the character may be converted into a desired hairstyle. In this way, it is not necessary to use a large number of training images to obtain a conversion model between any two hairstyles, and a desired hairstyle classification model and thus a boundary vector related thereto may be obtained by using less training images. By using the method described above, the requirements for training data may be greatly reduced, a calculation amount of training process may be reduced and a realistic target image may be obtained.
The embodiments of the method 300 for changing the hairstyle of the character are described in detail above. According to the exemplary embodiments of the present disclosure, an apparatus for changing the hairstyle of the character is also provided. In the following, it will be described in detail with reference to
According to the exemplary embodiments of the present disclosure, the original feature determination module 1010 includes: a division module configured to divide the original image into a plurality of regions according to a body structure of the character; a sub-vector generation module configured to generate a plurality of feature sub-vectors for the plurality of regions respectively; and a vector determination module configured to determine the original feature vector based on the plurality of feature sub-vectors.
According to the exemplary embodiments of the present disclosure, the division module includes: a head region determination module configured to determine a head region in the original image based on a head detection model; and a hairstyle region determination module configured to determine a hairstyle region in the head region based on a key-point detection model.
According to the exemplary embodiments of the present disclosure, the apparatus 1000 further includes: a normalization module configured to normalize the original image to eliminate an influence of illumination in an environment in which the character is located.
According to the exemplary embodiments of the present disclosure, the acquisition module 1020 includes: a training image acquisition module configured to acquire a plurality of sets of training images, in which each set of training images contains characters having one of a plurality of hairstyles; a training feature determination module configured to determine a feature vector of each training image in each set of training images; a classification model generation module configured to generate the hairstyle classification model based on the feature vector of each training image and the hairstyle of the character in the each training image; and a boundary vector determination module configured to determine the boundary vector describing between any two of the plurality of hairstyles based on the hairstyle classification model.
According to the exemplary embodiments of the present disclosure, the target feature determination module 1030 includes: an updating module configured to update a feature sub-vector corresponding to the hairstyle region in the original feature vector based on the boundary vector.
According to the exemplary embodiments of the present disclosure, the generation module 1040 further includes: a hairline determination module configured to determine an original hairline of the character in the original image based on the hairstyle region; a mask generation module configured to generate a target hairline mask based on the original hairline and a target hairline; and a target image generation module configured to generate the target image based on the target feature vector and the target hairline mask.
According to the exemplary embodiments of the present disclosure, the generation module 1040 further includes: a noise module configured to generate the target image based on the target feature vector and a noise vector for adjusting the target image.
According to the exemplary embodiments of the present disclosure, each of the original hairstyle and the target hairstyle includes at least one of: an attribute of length, an attribute of curl degree, an attribute of color, an attribute of hair parting style, and an attribute of bangs style.
Collecting, storing, using, processing, transmitting, providing, and disclosing etc. of the personal information of the user involved in the present disclosure all comply with the relevant laws and regulations, and do not violate the public order and morals.
Multiple components in the device 1100 are connected to the I/O interface 1105. The multiple components include: an input unit 1106, such as a keyboard, a mouse, etc.; an output unit 1107, such as various types of displays, speakers, etc.; and a storage unit 1108, such as a disk, an optical disc, etc.; and a communication unit 1109, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 1109 allows the device 1100 to exchange information/data with other devices through a computer network such as the Internet and/or various telecommunication networks.
The processing unit 1101 executes the various methods and processes described above, for example, the method 300. For example, in some implementations, the method 300 may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as the storage unit 1108. In some implementations, the computer programs may be partly or entirely loaded and/or installed on the device 1100 via the ROM 1102 and/or the communication unit 1109. When the computer program is loaded into the RAM 1103 and executed by the CPU 1101, one or more steps of the method 300 described above may be executed. Alternatively, in other implementations, the CPU 1101 may be configured to execute the method 300 in any other suitable manner (for example, by means of firmware).
According to the exemplary embodiments of the present disclosure, a computer-readable storage medium having a computer program stored thereon is provided. When the program is executed by the processor, the method described in the present disclosure is implemented.
The functions described hereinabove may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate array (FPGA), application specific integrated circuit (ASIC), application specific standard product (ASSP), system on chip system (SOC), complex programming logic device (CPLD) and so on.
The program codes used to implement the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to the processors or controllers of general-purpose computers, special-purpose computers, or other programmable data processing apparatus, so that when the program codes are executed by the processors or controllers, the functions/operations specified in the flowcharts and/or block diagrams are implemented. The program codes may be executed entirely on the machine, executed partly on the machine, executed partly on the machine as an independent software package, executed partly on the remote machine and partly on the remote machine, or executed entirely on the remote machine or server. The server may be a cloud server, a server of a distributed system, or a server in combination with block chains.
In the context of the present disclosure, a machine-readable medium may be a tangible medium, which may contain or store a program for use by an instruction execution system, apparatus, or device, or in combination with the instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of machine-readable storage medium may include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination of the foregoing.
In addition, although the operations are depicted in a specific order, this should be understood as requiring such operations to be performed in the specific order shown or in a sequential order, or requiring all illustrated operations to be performed to achieve the desired results. Under certain circumstances, multitasking and parallel processing may be advantageous. Likewise, although several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of the present disclosure. Certain features that are described in the context of separate implementations can also be implemented in combination in a single implementation. Conversely, various features that are described in the context of a single implementation can also be implemented in multiple implementations individually or in any suitable sub-combination.
Although the subject matter has been described in language specific to structural features and/or method logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely exemplary forms of implementing the claims.
Number | Date | Country | Kind |
---|---|---|---|
202011379566.1 | Nov 2020 | CN | national |