CVPR2021-Encoding in Style: a StyleGAN Encoder for Image-to-Image Translation风格编码:用于图像到图像转换

Encoding in Style: a StyleGAN Encoder for Image-to-Image Translation风格编码:用于图像到图像转换的StyleGAN编码器

论文下载
代码下载

0.摘要

我们提出了一个通用的图像到图像的转换框架pixel2style2pixel (pSp)。我们的pSp框架是基于一种新的编码器网络,它直接生成一系列的风格向量,这些向量被送入一个预先训练的StyleGAN生成器,形成扩展的W+潜在空间。我们首先展示了我们的编码器可以直接嵌入真实的图像到W+,没有额外的优化。接下来,我们提出利用我们的编码器直接解决图像到图像的翻译任务,将其定义为从某个输入域到潜在域的编码问题。通过偏离以前StyleGAN编码器使用的标准“先反转,后编辑”方法,我们的方法可以处理各种任务,即使输入图像没有在StyleGAN域中表示。我们表明,通过StyleGAN解决翻译任务显著简化了训练过程,因为不需要对手,对解决没有像素到像素对应的任务有更好的支持,并通过样式的重采样内在地支持多模态合成。最后,我们展示了我们的框架在各种面部图像到图像翻译任务的潜力,甚至当与最先进的解决方案,专门为一个任务设计,进一步表明它可以扩展超越人类的面部领域。

1.概述

近年来,生成性对抗网络(GAN)显著提高了图像合成,尤其是人脸图像的合成。最先进的图像生成方法已经实现了较高的视觉质量和逼真度,现在可以生成具有惊人真实感的图像。最值得注意的是,StyleGAN[20,21]提出了一种新颖的基于样式的生成器架构,并在高分辨率图像上实现了最先进的视觉质量。此外,已经证明它有一个分离的潜在空间W[39,7,35],提供控制和编辑功能。
最近,许多方法已经显示出控制StyleGAN的潜在空间和在W[17, 35, 36, 13]中执行有意义的操作的能力。这些方法遵循“先反转,后编辑”的方法,首先将图像反转到StyleGAN的潜在空间中,然后以一种语义上有意义的方式编辑潜在代码,以获得一个新代码,然后StyleGAN使用该代码生成输出图像。然而,已有研究表明,将实景图像反演为512维向量w∈w并不能得到准确的重建。受此启发,将真实图像编码到一个扩展的潜在空间W+中已成为一种常见的做法[1,2,4,42,3],该空间由18个不同的512维W向量拼接而成,每个对应StyleGAN的输入层。这些工作通常诉诸于使用W+的逐幅图像优化,需要几分钟的单个图像。为了加速这一优化过程,一些方法[4,42]训练编码器在W+中推断出一个近似向量,作为需要进行额外优化的良好初始点。然而,快速准确地将真实图像反演为W+仍然是一个挑战
在本文中,我们首先介绍了一种新的编码器结构,它可以将任意图像直接编码到W+中。编码器基于特征金字塔网络[24],其中风格向量从不同的金字塔尺度中提取,并直接插入到固定的、预先训练的StyleGAN生成器,以对应其空间尺度。我们展示了我们的编码器可以直接重建真实的输入图像,允许一个人执行潜在的空间操作,而不需要耗时的优化。虽然这些操作允许对真实图像进行广泛的编辑,但它们本质上是有限的。这是因为输入图像必须是可逆的,即必须存在重建图像的潜在代码。对于一些任务,例如有条件的图像生成,这个需求是一个严重的限制,在这些任务中,输入图像不在同一个StyleGAN域中。为了克服这一限制,我们建议将编码器与预训练的StyleGAN生成器一起使用,作为一个完整的图像到图像的转换框架。在这个公式中,输入图像直接编码到所需的输出潜在区,然后将这些潜在区输入StyleGAN以生成所需的输出图像。这允许使用StyleGAN进行图像到图像的转换,即使输入和输出图像来自不同的域。
虽然以前解决图像到图像转换任务的许多方法都涉及专门解决单个问题的专用架构,但我们遵循pix2pix[16]的精神,定义了一个能够解决广泛任务的通用框架,所有这些都使用相同的架构。除了简化训练过程(因为不需要训练对手鉴别器)之外,使用预先训练过的StyleGAN生成器比以前的工作提供了几个有趣的优点。例如,许多图像到图像架构显式地向生成器提供来自编码器的残差特征映射[16,38],从而产生强局部性偏差[33]。相反,我们的生成器只受样式控制,没有直接的空间输入。中间样式表示的另一个显著优势是对多模态合成的固有支持,用于模糊任务,如从草图、分割地图或低分辨率图像生成图像。在这样的任务中,生成的样式可以重新采样,以创建输出图像的变化,而不改变架构或训练过程。从某种意义上说,我们的方法执行了pixel2style2pixel转换,因为每个图像都首先被编码为样式向量,然后再编码为一张图像,因此被称为pSp
本文的主要贡献是:

  • 一种新的StyleGAN编码器,能够直接将真实图像编码到W+潜在域;以及
  • 用于利用预训练的StyleGAN生成器解决图像到图像转换任务的新方法。

