\abstract{
In this research work we present \glass, a novel zero-shot framework to generate an image (or a caption) corresponding to a given caption (or image). \glass is based on the CLIP neural network, which, given an image and a descriptive caption, provides similar embeddings. Differently, \glass takes a caption (or an image) as an input, and generates the image (or the caption) whose CLIP embedding is the most similar to the input one. This optimal image (or caption) is produced via a generative network, after an exploration by a genetic algorithm. Promising results are shown, based on the experimentation of the image Generators BigGAN and StyleGAN2, and of the text Generator GPT2.
}
在这项研究工作中,我们提出了\glass,一个新颖的零镜头框架来生成一个对应于给定的标题(或图像)的图像(或标题)。\glass是基于CLIP神经网络,它给出了一个图像和一个描述性的标题,提供了类似的嵌入。不同的是,\glass将标题(或图像)作为输入,并生成其CLIP嵌入与输入最相似的图像(或标题)。这个最优的图像(或标题)是通过生成网络,在探索遗传算法后产生的。在对图像生成器BigGAN和StyleGAN2以及文本生成器GPT2进行实验的基础上,给出了较为理想的结果。
\section{\uppercase{Introduction and background}}
In the last years, Generative Neural Networks showed promising results in a wide range of fields. The state of the art in the field of image generation is represented by Generative Adversarial Networks (GANs) \cite{gan}. GANs are capable of generating realistic synthetic images leveraging two competing neural networks: a Generator and a Discriminator. The objective of the Generator is to generate images capable of fooling the Discriminator. The objective of the Discriminator is to distinguish between images generated by the Generator and the original ones.
在过去的几年里,生成神经网络在许多领域显示出了有前景的结果。图像生成领域的最新技术是由生成式对抗网络(GANs)表示的。GANs能够利用两个相互竞争的神经网络生成真实的合成图像:一个生成器和一个鉴别器。生成器的目标是生成能够愚弄鉴别器的图像。鉴别器的目的是区分由生成器生成的图像和原始图像。
In the field of Natural Language Processing (NLP), unprecedented results have been achieved by transformers architectures \cite{attentionsurvey}. One of the most known and studied transformer is the Generative Pre-trained Transformer 2 (GPT2) \cite{gpt2}. GPT-2 has 1.5 billion parameters and was trained on a language modelling task on the texts of 8 millions of web pages.
在自然语言处理(NLP)领域,变压器体系结构已经取得了前所未有的成果。其中最著名和研究的变压器是生成预训练变压器2 (GPT2) \引用{GPT2}。GPT-2拥有15亿个参数,并被训练在800万个网页文本上进行语言建模。
Generating images from a descriptive caption has always been a challenging problem. In the last years, some architectures like StackGAN++ \cite{stackgan++} and AlignDRAW \cite{attention_captions} showed promising results in this field, although being limited to the visual and textual domains of the training dataset.
从描述性的标题生成图像一直是一个具有挑战性的问题。在过去的几年里,一些架构,如StackGAN++ \cite{StackGAN++}和AlignDRAW \cite{attention_caption}在这个领域显示了很有前途的结果,尽管被限制在视觉和文本的训练数据集领域。
Very recently (January 2021), a novel deep network which learns visual concepts from natural language supervision has been released by OpenAI. CLIP (Contrastive Language–Image Pre-training) \cite{CLIP} consists of two encoders: one for images and another for texts. CLIP encoders are capable of producing similar embeddings for images and texts representing similar concepts. CLIP can be applied to visual classification tasks without training: to distinguish the object X from Y in an images dataset, it is sufficient for each image to check whether the text description “a photo of X” or “a photo of Y” is more likely to be paired with it.
最近(2021年1月),OpenAI发布了一个新颖的深度网络,可以从自然语言监督中学习视觉概念。CLIP(对比语言-图像预训练)\引用{CLIP}包含两个编码器:一个用于图像,另一个用于文本。CLIP编码器能够为表示类似概念的图像和文本产生类似的嵌入。剪辑可以应用于视觉分类任务没有培训:区分对象X和Y的图像数据集,它是足以让每个图像检查文本描述是否“X”的照片或“Y”的照片更容易搭配。
In this paper, we propose a framework based on CLIP to generate (i.e., to build without a supporting database) the best image corresponding to a target caption. The proposed framework can also be used to generate a caption corresponding to a given image. More specifically, the framework takes a caption (or an image) as an input, and generates the image (or the caption) whose CLIP embedding is most similar to the input one. This optimal image (or text) is produced via a generative network after an exploration by a genetic algorithm. Early experimentation of the proposed CLIP-guided Generative Latent Space Search (\glass) has been carried out, on the basis of the image Generators BigGAN and StyleGAN2, and of the text Generator GPT2, for the text-to-image and image-to-text tasks, respectively.
在本文中,我们提出了一个基于CLIP的框架来生成(即在没有支持数据库的情况下构建)与目标标题相对应的最佳图像。提出的框架也可以用来生成对应于给定图像的标题。更具体地说,框架将标题(或图像)作为输入,并生成其CLIP嵌入与输入图像最相似的图像(或标题)。这个最优的图像(或文本)是通过遗传算法探索后生成网络产生的。在图像生成器BigGAN和StyleGAN2以及文本生成器GPT2的基础上,针对文本到图像和图像到文本的任务,提出了基于CLIP引导的生成潜在空间搜索(\glass)的早期实验。
The paper is structured as follows. Section 2 focuses on the Design of the \glass framework. Experimental studies are covered by Section 3. Conclusions are drawn in Section 4. The source code of \glass has been publicly released.
本文的结构如下。第二节重点介绍玻璃框架的设计。第3节介绍了实验研究。在第4节中得出结论。\glass的源代码已经公开发布。
\section{DESIGN OF THE \glass FRAMEWORK}
The main components of the \glass framework are: (i) the CLIP network for producing image and text embedding, (ii) an Image or Text Generator for generating a text/image output with a similar embedding, (iii) a Genetic Algorithm to explore the latent space of the Generator for finding the most similar embedding between image and text. In the case of the text-to-image task, the Image Generator is based on domain-specific or mixed-domains Generative Adversarial Networks, such as DeepMind’s BigGAN and Nvidia’s StyleGAN2, respectively. In the case of the image-to-text task, the Generative Pre-trained Transformer 2 (GPT2) has been used. Finally, as a Genetic Algorithm, the NSGA-II \cite{nsga2} has been employed, in order to solve a multi objective optimization problem. A classical Genetic Algorithm can be employed when solving one single objective optimization. The advantage of the Genetic Algorithm is that it is independent from the type of generative architecture, and it is characterized by a high degree of exploration. Since the genetic algorithm is considered well-known, the next subsections detail the first two components.
*玻璃框架的主要组成部分是:(i)CLIP生产网络嵌入图像和文本,(2)一个图像或文本生成器,用于生成一个文本/图像输出与类似的嵌入,(3)遗传算法探索生成器的潜在空间寻找最相似的图像和文本之间的嵌入。在文本到图像的任务中,图像生成器基于特定领域或混合领域的生成对抗网络,例如DeepMind的BigGAN和英伟达的StyleGAN2。在图像到文本任务的情况下,使用了生成式预训练Transformer 2 (GPT2)。最后,作为一种遗传算法,采用NSGA-II引用{nsga2}来解决一个多目标优化问题。在求解单目标优化问题时,可以采用经典的遗传算法。遗传算法的优点是它独立于生成式建筑的类型,具有较高的探索性。由于遗传算法被认为是众所周知的,下面的子部分详细介绍前两个部分。
NSGA-II see *https://www.zhihu.com/question/26990498
\subsection{The CLIP network}
CLIP is composed by two Neural Networks: an Image Encoder (IE) and a Text Encoder (TE). The two encoders produce similar embeddings if the image and the text contains similar visual and textual concepts. CLIP was trained using images and related snipped of texts scraped from the internet, to perform a contrastive learning task. Contrastive learning consists in training a model to predict the correct similarity between data samples. CLIP was inspired by some prior work: in 2013 Richer Socher \textit{et al.} trained a model to map images in feature vectors close to semantic word vectors corresponding to their class. The model shown some zero-shot capabilities \cite{socher2013zero}. Later, in 2017, Ang Li \textit{et al.} trained a model using images scraped form the internet and related user comments to predict the corresponding comments word n-gram given an image. The resulting model was able to achieve a zero-shot 11.5\% accuracy on ImageNet \cite{li2017learning}.
CLIP由两个神经网络组成:一个图像编码器(IE)和一个文本编码器(TE)。如果图像和文本包含类似的视觉和文本概念,则两个编码器产生类似的嵌入。CLIP使用从互联网上搜集来的图片和相关文本片段进行训练,以执行一项对比学习任务。对比学习包括训练模型来预测数据样本之间的正确相似性。CLIP的灵感来自于之前的一些工作:2013年,Richer Socher \textit{et al.}训练了一个模型来映射图像的特征向量,这些特征向量接近于对应于它们类的语义词向量。该模型显示了一些零射击能力,引用{socher20130zero}。后来,在2017年,Ang Li \textit{et al.}训练了一个模型,利用从互联网上抓取的图像和相关的用户评论来预测给定图像对应的评论词n-gram。得到的模型能够在ImageNet引用{li2017learning}上实现11.5 %的零精度。
Because of the wide range of visual concepts learned from natural language via contrastive learning, CLIP shows great zero-shot capabilities. CLIP’s zero-shot performances were tested on over 30 different tasks spanning from OCR to geo-localization. The model showed competitive results against fully supervised baselines. CLIP was able to match the accuracy of the original ResNet-50 classifier on ImageNet in zero-shot without seeing any of the 1.28 million training images.
由于通过对比学习从自然语言中学习的视觉概念的范围很广,CLIP显示了出色的零镜头能力。CLIP的零射击性能在超过30种不同的任务中进行了测试,从OCR到地理定位。与完全监督的基线相比,该模型显示出了具有竞争力的结果。CLIP能够在没有看到128万张训练图像的情况下,在零镜头下匹配ImageNet上原始ResNet-50分类器的准确性。
\subsection{Design of the Text-to-Image task}
Figure \ref{fig:txt2img} shows the architectural design of the \glass framework for the text-to-image task. Here, the CLIP text/image embeddings are represented in light/dark blue, respectively. The similarity $s$ of their output is sent to the Genetic Algorithm (the green box on the top) for being maximized. The Genetic Algorithms controls the input $z$ of the image Generator, whose components are represented in orange. The image Generator is based on a Generative Adversarial Network (GAN). To clearly understand the overall behavior of the framework, the GAN is first introduced in the following.
图/参考{fig:txt2img}显示了用于文本到图像任务的玻璃框架的建筑设计。在这里,CLIP文本/图像嵌入分别用浅蓝色/深蓝色表示。它们输出的相似度$s$被发送到遗传算法(顶部的绿色框)以获得最大化。遗传算法控制图像生成器的输入$z$,其组件用橙色表示。图像生成器是基于生成式对抗网络(GAN)的。为了清楚地理解框架的总体行为,下面首先介绍GAN。

