• AIPressRoom
  • Posts
  • On-device real-time few-shot face stylization – Google Analysis Weblog

On-device real-time few-shot face stylization – Google Analysis Weblog

Lately, now we have witnessed rising curiosity throughout customers and researchers in built-in augmented actuality (AR) experiences utilizing real-time face characteristic era and enhancing capabilities in cell functions, together with brief movies, digital actuality, and gaming. In consequence, there’s a rising demand for light-weight, but high-quality face era and enhancing fashions, which are sometimes based mostly on generative adversarial community (GAN) strategies. Nonetheless, nearly all of GAN fashions undergo from excessive computational complexity and the necessity for a big coaching dataset. As well as, it is usually vital to make use of GAN fashions responsibly.

On this publish, we introduce MediaPipe FaceStylizer, an environment friendly design for few-shot face stylization that addresses the aforementioned mannequin complexity and information effectivity challenges whereas being guided by Google’s accountable AI Ideas. The mannequin consists of a face generator and a face encoder used as GAN inversion to map the picture into latent code for the generator. We introduce a mobile-friendly synthesis community for the face generator with an auxiliary head that converts options to RGB at every stage of the generator to generate top quality pictures from coarse to wonderful granularities. We additionally rigorously designed the loss capabilities for the aforementioned auxiliary heads and mixed them with the widespread GAN loss capabilities to distill the coed generator from the instructor StyleGAN mannequin, leading to a light-weight mannequin that maintains excessive era high quality. The proposed answer is offered in open supply via MediaPipe. Customers can fine-tune the generator to be taught a method from one or a couple of pictures utilizing MediaPipe Mannequin Maker, and deploy to on-device face stylization functions with the personalized mannequin utilizing MediaPipe FaceStylizer.

Few-shot on-device face stylization

An end-to-end pipeline

Our purpose is to construct a pipeline to assist customers to adapt the MediaPipe FaceStylizer to totally different types by fine-tuning the mannequin with a couple of examples. To allow such a face stylization pipeline, we constructed the pipeline with a GAN inversion encoder and environment friendly face generator mannequin (see beneath). The encoder and generator pipeline can then be tailored to totally different types through a few-shot studying course of. The person first sends a single or a couple of related samples of the fashion pictures to MediaPipe ModelMaker to fine-tune the mannequin. The fine-tuning course of freezes the encoder module and solely fine-tunes the generator. The coaching course of samples a number of latent codes near the encoding output of the enter fashion pictures because the enter to the generator. The generator is then skilled to reconstruct a picture of an individual’s face within the fashion of the enter fashion picture by optimizing a joint adversarial loss operate that additionally accounts for fashion and content material. With such a fine-tuning course of, the MediaPipe FaceStylizer can adapt to the personalized fashion, which approximates the person’s enter. It might then be utilized to stylize check pictures of actual human faces.

Generator: BlazeStyleGAN

The StyleGAN mannequin household has been broadly adopted for face era and varied face enhancing duties. To assist environment friendly on-device face era, we based mostly the design of our generator on StyleGAN. This generator, which we name BlazeStyleGAN, is much like StyleGAN in that it additionally incorporates a mapping community and synthesis community. Nonetheless, for the reason that synthesis community of StyleGAN is the foremost contributor to the mannequin’s excessive computation complexity, we designed and employed a extra environment friendly synthesis community. The improved effectivity and era high quality is achieved by:

  1. Decreasing the latent characteristic dimension within the synthesis community to 1 / 4 of the decision of the counterpart layers within the instructor StyleGAN,

  2. Designing a number of auxiliary heads to remodel the downscaled characteristic to the picture area to type a coarse-to-fine picture pyramid to judge the perceptual high quality of the reconstruction, and

  3. Skipping all however the closing auxiliary head at inference time.

With the newly designed structure, we practice the BlazeStyleGAN mannequin by distilling it from a instructor StyleGAN mannequin. We use a multi-scale perceptual loss and adversarial loss within the distillation to switch the excessive constancy era functionality from the instructor mannequin to the coed BlazeStyleGAN mannequin and likewise to mitigate the artifacts from the instructor mannequin.

Extra particulars of the mannequin structure and coaching scheme will be present in our paper.

Within the above determine, we exhibit some pattern outcomes of our BlazeStyleGAN. By evaluating with the face picture generated by the instructor StyleGAN mannequin (prime row), the pictures generated by the coed BlazeStyleGAN (backside row) keep excessive visible high quality and additional scale back artifacts produced by the instructor because of the loss operate design in our distillation.

An encoder for environment friendly GAN inversion

To assist image-to-image stylization, we additionally launched an environment friendly GAN inversion because the encoder to map enter pictures to the latent area of the generator. The encoder is outlined by a MobileNet V2 spine and skilled with pure face pictures. The loss is outlined as a mix of picture perceptual high quality loss, which measures the content material distinction, fashion similarity and embedding distance, in addition to the L1 loss between the enter pictures and reconstructed pictures.

On-device efficiency

We documented mannequin complexities when it comes to parameter numbers and computing FLOPs within the following desk. In comparison with the instructor StyleGAN (33.2M parameters), BlazeStyleGAN (generator) considerably reduces the mannequin complexity, with solely 2.01M parameters and 1.28G FLOPs for output decision 256×256. In comparison with StyleGAN-1024 (producing picture dimension of 1024×1024), the BlazeStyleGAN-1024 can scale back each mannequin dimension and computation complexity by 95% with no notable high quality distinction and may even suppress the artifacts from the instructor StyleGAN mannequin.

We benchmarked the inference time of the MediaPipe FaceStylizer on varied high-end cell gadgets and demonstrated the ends in the desk beneath. From the outcomes, each BlazeStyleGAN-256 and BlazeStyleGAN-512 achieved real-time efficiency on all GPU gadgets. It might run in lower than 10 ms runtime on a high-end cellphone’s GPU. BlazeStyleGAN-256 may obtain real-time efficiency on the iOS gadgets’ CPU.

Equity analysis

The mannequin has been skilled with a excessive variety dataset of human faces. The mannequin is predicted to be truthful to totally different human faces. The equity analysis demonstrates the mannequin performs good and balanced when it comes to human gender, skin-tone, and ages.

Face stylization visualization

Some face stylization outcomes are demonstrated within the following determine. The photographs within the prime row (in orange bins) symbolize the fashion pictures used to fine-tune the mannequin. The photographs within the left column (within the inexperienced bins) are the pure face pictures used for testing. The 2×4 matrix of pictures represents the output of the MediaPipe FaceStylizer which is mixing outputs between the pure faces on the left-most column and the corresponding face types on the highest row. The outcomes exhibit that our answer can obtain high-quality face stylization for a number of well-liked types.

MediaPipe Options

The MediaPipe FaceStylizer goes to be launched to public customers in MediaPipe Options. Customers can leverage MediaPipe Mannequin Maker to coach a personalized face stylization mannequin utilizing their very own fashion pictures. After coaching, the exported bundle of TFLite mannequin recordsdata will be deployed to functions throughout platforms (Android, iOS, Net, Python, and so on.) utilizing the MediaPipe Duties FaceStylizer API in just some strains of code.

Acknowledgements

This work is made attainable via a collaboration spanning a number of groups throughout Google. We’d wish to acknowledge contributions from Omer Tov, Yang Zhao, Andrey Vakunov, Fei Deng, Ariel Ephrat, Inbar Mosseri, Lu Wang, Chuo-Ling Chang, Tingbo Hou, and Matthias Grundmann.