2.相关工作

2.1.GAN反演

随着GANs的迅速发展,许多作品试图理解和控制它们的潜在空间。一项受到广泛关注的具体任务是GAN反演,即寻找预训练GAN最准确地重建给定已知图像的潜在向量。受其最先进的图像质量和潜在空间语义丰富性的启发,许多近期作品都使用StyleGAN[20,21]来完成这项任务。通常,反演方法要么直接优化潜在向量,以最小化给定图像的误差[25,8,1,2],训练编码器将给定图像映射到潜在空间[31,8,32,12,29],要么使用混合方法将两者结合起来[4,42]。通常,执行优化的方法在重建质量上优于学习的编码器映射,但需要更长的时间。与上述方法不同,我们的编码器可以准确有效地将给定的人脸图像嵌入扩展的潜在空间W+,而无需进一步优化。

2.2.潜在的空间操作

近年来,许多论文提出了各种学习潜在码语义编辑的方法。一种流行的方法是找到对应于给定二进制↔old属性变化的线性方向,如young↔old,或no-smile↔smile[35, 11, 10, 3]。Tewari等人[36]利用预先训练的3DMM在潜在空间学习语义人脸编辑。Jahanian等人[17]以自我监督的方式找到对应于特定变换的潜在空间路径,如缩放或旋转。Härkönen等[13]通过使用中间激活空间的主成分轴以无监督的方式找到有用的路径。Collins等人[7]通过操纵潜在代码的相应组件来执行局部语义编辑。这些方法通常遵循“先反转,后编辑”的过程,即首先将图像嵌入潜在空间,然后以语义上有意义的方式编辑其潜在空间。这与我们的方法不同,我们的方法直接将输入图像编码为相应的输出潜伏,从而允许处理不驻留在StyleGAN域中的输入。

2.2.图像到图像

图像到图像的转换技术旨在学习将源域的输入图像映射到目标域的相应图像的条件图像生成函数。Isola等人[16]首先介绍了使用条件gan来解决各种图像到图像的转换任务。从那时起,他们的工作被扩展到许多场景:高分辨率合成[38]、无监督学习[27,43,22,26]、多模态图像合成[44,14,6]和条件图像合成[30,23,28,45,5]。上述工作已经构建了专用的架构,需要对生成器网络进行培训,通常不能推广到其他翻译任务。这与我们使用相同架构解决各种任务的方法形成对比。

3.PSP架构

在这里插入图片描述

图2。我们的pSp的架构。首先使用ResNet骨干上的标准特征金字塔提取特征映射。对于18个目标风格中的每一个,训练一个小的映射网络从对应的特征地图中提取学习到的风格,其中风格(0-2)从小的特征地图中生成,(3-6)从中等的特征地图中生成,(7-18)从最大的特征地图中生成。map2style的映射网络是一个小型的全卷积网络,它使用一组2步卷积,然后激活LeakyReLU,逐渐减小空间大小。每个生成的512个向量,被送入StyleGAN,从它的匹配仿射变换A开始。