这里有一个没注意到的细节,这是一个多目标优化问题,使用遗传算法给出pareto解,两个目标,一是语义距离近,二是判别器损失小(语义相似度高不代表图片质量高)
The Generative Adversarial Neural Network is a framework proposed in 2014 \cite{gan}, and consists in two competing neural networks: a $Generator$ and a $Discriminator$. The Generator produces candidates while the Discriminator evaluates them. The Generator learns to map from an seeding space called \textit{latent space} ($z$), to the data space of interest, while the Discriminator distinguishes candidates produced by the Generator ($d{img}$) from the real data ($R$). In Figure~\ref{fig:txt2img}, the output of the Discriminator is evaluated in terms of loss ($l$) to be minimized. During the training, the Generator objective is to increase the error rate of the Discriminator, by producing novel candidates that the Discriminator classifies as real. For this purpose, it is seeded with randomized input that is sampled from a predefined latent space (noise distribution $p_z$).
生成式对抗神经网络是在2014年(引用{gan})提出的一个框架,由两个相互竞争的神经网络组成:$Generator$和$Discriminator$。生成器生成候选对象,而鉴别器评估候选对象。生成器学习从名为\textit{latent space} ($z$)的种子空间映射到感兴趣的数据空间,而Discriminator将生成器生成的候选数据($d{img}$)与实际数据($R$)区分开来。在图~\ref{fig:txt2img}中,Discriminator的输出是根据要最小化的损失($l$)来计算的。在训练过程中,Generator的目标是通过产生新的候选对象来增加Discriminator的错误率,而Discriminator将这些候选对象分类为真实的。为此目的,它是用从预定义的潜在空间(噪声分布$p_z$)采样的随机输入来播种的。
Independent backpropagation procedures are applied to both networks, to allow the Generator to produce better images, while the Discriminator becomes more skilled at distinguishing synthetic images. For this purpose, Generator and Discriminator are simultaneously trained to perform their respective task in a zero-sum game. The Generator and the Discriminator are typically transposed convolutional and convolutional neural networks, respectively. In the proposed architecture, pre-trained GANs have been used. Specifically, the Discriminator takes the image and provides a single scalar representing the probability that its input comes from the original data rather than from the Generator. More formally, let us assume that the Discriminator $D$ is trained to output $1$ if its input image is original, and $0$ if it is synthetically generated. Then, using the Cross Entropy loss the conjunct training objective function can be expressed as:
两个网络都应用了独立的反向传播程序,以允许生成器产生更好的图像,而鉴别器在区分合成图像方面变得更熟练。为此,Generator和Discriminator同时被训练在零和博弈中执行各自的任务。生成器和鉴别器通常分别是转置卷积和卷积神经网络。在建议的体系结构中,使用了经过训练的GANs。具体来说,Discriminator获取图像并提供一个标量,表示其输入来自原始数据而不是来自Generator的概率。更正式地说,我们假设识别器$D$经过训练,如果其输入图像是原始的,则输出$1$,如果是综合生成的,则输出$0$。那么,利用交叉熵损失,联合训练目标函数可以表示为:


