GAN反演+老照片修复

发布于:2024-04-24 ⋅ 阅读:(16) ⋅ 点赞:(0)

在这里插入图片描述
关于老照片修复~~~~~上图为运行腾讯ARC的模型之后的效果图

其使用的模型,GFP-GAN,Towards Real-World Blind Face Restoration with Generative Facial Prior,理解记录如下:

Abstract:

In this work, we propose GFP-GAN that leverages rich and diverse priors encapsulated in a pretrained face GAN for blind face restoration.
提出了GFP-GAN,利用丰富多样的先验,将其封装在一个预训练的人脸中,用于模糊人脸修复。

This Generative Facial Prior (GFP) is incorporated into the face restoration process via spatial feature transform layers, which allow our method to achieve a good balance of realness and fidelity.
这种生成性面部先验(GFP)通过空间特征转换层被纳入面部修复过程,这使得我们的方法在真实性和保真度之间取得了良好的平衡。

Thanks to the powerful generative facial prior and delicate designs, our GFP-GAN couldjointly restore facial details and enhance colors with just a single forward pass, while GAN inversion methods require image-specific optimization at inference.
得益于强大的生成性面部先验和精细的设计,GFP-GAN可以通过一次前向传递来联合恢复面部细节和增强颜色,而GAN反演方法需要在推理时对图像进行特定的优化。

Introduction

StyleGAN 等,这些人脸GANs,能够生成具有高度可变性的忠实人脸,从而提供丰富多样的先验, 如几何学、面部纹理和颜色,使得联合恢复面部细节和增强颜色成为可能;

然而,将这种生成性先验因素纳入修复过程是具有挑战性的。

以前 通常使用 GAN inversion


关于GAN反演:

给定一张灰度图像,如何利用预训练好的GAN恢复它的颜色呢?一个自然的想法是在GAN的图像空间寻找一张灰度化后与目标图片一致的图片,由于GAN倾向于输出自然的图片,因此找到的这张图会有自然的颜色。

上述方案要求用GAN的生成器G准确重建一张目标图片。针对该任务,传统的做法是优化生成器输入的隐向量z,又称作GAN inversion。

预训练GAN通常能够生成非常逼真和多样的图像,通过反演找到与特定输入图像对应的潜在代码,我们可以利用GAN的生成先验来执行各种任务,如图像编辑、风格迁移或图像超分辨率等。

用GAN模型近似表征自然图像分布,在恢复图像时,对于失真图,要恢复它,其实就是要在GAN表征的自然图分布中找到一个跟失真图最相似的图。

即,如果我们要复原图像A,则可以训练GAN网络,使其生成一个跟图像A的GroundTruth相似度很高很高的图像,该生成图像即为我们修复后的图像;

在这里插入图片描述
如上图,找相似图的过程是:

比如想复原失去色彩的图像 φ(x),其中 x 指原图Ground Truth,φ 指退化函数,如失去色彩、加噪声……

首先,由GAN生成近似的自然图像 G(z; θ),z 是服从高斯分布的随机向量;

然后对近似自然图 G(z; θ) 进行退化操作 φ,退化结果是 φ(G(z; θ));

那么我们选择一个跟要复原图像 φ(x) 最相似的退化图 φ(G(z; θ)),那退化前的近似自然图G(z; θ)自然可以近似 x。

一般来说,目标函数通常包含两个部分:一是判别器对于生成样本的评价结果;二是输入样本与生成样本之间的差异度量;


此文作者表示,GAN Inversion 尽管有视觉上的真实输出,但是因为低维潜在代码不足以指导准确的修复,通常产生低保真度的图像。

GFP-GAN 网络模型如下:
在这里插入图片描述

It consists of a degradation removal module (U-Net) and a pretrained face GAN as facial prior (such as StyleGAN2).
GFP-GAN包括一个退化消除模块,和一个预训练的面部GAN作为面部先验。

They are bridged by a latent code mapping and several Channel-Split Spatial Feature Transform(CS-SFT) layers.
它们通过一个直接的潜在代码映射和几个通道分割空间特征变换(CS-SFT)层以粗到细的方式连接起来。

Specifically, the degradation removal module is designed to remove complicated degradation, and extract two kinds of features, i.e.

  1. latent features F l a t e n t F_{latent} Flatent to map the input image to the closest latent code in StyleGAN2,
  2. multi-resolution spatial features F s p a t i a l F_{spatial} Fspatial for modulating the StyleGAN2 features.

在这里插入图片描述

A pre-trained face GAN captures a distribution over faces in its leaned weights of convolutions, namely, generative prior.
一个预训练过的人脸GAN在其倾斜的卷积权重中捕捉到了人脸的分布,即生成性先验。

We leverage such pretrained face GANs to provide diverse and rich facial details for our task.
我们利用这种预训练的人脸GANs为我们的任务提供多样化和丰富的面部细节。

A typical way of deploying generative priors is to map the input image to its closest latent codes Z, and then generate the corresponding output by a pretrained GAN.
部署生成式先验的典型方法是将输入图像映射到其最接近的潜在代码Z,然后通过预训练的GAN生成相应的输出。

However, these methods usually require time-consuming iterative optimization for preserving fidelity.
然而,这些方法通常需要耗费时间的迭代优化来保持保真度。

Instead of producing a final image directly, we generate intermediate convolutional features F G A N F_{GAN} FGAN of the closest face, as it contains more details and could be further modulated by input features for better fidelity (see Sec. 3.4).
我们没有直接生成最终图像,而是生成最接近的人脸的中间卷积特征 F G A N F_{GAN} FGAN,因为它包含更多的细节,可以通过输入特征进一步调制以获得更好的保真度。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述


关于 modulate

StyleGAN2 通过使用一种称为“风格调制”(style modulation)的技术来改进图像生成过程。

在这种技术中,生成器网络的不同层接收来自一个或多个“风格代码”(style codes)的输入,这些代码控制生成图像的各种属性,如颜色、纹理和形状。

将多分辨率空间特征集成到 StyleGAN2 的风格调制过程中,这可以通过将 F s p a t i a l F_{spatial} Fspatial 与 StyleGAN2 生成器网络中的相应特征图相结合来实现,从而在空间域中调制风格代码的影响。

这种方法的潜在好处是,它可以允许生成器在生成图像时考虑更多的空间上下文信息。通过在不同空间尺度上引入额外的特征,生成器可以生成更真实、更复杂的图像,这些图像在细节和结构上更加接近真实世界的图像。


GFP-GAN 四大损失:

  1. reconstruction loss: constraints the outputs y ^ \hat{y} y^ close to the ground-truth y y y,

  2. adversarial loss for restoring realistic textures,

  3. proposed facial component loss to further enhance facial details,
    带有局部判别器的面部成分损失,以进一步增强面部细节的感知性;

  4. identity preserving loss.
    身份保护损失,来进一步提高保真度;

参考链接:

  1. https://github.com/TencentARC/GFPGAN
  2. paper: Towards Real-World Blind Face Restoration with Generative Facial Prior
  3. paper: Exploiting Deep Generative Prior for Versatile Image Restoration and Manipulation
  4. https://zhuanlan.zhihu.com/p/270932356
  5. https://arc.tencent.com/zh/ai-demos/faceRestoration
  6. https://zhuanlan.zhihu.com/p/609795548