我们的pSp框架建立在一个预先训练的StyleGAN生成器和W+潜在空间的代表性能力之上。为了利用这种表示,我们需要一个强大的编码器,它能够将每个输入图像匹配到潜伏域的精确编码。嵌入该领域的一个简单技术是使用从编码器网络的最后一层获得的单个512维向量直接将给定的输入图像编码到W+,从而一起学习所有18个风格向量。然而,这样的架构存在很强的瓶颈,难以充分表现出原始图像的细节,从而限制了重建质量。
在StyleGAN中,作者展示了不同的样式输入对应于不同的细节级别,这些级别大致分为三组——粗、中、细。根据上述观察,在pSp中,我们使用特征金字塔[24]扩展了编码器骨干,生成了三层特征映射,并使用一个简单的中间网络——map2style——从这些特征映射中提取样式,如图2所示。样式与层次化表示法对齐后,根据样式的大小输入生成器生成输出图像,通过中间样式表示法完成输入像素到输出像素的转换。完整的体系结构如图2所示。
与在StyleGAN中一样,我们进一步将w定义为预训练生成器的平均样式向量。给定一个输入图像x,我们的模型的输出被定义为
在这里插入图片描述
其中E(·)和G(·)分别表示编码器和StyleGAN生成器。在这个公式中,我们的编码器旨在学习相对于平均风格向量的潜在代码。我们发现这样可以得到更好的初始化。

3.1.损失函数

虽然基于风格的翻译是我们的框架的核心部分,但损失的选择也至关重要。我们的编码器使用多个目标的加权组合进行训练。首先,我们利用像素级的L2损耗,
在这里插入图片描述
此外,为了学习感知相似性,我们利用了LPIPS[40]损失,与更标准的感知损失[18]相比,它已被证明能更好地保存图像质量[12],式中F(·)为感知特征提取器。:
在这里插入图片描述
为了使编码器输出的潜在风格向量更接近于平均潜在向量,我们另外定义了以下正则化损失:
在这里插入图片描述
与StyleGAN中引入的截断技巧类似,我们发现在编码器的训练中添加这种正则化可以提高图像质量,而不会损害输出的保真度,特别是在下面探讨的一些更模糊的任务中。
最后,在处理人脸图像编码的特定任务时,一个常见的挑战是保存输入标识。为了解决这个问题,我们加入了一个专门的识别损失测量输出图像和它的源图像之间的余弦相似度,其中R是预训练的ArcFace[9]网络
在这里插入图片描述
综上,总损失函数定义为
在这里插入图片描述
其中,λ1, λ2, λ3, λ4是定义损失权值的常数。与以前的作品相比,这组经过策划的损失函数允许更准确地编码到StyleGAN中,并且可以根据其性质轻松地针对不同的编码任务进行调整。常数和其他实现细节可以在补充材料中找到。

3.2.StyleGAN域的优点

在这里插入图片描述

图3。多模式生成的风格混合。

通过样式域进行图像之间的转换使pSp区别于许多标准的图像到图像的转换框架,因为它使我们的模型可以全局操作而不是局部操作,而不需要像素到像素的对应。这是一个理想的属性,因为已经表明,在处理非局部转换[33]时,局部偏差限制了当前方法。此外,之前的研究[20,7]表明,StyleGAN学习到的语义对象的解缠是由于它的分层表示。这种独立操作语义属性的能力导致了另一个期望的属性:对多模态合成的支持。由于一些翻译任务是模糊的,单个输入图像可能对应多个输出,因此能够对这些可能的输出进行采样是理想的。虽然这需要在标准的图像到图像架构中进行专门的改变[44,14],但我们的框架本身通过简单地采样样式向量来支持这一点。在实践中,这是通过随机抽样一个向量w∈R512并通过复制W在W+中生成相应的潜在代码。然后,通过将计算出的潜在代码的选择层替换为随机生成的潜在代码的选择层来执行样式混合,可能使用用于在两种样式之间混合的α参数。这种方法如图3所示