At the end of the training process, the Generator is able to generate data indistinguishable (by the Discriminator) from the data originally provided. It has been shown that the resulting Generator is also able to give semantically significant interpolations in the domain of the training data \cite{gansurvey}.
Figure \ref{fig:txt2img} focuses on the search carried out by the Genetic Algorithm, over pre-trained networks. Overall, the Generator is seeded by $z$ (according to a noise distribution $pz$) and provides a related image to both the Discriminator and the CLIP image encoding ($CLIP{IE}$). The latter is compared with the CLIP text encoding ($CLIP{TE}$) of the target text, via a similarity function $Sim$. As a similarity function, the cosine similarity has been used according to \cite{CLIP}. One objective for the Genetic Algorithm is to provide the best $z$ to maximize this similarity. More formally, given the target text $T$, the optimization problem is:
在训练过程的最后,Generator能够生成(由Discriminator)与最初提供的数据无法区分的数据。已经证明,生成的生成器也能够在训练数据的领域给出语义上有意义的插值\引用{gansurvey}。
图\参考{图:txt2img}集中于通过遗传算法在预先训练的网络上进行的搜索。总的来说,生成器被$z$(根据噪声分布$p_z$)作为种子,并为Discriminator和CLIP图像编码($CLIP{IE}$)提供一个相关的图像。后者通过相似度函数$Sim$与目标文本的CLIP文本编码($CLIP_{TE}$)进行比较。余弦相似度是根据\引用{CLIP}使用的相似度函数。遗传算法的一个目标是提供最佳的$z$来最大化这种相似性。更正式地说,给定目标文本$T$,优化问题是:

The second objective of the Genetic Algorithm is the classification loss $l$ of the Discriminator, which is calculated from the encoding $d{img}$ provided by the image of the Generator, and the value associated to the output of a real image ($R$). More formally, the optimization problem is:
遗传算法的第二个目标是鉴别器的分类损失$l$,它是由生成器的图像提供的编码$d{img}$和与真实图像的输出相关的值($R$)计算出来的。更正式地说,优化问题是: 
After solving the optimization problem, the resulting optimal image provided by the Generator is $img{opt}$.\
It is worth to notice that if using a generative architecture without Discriminator, the second objective is missing. As a consequence, the optimization problem is single-objective, since it considers only the CLIP embeddings similarity.
在解决了优化问题后,由生成器提供的最优图像是$img{opt}$.\
值得注意的是,如果使用生成架构而不使用Discriminator,第二个目标就会丢失。因此,该优化问题是单目标的,因为它只考虑了CLIP嵌入的相似性。
\subsection{Design of the Image-to-Text task}
Figure \ref{fig:img2txt} shows the architectural design of the \glass framework for the image-to-text task. Similarly to the text-to-image task, the CLIP image/text embeddings are represented in dark/light blue, respectively. The similarity $s$ of their output is sent to the Genetic Algorithm for being maximized. The Genetic Algorithms controls the seed $z$ of the text Generator, represented in orange. The state of the art for text generators is based on transformers, such as XLNet \cite{xlnet}, Conditional Transformer Language Model (CTRL)\cite{ctrl} and Generative Pre-trained Transformer-2 (GPT2)\cite{gpt2}. As an example, in this paper the GPT2 has been used.
图/参考{fig:img2txt}显示了用于图像到文本任务的\玻璃框架的建筑设计。与文本到图像的任务类似,CLIP图像/文本嵌入分别用深蓝/浅蓝色表示。将它们输出的相似度$s$发送给遗传算法求最大。遗传算法控制文本生成器的种子$z$,用橙色表示。当前最先进的文本生成器是基于变压器的,比如XLNet {XLNet}、条件变压器语言模型(CTRL) {CTRL}和生成式预训练变压器2 (GPT2) {GPT2}。本文以GPT2为例。