4.应用和细节

5.讨论

虽然我们建议的图像到图像翻译框架在各种应用中取得了令人信服的结果,但它有一些固有的假设,应该加以考虑。首先,利用预训练的StyleGAN生成的高质量图像是有成本的——该方法仅限于StyleGAN可以生成的图像。因此,如果在训练StyleGAN模型时没有此类示例,生成不靠近正面或具有特定表情的人脸可能会很有挑战性。此外,pSp的全局方法虽然对许多任务有利,但在保留输入图像的更精细细节(如耳环或背景细节)方面确实带来了挑战。这在修复或超分辨率任务中尤其重要,因为标准的图像到图像架构可以简单地传播局部信息。图11给出了重建失败的一些例子。

6.总结

在这项工作中,我们提出了一种新的编码器架构,可以直接将真实图像映射到W+潜在空间,而无需优化。在那里,样式以分层方式提取,并输入固定样式生成器的相应输入。结合我们的编码器和StyleGAN解码器,我们提出了一个通用框架,用于解决各种图像到图像的翻译任务,所有这些任务都使用相同的体系结构。值得注意的是,与之前StyleGAN编码器的“先反转,后编辑”方法不同,我们表明pSp可以用于直接将这些翻译任务编码为StyleGAN,从而支持不在StyleGAN域中的输入图像。此外,与以往通常依赖专用体系结构来解决单个翻译任务的工作不同,我们展示了pSp能够解决各种各样的问题,只需要对训练损失和方法进行最小的更改。我们希望,我们的方法的易用性将鼓励进一步研究如何将StyleGAN用于真正的图像到图像的翻译任务

参考文献

[1] Rameen Abdal, Yipeng Qin, and Peter Wonka. Image2stylegan: How to embed images into the stylegan latent space? In Proceedings of the IEEE international conference on computer vision, pages 4432–4441, 2019.
[2] Rameen Abdal, Yipeng Qin, and Peter Wonka. Image2stylegan++: How to edit the embedded images? In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 8296–8305, 2020.
[3] Rameen Adbal, Pie Zhu, Niloy J. Mitra, and Peter Wonka. Styleflow: Attribute-conditioned exploration of stylegangenerated images using conditional continuous normalizing flows. arXiv preprint arXiv:, 2020.
[4] Baylies. stylegan-encoder. https://github.com/ pbaylies / stylegan - encoder, 2019. Accessed: April 2020.
[5] Shu-Y u Chen, Wanchao Su, Lin Gao, Shihong Xia, and Hongbo Fu. DeepFaceDrawing: Deep generation of face images from sketches. ACM Transactions on Graphics (Proceedings of ACM SIGGRAPH 2020), 39(4):72:1–72:16, 2020.
[6] Y unjey Choi, Y oungjung Uh, Jaejun Y oo, and Jung-Woo Ha. Stargan v2: Diverse image synthesis for multiple domains. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 8188–8197, 2020.
[7] Edo Collins, Raja Bala, Bob Price, and Sabine Susstrunk. Editing in style: Uncovering the local semantics of gans. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 5771–5780, 2020.
[8] Antonia Creswell and Anil Anthony Bharath. Inverting the generator of a generative adversarial network. IEEE transactions on neural networks and learning systems, 30(7):1967– 1974, 2018.
[9] Jiankang Deng, Jia Guo, Niannan Xue, and Stefanos Zafeiriou. Arcface: Additive angular margin loss for deep face recognition. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pages 4690– 4699, 2019.
[10] Emily Denton, Ben Hutchinson, Margaret Mitchell, and Timnit Gebru. Detecting bias with generative counterfactual face attribute augmentation. arXiv preprint arXiv:1906.06439, 2019.
[11] Lore Goetschalckx, Alex Andonian, Aude Oliva, and Phillip Isola. Ganalyze: Toward visual definitions of cognitive image properties, 2019.
[12] Shanyan Guan, Ying Tai, Bingbing Ni, Feida Zhu, Feiyue Huang, and Xiaokang Yang. Collaborative learning for faster stylegan embedding. arXiv preprint arXiv:2007.01758, 2020.
[13] Erik Härkönen, Aaron Hertzmann, Jaakko Lehtinen, and Sylvain Paris. Ganspace: Discovering interpretable gan controls. arXiv preprint arXiv:2004.02546, 2020.
[14] Xun Huang, Ming-Y u Liu, Serge Belongie, and Jan Kautz. Multimodal unsupervised image-to-image translation. In Proceedings of the European Conference on Computer Vision (ECCV), pages 172–189, 2018.
[15] Y uge Huang, Y uhan Wang, Ying Tai, Xiaoming Liu, Pengcheng Shen, Shaoxin Li, Jilin Li, and Feiyue Huang. Curricularface: adaptive curriculum learning loss for deep face recognition. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 5901–5910, 2020.
[16] Phillip Isola, Jun-Y an Zhu, Tinghui Zhou, and Alexei A Efros. Image-to-image translation with conditional adversarial networks. In Proceedings of the IEEE conference on computer vision and pattern recognition, pages 1125–1134, 2017.
[17] Ali Jahanian, Lucy Chai, and Phillip Isola. On the ”steerability” of generative adversarial networks. arXiv preprint arXiv:1907.07171, 2019.
[18] Justin Johnson, Alexandre Alahi, and Li Fei-Fei. Perceptual losses for real-time style transfer and super-resolution. In European conference on computer vision, pages 694–711. Springer, 2016.
[19] Tero Karras, Miika Aittala, Janne Hellsten, Samuli Laine, Jaakko Lehtinen, and Timo Aila. Training generative adversarial networks with limited data. In Proc. NeurIPS, 2020.
[20] Tero Karras, Samuli Laine, and Timo Aila. A style-based generator architecture for generative adversarial networks. In Proceedings of the IEEE conference on computer vision and pattern recognition, pages 4401–4410, 2019.
[21] Tero Karras, Samuli Laine, Miika Aittala, Janne Hellsten, Jaakko Lehtinen, and Timo Aila. Analyzing and improving the image quality of stylegan. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 8110–8119, 2020.
[22] Oren Katzir, Dani Lischinski, and Daniel Cohen-Or. Crossdomain cascaded deep feature translation. arXiv, pages arXiv–1906, 2019.
[23] Y uhang Li, Xuejin Chen, Feng Wu, and Zheng-Jun Zha. Linestofacephoto: Face photo generation from lines with conditional self-attention generative adversarial networks. In Proceedings of the 27th ACM International Conference on Multimedia, pages 2323–2331, 2019.
[24] Tsung-Yi Lin, Piotr Dollár, Ross Girshick, Kaiming He, Bharath Hariharan, and Serge Belongie. Feature pyramid networks for object detection. In Proceedings of the IEEE conference on computer vision and pattern recognition, pages 2117–2125, 2017.
[25] Zachary C Lipton and Subarna Tripathi. Precise recovery of latent vectors from generative adversarial networks. arXiv preprint arXiv:1702.04782, 2017.
[26] Wallace Lira, Johannes Merz, Daniel Ritchie, Daniel CohenOr, and Hao Zhang. Ganhopper: Multi-hop gan for unsupervised image-to-image translation. arXiv preprint arXiv:2002.10102, 2020.
[27] Ming-Y u Liu, Thomas Breuel, and Jan Kautz. Unsupervised image-to-image translation networks. In Advances in neural information processing systems, pages 700–708, 2017.
[28] Xihui Liu, Guojun Yin, Jing Shao, Xiaogang Wang, et al. Learning to predict layout-to-image conditional convolutions for semantic image synthesis. In Advances in Neural Information Processing Systems, pages 570–580, 2019.
[29] Y otam Nitzan, Amit Bermano, Y angyan Li, and Daniel Cohen-Or. Disentangling in latent space by harnessing a pretrained generator. arXiv preprint arXiv:2005.07728, 2020.
[30] Taesung Park, Ming-Y u Liu, Ting-Chun Wang, and Jun-Y an Zhu. Semantic image synthesis with spatially-adaptive normalization. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pages 2337–2346, 2019.
[31] Guim Perarnau, Joost V an De Weijer, Bogdan Raducanu, and Jose M Álvarez. Invertible conditional gans for image editing. arXiv preprint arXiv:1611.06355, 2016.
[32] Stanislav Pidhorskyi, Donald A Adjeroh, and Gianfranco Doretto. Adversarial latent autoencoders. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 14104–14113, 2020.
[33] Eitan Richardson and Y air Weiss. The surprising effectiveness of linear unsupervised image-to-image translation. ArXiv, abs/2007.12568, 2020.
[34] Esther Robb, Wen-Sheng Chu, Abhishek Kumar, and JiaBin Huang. Few-shot adaptation of generative adversarial networks. arXiv, 2020.
[35] Y ujun Shen, Jinjin Gu, Xiaoou Tang, and Bolei Zhou. Interpreting the latent space of gans for semantic face editing. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 9243–9252, 2020.
[36] Ayush Tewari, Mohamed Elgharib, Gaurav Bharaj, Florian Bernard, Hans-Peter Seidel, Patrick Pérez, Michael Zollhöfer, and Christian Theobalt. Stylerig: Rigging stylegan for 3d control over portrait images. arXiv preprint arXiv:2004.00121, 2020.
[37] Carlos Eduardo Thomaz and Gilson Antonio Giraldi. A new ranking method for principal components analysis and its application to face image analysis. Image and Vision Computing, 28(6):902 – 913, 2010.
[38] Ting-Chun Wang, Ming-Y u Liu, Jun-Y an Zhu, Andrew Tao, Jan Kautz, and Bryan Catanzaro. High-resolution image synthesis and semantic manipulation with conditional gans. In Proceedings of the IEEE conference on computer vision and pattern recognition, pages 8798–8807, 2018.
[39] Ceyuan Y ang, Y ujun Shen, and Bolei Zhou. Semantic hierarchy emerges in deep generative representations for scene synthesis, 2019.
[40] Richard Zhang, Phillip Isola, Alexei A Efros, Eli Shechtman, and Oliver Wang. The unreasonable effectiveness of deep features as a perceptual metric. In Proceedings of the IEEE conference on computer vision and pattern recognition, pages 586–595, 2018.
[41] Hang Zhou, Jihao Liu, Ziwei Liu, Y u Liu, and Xiaogang Wang. Rotate-and-render: Unsupervised photorealistic face rotation from single-view images. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 5911–5920, 2020.
[42] Jiapeng Zhu, Y ujun Shen, Deli Zhao, and Bolei Zhou. Indomain gan inversion for real image editing. arXiv preprint arXiv:2004.00049, 2020.
[43] Jun-Y an Zhu, Taesung Park, Phillip Isola, and Alexei A Efros. Unpaired image-to-image translation using cycleconsistent adversarial networks. In Proceedings of the IEEE international conference on computer vision, pages 2223– 2232, 2017.
[44] Jun-Y an Zhu, Richard Zhang, Deepak Pathak, Trevor Darrell, Alexei A Efros, Oliver Wang, and Eli Shechtman. Toward multimodal image-to-image translation. In Advances in neural information processing systems, pages 465–476, 2017.
[45] Peihao Zhu, Rameen Abdal, Yipeng Qin, and Peter Wonka. Sean: Image synthesis with semantic region-adaptive normalization. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 5104– 5113, 2020.

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值