这里没有使用判别器,实际上还是可以采用topk采样等方法,求解语言概率最大和CLIP相似度最大两个目标
More specifically, GPT2 is a transformer model developed by OpenAI as improved version of the Generative Pre-trained Transformer (GPT). The transformer architecture was introduced in 2017, and it is used mainly for solving NLP tasks. Although transformers are built to work with temporal data (like Recurrent Neural Networks or Long Short Term Memory Neural Networks), they do not require that temporal data are sequentially processed. Hence, transformers allow a fast large scale parallel training.
更具体地说,GPT2是OpenAI开发的变压器模型,作为生成式预训练变压器(GPT)的改进版本。变压器架构于2017年引入,主要用于解决NLP任务。虽然变压器是用来处理时间数据的(像循环神经网络或长短期记忆神经网络),但它们不需要顺序处理时间数据。因此,变压器允许快速大规模的并行训练。
Transformers are composed by a stack of encoders and decoders, and heavily rely on a mechanism called \textit{attention}, which is able to highlight important information while discarding the non-important one. The training data for GPT2 was scraped from the internet using a custom web scraper that emphasizes document quality using some meta-heuristics. The resulting dataset contains text from over 45 million links and consists in almost 40 GB of text. GPT2 was trained using a Model-Agnostic Meta-Learning (MAML) method \cite{maml}, and tested with zero-shot approach on a variety of tasks: text generation, translation, summarization, question answering, etc. It was able to match and even surpass the state-of-the-art of fully supervised models in zero-shot.
转换器由一堆编码器和解码器组成,严重依赖于一种名为\textit{attention}的机制,该机制能够在突出显示重要信息的同时丢弃不重要的信息。GPT2的训练数据是使用自定义web刮板从互联网上收集的,该刮板使用一些元启发式方法强调文档质量。结果数据集包含超过4500万链接的文本,包含近40gb的文本。GPT2是使用模型不可知论元学习(MAML)方法进行训练的\引用{MAML},并在各种任务中使用零镜头方法进行测试:文本生成、翻译、摘要、问题回答等。它能够在零镜头下媲美甚至超过最先进的完全监督模型。
MAML扩展
MAML 学到的初始化参数和 pretrain 得到的参数肯定不同,因为 pretrain 只是保证了在一个 task 上 adapt 的很好,它并不关心如何 transfer 到其他 task 上,adaptivity 只是一个 by-product. MAML 是直接学习了 adaptation 这个 meta-task。
https://www.zhihu.com/question/357515885/answer/910589791
https://zhuanlan.zhihu.com/p/57864886
https://zhuanlan.zhihu.com/p/181709693
It is important to notice that GPT2 does not use a human-like alphabet, but an alphabet of tokens generated using the Byte Pair Encoding (BPE) \cite{bpe}. GPT2 can be used as generative architecture by setting context tokens, and using them to predict the next token, until the stop-sentence token predicted or a target text length is reached. We will refer to input context tokens as its \textit{latent space}.
需要注意的是,GPT2并不使用类人字母表,而是使用字节对编码(BPE) \引用{BPE}生成的标记字母表。GPT2可以作为生成架构使用,它设置上下文令牌,并使用它们预测下一个令牌,直到预测的停止句令牌或达到目标文本长度。我们将引用输入上下文标记作为它的\textit{latent space}。
In Figure \ref{fig:img2txt} the Generator is seeded by $z$, to provide an output text accordingly. The output text is used to fed the CLIP text encoder ($CLIP{TE}$). Finally, the similarity between the embedding of the ($CLIP{TE}$) and the embedding of the CLIP image embedding ($CLIP{IE}$) is computed. The optimization problem of the Genetic Algorithm is to maximize this similarity.\
After solving the optimization problem, the resulting optimal image generated from GPT2 is $text{opt}$.\
在Figure \ref{fig:img2txt}中,生成器以$z$作为种子,以提供相应的输出文本。输出文本用于提供CLIP文本编码器($CLIP{TE}$)。最后,计算($CLIP{TE}$)的嵌入与CLIP图像嵌入($CLIP{IE}$)的嵌入之间的相似度。遗传算法的优化问题就是使这种相似性最大化
在解决了优化问题后,由GPT2生成的最优图像是$text{opt}$.\
\section{\uppercase{Experimental studies}}
The \glass framework has been implemented and publicly released as an open source GitHub repository \cite{clip-glass-repo}, along with an in-browser demonstration. Experiments have been carried out on an Intel Core i9-9900K CPU, a GeForce RTX 2080 GPU. After the input image/caption, 500 generations are executed by the Genetic Algorithm to find the optimal caption/image. The order of magnitude of the processing time of an input is 5-10 minutes depending on the generative architecture used.
这个玻璃框架已经被实现并公开发布为一个开源的GitHub库,引用{clip-glass-repo},以及一个浏览器内的演示。实验在Intel Core i9-9900K CPU和GeForce RTX 2080 GPU上进行。输入图像/标题后,遗传算法执行500代,以找到最佳的标题/图像。输入处理时间的数量级是5-10分钟,这取决于所使用的生成架构。
过慢无法商用
In this section, some pilot experiments of \glass are considered, to show its generation capabilities. Each output is assessed in terms of $quality$, i.e. absence of artifacts, and $relevance$, i.e., the absence of unexpected elements, evaluated with the naked eye as low, medium, or high.
在本节中,考虑了一些\玻璃的初步实验,以显示其生成能力。每一个输出都是根据$quality$,即没有工件,和$relevance$,即没有意外元素来评估的,用肉眼评估为低、中或高。
\subsection{Examples of the Text-to-Image task}
Different state-of-the-art pre-trained networks have been used as Generator/Discriminator. In particular, two GANs have been used: DeepMind’s BigGAN \cite{biggan} and Nvidia’s StyleGAN2 \cite{stylegan2}.
The original BigGAN, trained on the ImageNet dataset, has been considered \cite{imagenet}. Three versions of StyleGAN2 have been used: (i) StyleGAN2-face, which is trained on Flickr-Faces-HQ \cite{ffhq}; (ii) StyleGAN2-church, trained on a subset of LSUN \cite{lsun} made of church buildings; (iii) StyleGAN2-car, trained on a subset of LSUN made of cars. \
OpenAI publicly released only BigGAN Generator. For this case, a single-objective genetic algorithm is used when optimizing its latent space. Differently, Nvidia released both StyleGAN Generator and Discriminator.\
The BigGAN latent space $z$ is composed by 1000 booleans representing the 1000 ImageNet classes, and by 128 real numbers meant to be sampled from a truncated normal distribution in the range $[-2,\;2]$. When optimizing its latent space, mixed genetic operators are employed to correctly perform the initialization, mutation and crossover operations.\
The StyleGAN2 latent space $z$ is made by 512 real numbers meant to be sampled from a normal distribution.\
Figure~\ref{fig:results_specific_StyleGAN2_ffhq_d} shows three representative examples of input caption and related output image generated via StyleGAN2-face. Since this GAN is specialized on faces, the overall result is very good: the quality and the relevance of all images are high, except for Image (b), whose relevance is medium due to the blonde hairs on the bottom.\
Figure~\ref{fig:results_specific_StyleGAN2_car_d} shows three representative examples of input caption and related output image generated via StyleGAN2-car. Although this GAN is specialized on cars, the quality of all images is medium, due to the presence of artifacts. The relevance is high for (a) and (b), but medium for (c) because the “intersection” is not visible.\
Figure~\ref{fig:results_specific_StyleGAN2_church_d} shows three representative examples of input caption and related output image generated via StyleGAN2-church. This GAN is specialized on images of church buildings. Indeed, the image relevance is high, and the quality is about high due to the presence of minor artifacts.\
The examples clearly show that \glass is able to combine the right image elements for matching the target caption, when using input texts that belong to the same domain of the generative network.
不同的最先进的预训练网络已被用作生成器/鉴别器。特别是,两个gan已经被使用:DeepMind的BigGAN \cite{BigGAN}和Nvidia的StyleGAN2 \cite{StyleGAN2}。
原始的BigGAN,在ImageNet数据集上训练,被认为是\引用{ImageNet}。已经使用了三个版本的StyleGAN2: (i) StyleGAN2-face,它是在Flickr-Faces-HQ上训练的,\引用{ffhq};(ii) StyleGAN2-church,训练于LSUN的一个子集,由教堂建筑组成;(iii) StyleGAN2-car,训练于由汽车组成的LSUN的一个子集。\ \
OpenAI只公开发布BigGAN生成器。在这种情况下,使用单目标遗传算法来优化其潜在空间。不同的是,Nvidia同时发布了StyleGAN Generator和Discriminator
BigGAN潜空间$z$由1000个布尔值组成,表示1000个ImageNet类,并由128个实数组成,这些实数是从截断的正态分布中采样的,范围为$[-2,\;2]$。在优化其潜空间时,采用混合遗传算子正确地进行初始化、变异和交叉操作
StyleGAN2的潜空间$z$是由512个实数组成的,这意味着从一个正态分布中采样
图~\ref{fig:results_specific_StyleGAN2_ffhq_d}显示了通过StyleGAN2-face生成的输入标题和相关输出图像的三个典型示例。因为这个GAN是专门针对人脸的,所以整体效果非常好:所有图像的质量和相关性都很高,除了图像(b),它的相关性是中等的,因为底部有金色的头发
图~\ref{fig:results_specific_StyleGAN2_car_d}显示了通过StyleGAN2-car生成的输入标题和相关输出图像的三个典型例子。虽然该GAN专门用于汽车,但由于存在人工制品,所有图像的质量都是中等。(a)和(b)的相关性高,但(c)的相关性中等,因为“交集”是不可见的。\
图~\ref{fig:results_specific_StyleGAN2_church_d}显示了通过StyleGAN2-church生成的输入标题和相关输出图像的三个典型例子。这个GAN专门研究教堂建筑的图像。事实上,图像的相关性是高的,由于存在较小的伪影,质量是高的
这些例子清楚地表明\glass能够结合正确的图像元素匹配目标标题,当使用属于生成网络的相同领域的输入文本。
商用角度讲,小领域是好的
Differently than in the previous cases, Figure~\ref{fig:results_mix_ffhq} shows the output images generated via StyleGAN2 on three domains (face, car, and church). To asses the role of the Discriminator, the optimization is also performed without it. In Figure~\ref{fig:results_mix_ffhq}, the images produced without Discriminator have a final asterisk in the caption. Specifically, by using the input text “the face of a blonde girl with glasses”, the StyleGAN2-face achieves a high quality and relevance for (a) and (d), as expected. On the other side, the low performance of StyleGAn2-car and StyleGAn2-church are apparent. However, it is worth noting that in Figure~\ref{fig:results_mix_ffhq} (f) the picture resembles a face with glasses, generated via two windows on a building.
与之前的例子不同,Figure~\ref{fig:results_mix_ffhq}显示了通过StyleGAN2在三个域(人脸、汽车和教堂)上生成的输出图像。为了评估Discriminator的作用,优化也在没有它的情况下执行。在图~\ref{fig:results_mix_ffhq}中,没有Discriminator的图像在标题中有一个最后的星号。具体来说,通过使用输入文本“一个戴眼镜的金发女孩的脸”,StyleGAN2-face实现了(a)和(d)的高质量和相关性,正如预期的那样。另一方面,StyleGAn2-car和StyleGAn2-church的低性能也很明显。然而,值得注意的是,在Figure~\ref{fig:results_mix_ffhq} (f)中,这张照片就像一张戴着眼镜的脸,它是通过建筑物上的两个窗户生成的。
Figure~\ref{fig:results_mix_car} and Figure~\ref{fig:results_mix_church} show the output images generated via StyleGAN2, with and without Discriminator, for the input caption “a blue car in the snow” and “a gothic church in the city”, respectively. Not surprisingly, the GAN that is specialized in the category of interest (face, car, church) provide the best significance, but medium-low quality due to the presence of artifacts.
图~\ref{fig:results_mix_car}和图~\ref{fig:results_mix_church}显示了通过StyleGAN2生成的输出图像,带有和不带Discriminator,分别为输入标题“雪地里的一辆蓝色汽车”和“城市里的一座哥特式教堂”。毫不奇怪,专注于兴趣类别(脸、汽车、教堂)的GAN提供了最好的意义,但由于存在人工制品,其质量为中-低。
Overall, the resulting images resemble the target caption, but the medium-low quality of the images suggests that, to correctly perform this task, a bigger Generator (i.e. with more parameters) trained on a wider variety of images is needed. In other words, the Generator cannot create images that do not belong to its training domain. In general, it is apparent that the Discriminator guarantees a better quality of the output images. Interestingly, when the Discriminator is not used, even if the target text is outside of the Generator domain, it is able to generate images that somehow resemble the target text. For example, Figure \ref{fig:results_mix_car}(d) is generated via StyleGAN2-face with the input caption a blue car in the snow'': it represents a face of man in the snow with a blue sweater. Another example is Figure <br /> \ref{fig:results_mix_car}(f), generated by StyleGAN2-church without Discriminator: it represents a church with a blue blob whose shape remembers a car.<br />Figure \ref{fig:results_mix_church} shows examples generated by the three domain StyleGAN2 networks via the captiona gothic church in the city’’. Specifically, StyleGAN2-car without Discriminator generates an image with a background building that remember the gothic style.
Finally, the \glass framework has been experimented using BigGAN, a large scale GAN trained with ImageNet, i.e., with multiple domains images. Figure~\ref{fig:results_specific_DeepMindBigGAN} shows three captions and the related images generated from BigGAN. Although the overall quality is medium for the presence of artifacts, the relevance is high.
总的来说,生成的图像与目标标题相似,但图像的中低质量表明,要正确执行该任务,需要在更广泛的图像上训练更大的Generator(即具有更多参数)。换句话说,生成器不能创建不属于其训练域的图像。一般来说,很明显,鉴别器保证了更好的输出图像质量。有趣的是,当不使用Discriminator时,即使目标文本不在Generator域中,它也能够生成与目标文本相似的图像。例如,Figure \ref{fig:results_mix_car}(d)是通过StyleGAN2-face生成的,输入标题为“雪地里的蓝色汽车”:它表示雪地里穿着蓝色毛衣的男人的脸。另一个例子是Figure
\ref{fig:results_mix_car}(f),由StyleGAN2-church生成,不带Discriminator:它代表一个蓝色斑点的教堂,形状记得一辆车。
图\ref{fig:results_mix_church}显示了由三个域StyleGAN2网络通过标题“城市中的一座哥特式教堂”生成的示例。具体来说,不使用Discriminator的StyleGAN2-car生成的图像带有哥特式风格的背景建筑。
最后,使用BigGAN对\glass框架进行了实验,BigGAN是一种用ImageNet训练的大规模GAN,即多域图像。图~\ref{fig:results_specific_DeepMindBigGAN}显示了三个标题和由BigGAN生成的相关图像。虽然整体质量对于工件的存在是中等的,但是相关性是高的。
\subsection{Examples of the Image-to-Text task}
This section focuses on some representative examples of the caption generation capabilities of \glass.
Specifically, 20 context tokens have been used as GPT2 latent space $z$, to which three fixed tokens have been concatenated, representing the static context “the picture of”. The latent space of the context tokens is a integer space of numbers ranging from 0 to 50257, which is the BPE vocabulary size. Indeed, GPT2 adopts a subword-level vocabulary: it does not predict the next word but the next subword token. When optimizing GPT2 latent space, integer genetic operators have been used to perform initialization, mutation and crossover operations.\
Figure~\ref{fig:results_gpt2} shows nine input images randomly extracted from ImageNet, with the related captions generated via GPT2. The results clearly show the \glass potential of caption generation. The most captions have both high quality and high relevance. Some captions, e.g., (a), (c), and (h) have high relevance and medium quality because of the textual artifacts. For example, caption (a) the picture of a dog that has a high fatality rate'', can be related to the fact that the dog is lying on the ground; caption (h)the picture of the world’s first `safe’ phone’’, can be related to the fact that the phone in the picture resembles a safe.
本节重点介绍一些\glass的标题生成能力的代表性例子。
具体来说,使用20个上下文标记作为GPT2潜空间$z$,将三个固定标记连接到其中,表示静态上下文“the picture of”。上下文标记的潜在空间是一个整数空间,范围从0到50257,这是BPE词汇表的大小。实际上,GPT2采用了子单词级词汇表:它不预测下一个单词,而是预测下一个子单词标记。在优化GPT2潜空间时,使用整数遗传算子进行初始化、变异和交叉操作
图~\ref{fig:results_gpt2}显示了随机从ImageNet中提取的9张输入图像,以及通过GPT2生成的相关标题。结果清楚地显示\玻璃潜力的字幕生成。大多数标题都具有高质量和高相关性。一些标题,例如(a)、(c)和(h),由于文本的人工制品,具有高相关性和中等质量。例如,标题(a)“有高致死率的狗的图片”,可能与狗躺在地上的事实有关;标题(h)“世界上第一款‘安全’手机的图片”,可以与图片中的手机类似于一个保险箱的事实有关。
\section{\uppercase{Conclusions}}
In this research work we have introduced \glass, a zero-shot framework which takes an input caption and generates a corresponding image, and vice versa. \glass is based on the CLIP neural network, for generating close embeddings of semantically close texts or images, a Generator network, for controlling the respective generation of images or texts, and a Genetic Algorithm, to explore the Generator space to find the best image or text. The design choices are first detailed, and then a set of pilot experiments are discussed, using the generative networks BigGAN, StyleGAN2 and GPT2. Results show the high potential of the proposed framework, in terms of quality and relevance of the output image or text, encouraging further comparative research. The source code has been publicly released, along with an in-browser demonstration.
在这项研究工作中,我们引入了\glass,一个零镜头框架,它接受输入的标题并生成相应的图像,反之亦然。\glass是基于CLIP神经网络,用于生成语义上相近的文本或图像的紧密嵌入,一个Generator网络,用于控制各自生成的图像或文本,和一个遗传算法,探索Generator空间,找到最佳的图像或文本。首先详细介绍了设计选择,然后利用生成网络BigGAN、StyleGAN2和GPT2进行了一组试点实验。结果表明,在输出图像或文本的质量和相关性方面,提出的框架具有很高的潜力,鼓励进一步的比较研究。源代码已经公开发布,同时还有一个浏览器内的演示。
\section*{\uppercase{Acknowledgement}}
Work partially supported by the Italian Ministry of Education and Research (MIUR) in the framework of the CrossLab project (Departments of Excellence).
由意大利教育和研究部(MIUR)在跨部门(卓越部门)项目框架下部分支持的工作。
