diff --git a/draftandreviseeffectiveimagegenerationwithcontextualrqtransformer/69e4999c-0dda-47a8-bf21-e7202be93717_content_list.json b/draftandreviseeffectiveimagegenerationwithcontextualrqtransformer/69e4999c-0dda-47a8-bf21-e7202be93717_content_list.json new file mode 100644 index 0000000000000000000000000000000000000000..72e046a29fecc07b978949b2fae7ea4c003bf3e4 --- /dev/null +++ b/draftandreviseeffectiveimagegenerationwithcontextualrqtransformer/69e4999c-0dda-47a8-bf21-e7202be93717_content_list.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:337aa7eab31cdc8339f7c4b39c1cabb80c286d489f919e8ba2f801b6a91ce06a +size 77300 diff --git a/draftandreviseeffectiveimagegenerationwithcontextualrqtransformer/69e4999c-0dda-47a8-bf21-e7202be93717_model.json b/draftandreviseeffectiveimagegenerationwithcontextualrqtransformer/69e4999c-0dda-47a8-bf21-e7202be93717_model.json new file mode 100644 index 0000000000000000000000000000000000000000..ad6679b3074c068af94b81d924c5a4356bdc29c6 --- /dev/null +++ b/draftandreviseeffectiveimagegenerationwithcontextualrqtransformer/69e4999c-0dda-47a8-bf21-e7202be93717_model.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7c53356ccc8658ce1118e83007651c2a07267d65b6c5914fd09a17b84811d30c +size 92781 diff --git a/draftandreviseeffectiveimagegenerationwithcontextualrqtransformer/69e4999c-0dda-47a8-bf21-e7202be93717_origin.pdf b/draftandreviseeffectiveimagegenerationwithcontextualrqtransformer/69e4999c-0dda-47a8-bf21-e7202be93717_origin.pdf new file mode 100644 index 0000000000000000000000000000000000000000..22985ae91d3a70e0fe063f1d90ba8ff23f93069c --- /dev/null +++ b/draftandreviseeffectiveimagegenerationwithcontextualrqtransformer/69e4999c-0dda-47a8-bf21-e7202be93717_origin.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dc07e8dd876b17f58b9556d33975134c831504d21b180b4c33380dc7b7b51996 +size 3577324 diff --git a/draftandreviseeffectiveimagegenerationwithcontextualrqtransformer/full.md b/draftandreviseeffectiveimagegenerationwithcontextualrqtransformer/full.md new file mode 100644 index 0000000000000000000000000000000000000000..f7ba79bd25122158a34872051f22805380f57680 --- /dev/null +++ b/draftandreviseeffectiveimagegenerationwithcontextualrqtransformer/full.md @@ -0,0 +1,326 @@ +# Draft-and-Revise: Effective Image Generation with Contextual RQ-Transformer + +Doyup Lee* + +Kakao Brain + +doyup.lee@kakaobrain.com + +Chiheon Kim* + +Kakao Brain + +chiheon.kim@kakaobrain.com + +Saehoon Kim + +Kakao Brain + +shkim@kakaobrain.com + +Minsu Cho + +POSTECH + +mscho@postech.ac.kr + +Wook-Shin Han† + +POSTECH + +wshan@dblab.postech.ac.kr + +# Abstract + +Although autoregressive models have achieved promising results on image generation, their unidirectional generation process prevents the resultant images from fully reflecting global contexts. To address the issue, we propose an effective image generation framework of Draft-and-Revise with Contextual RQ-transformer to consider global contexts during the generation process. As a generalized VQ-VAE, RQ-VAE first represents a high-resolution image as a sequence of discrete code stacks. After code stacks in the sequence are randomly masked, Contextual RQ-Transformer is trained to infill the masked code stacks based on the unmasked contexts of the image. Then, we propose the two-phase decoding, Draft-and-Revise, for Contextual RQ-Transformer to generate an image, while fully exploiting the global contexts of the image during the generation process. Specifically, in the draft phase, our model first focuses on generating diverse images despite rather low quality. Then, in the revise phase, the model iteratively improves the quality of images, while preserving the global contexts of generated images. In experiments, our method achieves state-of-the-art results on conditional image generation. We also validate that the Draft-and-Revise decoding can achieve high performance by effectively controlling the quality-diversity trade-off in image generation. + +# 1 Introduction + +Learning discrete representations of images enables autoregressive (AR) models to achieve promising results on image generation. Here, an image is encoded into a feature map, which is represented as a sequence of discrete codes [13, 33] or code stacks [23]. Then, an AR model generates a sequence of codes in the raster scan order and decodes the codes into an image. Consequently, AR models show high performance and scalability on large-scale datasets [13, 23, 26]. + +Despite the promising results of AR models, we pos + +tulate that the ability of AR models is limited due to the lack of considering global contexts in the generation process. Specifically, since AR models generate images by sequentially predicting the + +![](images/1a021e2ddb834f507f24a7adfb38c60de78e47a5df0dfff6837c7d3a913785d5.jpg) +Figure 1: Examples of image inpainting by an AR model (middle) and ours (right). + +next code and attending to only precedent codes generated, they neither exploit the later part of the generated image nor consider the global contexts during generation. For example, Figure 1 (middle) shows that an AR model fails to generate a coherent image, when it is asked to inpaint the masked region of Figure 1 (left) with a school bus. Such a failure is due to the inability of AR models to refer to the context of traffic lane on the right side of the masked region. + +To address this issue, we propose an effective image generation framework, Draft-and-Revise, with a contextual transformer to exploit the global contexts of images. Given a randomly masked image, the contextual transformer is first trained to infill the masks by bidirectional self-attention similarities similarly to BERT [8]. To fully leverage the contextual prediction in generation, we propose Draft-and-Revise decoding which has two phases, draft and revise, imitating the image generation process of a human expert who draws a draft first and iteratively revises the draft to improve its quality. In the draft phase, the model first infills an empty image to generate a draft image with diverse contents despite the rather low-quality. In the revise phase, the visual quality of the draft is iteratively improved, while the global contexts of the draft are preserved and exploited. Consequently, our Draft-and-Revise with contextual transformer effectively generates high-quality images with diverse contents. + +We use residual-quantized VAE (RQ-VAE) [23] to implement our image generation framework, since RQ-VAE generalizes vector-quantized VAE (VQ-VAE) [33] by representing an image as a sequence of code stacks instead of a sequence of codes. Then, we propose Contextual RQ-Transformer as a contextual transformer for masked code stack modeling of RQ-VAE. Specifically, given a sequence of randomly masked code stacks, Contextual RQ-Transformer first uses a bidirectional transformer to capture the global contexts of unmasked code stacks. Based on the global contexts, the masked code stacks are predicted in parallel, while the codes in each masked code stack are sequentially predicted. In experiments, our Draft-and-Revise framework with Contextual RQ-Transformer achieves state-of-the-art results on conditional image generation and remarkable improvements on image inpainting. In addition, we demonstrate that Draft-and-Revise decoding can effectively control the quality-diversity trade-off in image generation to achieve high performance. + +The main contributions of this paper are summarized as follows. 1) We propose an intuitive and powerful framework, Contextual RQ-Transformer, for masked code stack modeling of RQ-VAE based on a bidirectional transformer. 2) We propose a novel two-phase decoding, Draft-and-Revise, for bidirectional transformers to fully exploit the global contexts during image generation and achieve state-of-the-art results on class- and text-conditional image generation benchmarks. 3) An extensive ablation study validates the effectiveness of Draft-and-Revise decoding on controlling the quality-diversity trade-off and its capability to generate high-quality images with diverse contents. + +# 2 Related Work + +Discrete Representation for Image Generation By representing an image as a sequence of codes, VQ-VAE [33] becomes an important part for high-resolution image generation [6, 10, 15, 23, 26, 33], but suffers from low quality of reconstructed images. However, VQGAN [13] significantly improves the perceptual quality of reconstructed images by adding the adversarial and perceptual losses into the training objective of VQ-VAE. As a generalized approach of VQ-VAE and VQGAN, RQ-VAE [23] represents an image as a sequence of code stacks, which consists of ordered codes, and reduces the sequence length, while preserving the reconstruction quality. Then, RQ-Transformer [23] achieves high performance with lower computational costs on generating high-resolution images. However, as an AR model of RQ-VAE, RQ-Transformer cannot capture the global contexts of generated images. + +Generation Tasks with Bidirectional Transformers To overcome the limitation of AR models on unidirectional architecture, bidirectional transformers have been studied for generative tasks. After a bidirectional transformer is trained to infill a random mask as the masked token modeling of BERT [8], an effective decoding method has been proposed for bidirectional transformers to generate texts [14, 30], images [6, 35], or videos [16]. For image generation, M6-UFC [35] first incorporates the masked token modeling in the codes of VQGAN [13] for image generation. MaskGIT [6] proposes the confidence-based decoding to achieve high performance on ImageNet [7]. Similar to M6-UFC [35] and MaskGIT [6], we also incorporate the masked token modeling of RQ-VAE in a bidirectional transformer for image generation. However, instead of the confidence-based decoding [6, 35], we propose a novel two-phase decoding for a bidirectional transformer to achieve state-of-the-art performance and validate its effectiveness. Recently, discrete diffusion models [1, 4, 12, 15] also uses + +![](images/85b2b461df4adcf46cfff9c147818bb911c91bcc6f29722f41939288924226d9.jpg) +Tokenizing (RQ-VAE) + +![](images/3a8d5e5d9bccc7f9f2a06611831589d0ac3651e507dcb5f6bd91f61b22336391.jpg) +Random Masking + +![](images/1439462acfd962d87b120f2817578afe2131efb46b0493ddd5ad0db5c46a8c38.jpg) +Contextual RQ-Transformer + +![](images/bc648c59fbd0bf28332fef86ae8569fd66d73b98fd942c32fb3132eaaca0475a.jpg) +Draft-and-Revise Decoding + +![](images/f27ea1a4bd6e4f51135f24cf0cbc79dd4875a95db8398031423bd42202a3d399.jpg) +Figure 2: The overview of Draft-and-Revise framework with Contextual RQ-Transformer. Our framework exploits global contexts of images to generate high-quality images with diverse contents. + +bidirectional transformers to generate an image, and the training with an absorbing state [1] is also the same to infill randomly masked sequence [4, 6]. However, different from the reverse process of diffusion models, our decoding method has explicit two phases to generate high-quality images with diverse contents. + +# 3 Draft-and-Revise Framework for Effective Image Generation + +In this section, we propose our Draft-and-Revise framework for effective image generation using bidirectional contexts of images. We first review RQ-VAE [23] as a generalization of VQ-VAE. Then, we propose Contextual RQ-Transformer which is trained to infill a randomly masked sequence of code stacks of RQ-VAE by understanding bidirectional contexts of unmasked parts in the sequence. Lastly, we propose draft-and-revise decoding for a bidirectional transformer to effectively generate high-quality images exploiting global contexts of images. Figure 2 provides the overview of our proposed framework, including Contextual RQ-Transformer and Draft-and-Revise decoding. + +# 3.1 Residual-Quantized Variational Autoencoder (RQ-VAE) + +RQ-VAE [23] represents an image as a sequence of code stacks. Let a codebook $\mathcal{C} = \{(k, \mathbf{e}(k))\}_{k \in [K]}$ include pairs of a code $k$ and its code embedding $\mathbf{e}(k) \in \mathbb{R}^{n_z}$ , where $K = |\mathcal{C}|$ is the codebook size and $n_z$ is the dimensionality of $\mathbf{e}(k)$ . Given a vector $\mathbf{z} \in \mathbb{R}^{n_z}$ , $\mathcal{Q}(\mathbf{z}; \mathcal{C})$ is defined as the code of $\mathbf{z}$ : + +$$ +\mathcal {Q} (\mathbf {z}; \mathcal {C}) = \underset {k} {\arg \min } \| \mathbf {z} - \mathbf {e} (k) \| _ {2} ^ {2}. \tag {1} +$$ + +Then, RQ with depth $D$ represents a vector as a code stack which consists of $D$ codes: + +$$ +\mathcal {R Q} (\mathbf {z}; \mathcal {C}, D) = \left(k _ {1}, \dots , k _ {D}\right) \in [ K ] ^ {D}, \tag {2} +$$ + +where $k_{d}$ is the $d$ -th code of $\mathbf{z}$ . Specifically, RQ first initializes the 0-th residual vector as $\mathbf{r}_0 = \mathbf{z}$ , and then recursively discretizes a residual vector $\mathbf{r}_{d-1}$ and computes the next residual vector $\mathbf{r}_d$ as + +$$ +k _ {d} = \mathcal {Q} \left(\mathbf {r} _ {d - 1}; \mathcal {C}\right), \quad \mathbf {r} _ {d} = \mathbf {r} _ {d - 1} - \mathbf {e} \left(k _ {d}\right), \tag {3} +$$ + +for $d \in [D]$ . Finally, $\mathbf{z}$ is approximated by the sum of the $D$ code embeddings $\hat{\mathbf{z}} := \sum_{d=1}^{D} \mathbf{e}(k_d)$ . We remark that RQ is a generalized version of VQ, as RQ with $D = 1$ is equivalent to VQ. For $D > 1$ , RQ conducts a finer approximation of $\mathbf{z}$ as the quantization errors are sequentially reduced as $d$ increases. Here, the coarse-to-fine approximation ensures the $D$ codes to be sequentially dependent. + +RQ-VAE represents an image as a map of code stacks. Specifically, a given image $\mathbf{X}$ is first converted to a low-resolution feature map $\mathbf{Z} = E(\mathbf{X}) \in \mathbb{R}^{H \times W \times n_z}$ , and then each feature vector $\mathbf{Z}_{hw}$ at spatial position $(h, w)$ is discretized into a code stack by RQ with depth $D$ . As a result, we get a map of code stacks $\mathbf{S} \in [K]^{H \times W \times D}$ . Further details of RQ-VAE are referred to Appendix. + +# 3.2 Contextual Transformer for Image Generation with Global Contexts + +As a bidirectional transformer for RQ-VAE, we propose Contextual RQ-Transformer for image generation based on a contextual understanding of images. First, we adopt the pretraining of BERT [8] to formulate a masked code stack modeling of RQ-VAE. Then, we introduce how Contextual RQ-Transformer infills the randomly masked code stacks after reading the given contextual information. + +# 3.2.1 Masked Code Stack Modeling of RQ-VAE + +By adopting the pretraining of BERT [8], we formulate the masked code stack modeling of RQ-VAE with a contextual transformer to generate an image by iterative mask-infilling as non-AR models [14]. We first convert the map $\mathbf{S} \in [K]^{H \times W \times D}$ into a sequence of code stacks $\mathbf{S}' \in [K]^{N \times D}$ using the raster-scan ordering, where $N = HW$ and $\mathbf{S}_n' = (\mathbf{S}_{n1}', \dots, \mathbf{S}_{nD}') \in [K]^D$ for $n \in [N]$ . We denote $\mathbf{S}'$ as $\mathbf{S}$ for the brevity of notation. A mask vector $\mathbf{m}$ is defined as a binary vector $\mathbf{m} \in \{0, 1\}^N$ to indicate the spatial positions to be masked. Then, the masked sequence $\mathbf{S}_{\backslash \mathbf{m}}$ of $\mathbf{S}$ by $\mathbf{m}$ is defined as + +$$ +\left(\mathbf {S} _ {\backslash \mathbf {m}}\right) _ {n} = \left\{ \begin{array}{l l} \mathbf {S} _ {n} & \text {i f} \mathbf {m} _ {n} = 0 \\ {[ \mathrm {M A S K} ] ^ {D}} & \text {i f} \mathbf {m} _ {n} = 1 \end{array} , \right. \tag {4} +$$ + +where $[\mathbf{MASK}]$ is a mask token to substitute for $\mathbf{S}_{nd}$ if $\mathbf{m}_n = 1$ . Given a random mask vector $\mathbf{m} \sim q(\mathbf{m})$ , the masked code stacks given $\mathbf{S}_{\backslash \mathbf{m}}$ are modeled as + +$$ +\prod_ {n: \mathbf {m} _ {n} = 1} p (\mathbf {S} _ {n} | \mathbf {S} _ {\backslash \mathbf {m}}) = \prod_ {n: \mathbf {m} _ {n} = 1} \prod_ {d = 1} ^ {D} p \left(\mathbf {S} _ {n d} | \mathbf {S} _ {n, < d}, \mathbf {S} _ {\backslash \mathbf {m}}\right), \tag {5} +$$ + +where $q(\mathbf{m})$ is a mask distribution where the masking portion $\sum_{n=1}^{N} \mathbf{m}_i / N$ in (0, 1] as well as the masking positions are randomly chosen. Instead of fixing the portion to $15\%$ as in BERT, training a model with a random masking portion from (0, 1] enables the model to generate new images based on various masking patterns including $\mathbf{m}_n = 1$ for all $n$ . We explain the details of $q(\mathbf{m})$ in Section 3.2.3. + +The left-hand side of Eq. 5 implies that all masked code stacks can be decoded in parallel based on the contexts of $\mathbf{S}_{\backslash \mathbf{m}}$ . If $D = 1$ , Eq. 5 becomes equivalent to conventional masked token modeling of texts [8] and images [6, 16] where a single token at each masked position is predicted. For $D > 1$ , the $D$ codes of $\mathbf{S}_n$ are autoregressively predicted, as they are sequentially computed in Eq. 3 for a coarse-to-fine approximation and hence well-suited for an AR prediction. We show that the effectiveness of our framework is generalizable regardless of $D$ in Appendix B. In addition, the parallel decoding can control the trade-off between the quality and sampling speed of image generation. + +# 3.2.2 Contextual RQ-Transformer + +We modify the previous RQ-Transformer [23] for masked code stack modeling with bidirectional contexts in Eq. 5. Contextual RQ-Transformer consists of Bidirectional Spatial Transformer and Depth Transformer: Bidirectional Spatial Transformer understands contextual information in the unmasked code stacks using bidirectional self-attention, and Depth Transformer infills the masked code stacks in parallel, by autoregressively predicting the $D$ codes at each position. + +Bidirectional Spatial Transformer Given a masked sequence of code stacks $\mathbf{S}_{\backslash \mathbf{m}}$ , bidirectional spatial transformer first embeds the masked sequence $\mathbf{S}_{\backslash \mathbf{m}}$ using the code embeddings of RQ-VAE as + +$$ +\mathbf {u} _ {n} = \mathrm {P E} _ {N} (n) + \left\{ \begin{array}{l l} \sum_ {d = 1} ^ {D} \mathbf {e} \left(\mathbf {S} _ {n d}\right) & \text {i f} \mathbf {m} _ {n} = 0 \\ \mathbf {e} _ {[ \text {M A S K} ]} & \text {i f} \mathbf {m} _ {n} = 1 \end{array} , \right. \tag {6} +$$ + +where $\mathrm{PE}_N(n)$ is an embedding for position $n$ , and $\mathbf{e}_{[\mathrm{MASK}]} \in \mathbb{R}^{n_z}$ is a mask embedding. Then, the bidirectional self-attention blocks, $f_{\theta}^{\mathrm{spatial}}$ , extracts the context vector $\mathbf{h}_n$ to predict a code stack $\mathbf{S}_n$ , + +$$ +\left(\mathbf {h} _ {1}, \dots , \mathbf {h} _ {N}\right) = f _ {\theta} ^ {\text {s p a t i a l}} \left(\mathbf {u} _ {1}, \dots , \mathbf {u} _ {N}\right). \tag {7} +$$ + +Depth Transformer The code stack at a masked position $\mathbf{S}_n = (\mathbf{S}_{n1},\dots ,\mathbf{S}_{nD})$ is autoregressively predicted. The input of depth transformer $(\mathbf{v}_{nd})_{d = 1}^{D}$ is defined as + +$$ +\mathbf {v} _ {n d} = \mathrm {P E} _ {D} (d) + \left\{ \begin{array}{l l} \mathbf {h} _ {n} & \text {i f} d = 1 \\ \sum_ {d ^ {\prime} = 1} ^ {d - 1} \mathbf {e} \left(\mathbf {S} _ {n d ^ {\prime}}\right) & \text {i f} d > 1 \end{array} \right. \tag {8} +$$ + +Algorithm 1 UPDATE of S +Require: A sequence of code stacks S, a partition $\Pi = (\mathbf{m}^1,\dots ,\mathbf{m}^T)$ , a model $\theta$ 1: for $t = 1,\dots ,T$ do 2: Sample $\mathbf{S}_n\sim p_\theta (\mathbf{S}_n|\mathbf{S}_{\backslash \mathbf{m}^t})$ $\forall n:\mathbf{m}_n^t = 1$ update the codes at masked positions 3: end for 4: return S +Algorithm 2 Draft-and-Revise decoding +Require: Partition sampling distributions $p_{\mathrm{draft}}$ and $p_{\mathrm{rev}}$ , the number of revision iterations M /* draft phase \*/ 1: $\mathbf{S}^{\mathrm{empty}}\gets ([\mathrm{MASK}],\dots ,[\mathrm{MASK}])^N$ ▷initialize empty code map 2: Sample $\Pi \sim p(\Pi ;T_{\mathrm{draft}})$ 3: $\mathbf{S}^{\mathrm{draft}}\gets \mathrm{UPDATE}(\mathbf{S}^{\mathrm{empty}},\Pi ;\theta)$ generate a draft code map /* revision phase \*/ 4: $\mathbf{S}^{0}\gets \mathbf{S}^{\mathrm{draft}}$ 5: for $m = 1,\dots ,M$ do 6: Sample $\Pi \sim p(\Pi ;T_{\mathrm{revise}})$ 7: $\mathbf{S}^{m}\gets \mathrm{UPDATE}(\mathbf{S}^{m - 1},\Pi ;\theta)$ iteratively revise the code map 8: end for 9: return $\mathbf{S}^{M}$ + +where $\mathrm{PE}_D(d)$ is the positional embedding for depth $d$ . Then, depth transformer $f_{\theta}^{\mathrm{depth}}$ , which consists of causal attention blocks, outputs the logit $\mathbf{p}_{nd}$ to predict the $d$ -th code $\mathbf{S}_{nd}$ at position $n$ as + +$$ +\mathbf {p} _ {n d} = f _ {\theta} ^ {\mathrm {d e p t h}} \left(\mathbf {v} _ {n 1}, \dots , \mathbf {v} _ {n d}\right) \quad \text {a n d} \quad p _ {\theta} \left(\mathbf {S} _ {n d} = k | \mathbf {S} _ {n, < d}, \mathbf {S} _ {\backslash \mathbf {m}}\right) = \operatorname {s o f t m a x} \left(\mathbf {p} _ {n d}\right) _ {k}. \qquad (9) +$$ + +We remark that the architecture of Contextual RQ-Transformer subsumes bidirectional transformers. Specifically, RQ-Transformer with the depth $D = 1$ is equivalent to a bidirectional transformer since the depth transformer becomes a multilayer perceptron with layer normalization [2]. + +# 3.2.3 Training of Contextual RQ-Transformer + +For the training of Contextual RQ-Transformer, let us define a mask distribution $q(\mathbf{m})$ with a mask scheduling function $\gamma$ . Following previous approaches [6, 14, 16], the scheduling function $\gamma$ is chosen to be decreasing and to satisfy $\gamma(0) = 1$ and $\gamma(1) = 0$ . Then, a mask $\mathbf{m} \sim q(\mathbf{m})$ is specified as + +$$ +r \sim \operatorname {U n i f} ([ 0, 1)) \quad \text {a n d} \quad \mathbf {m} \sim \operatorname {U n i f} (\{\mathbf {m}: | \mathbf {m} | = \lceil \gamma (r) \cdot N \rceil \}), \tag {10} +$$ + +where $|\mathbf{m}| = \sum_{n\in [N]}\mathbf{m}_n$ is the count of masked positions. Finally, the training objective of Contextual RQ-Transformer is to minimize the negative log-likelihood of masked code stacks: + +$$ +\mathcal {L} = \mathbb {E} _ {\mathbf {m} \sim q (\mathbf {m})} \left[ \mathbb {E} _ {\mathbf {S}} \left[ \sum_ {n: \mathbf {m} _ {n} = 1} ^ {D} \sum_ {d = 1} ^ {D} - \log p _ {\theta} \left(\mathbf {S} _ {n d} \mid \mathbf {S} _ {n, < d}, \mathbf {S} _ {\backslash \mathbf {m}}\right) \right] \right]. \tag {11} +$$ + +# 3.3 Draft-and-Revise: Two-Phase Decoding with Global Contexts of Generated Images + +We propose a novel decoding algorithm, Draft-and-Revise, for Contextual RQ-Transformer to effectively generate high-quality images with diverse visual contents. We remark that our effective decoding method is required for bidirectional transformers to fully exploit the global contexts of images and achieve high performance of image generation. Here, we introduce the details of our Draft-and-Revise decoding and then explain how the two-phase decoding of Draft-and-Revise can effectively control the quality-diversity trade-off of generated images. + +We define a partition $\Pi = (\mathbf{m}^1, \dots, \mathbf{m}^T)$ as a collection of pairwise disjoint $T$ mask vectors to cover all spatial positions, where $\sum_{t=1}^{T} \mathbf{m}_n^t = 1$ for all $n \in [N]$ . A partition $\Pi$ is sampled from the distribution $p(\Pi; T)$ , which is the uniform distribution over all balanced partitions with size $T$ : + +$$ +p (\boldsymbol {\Pi}; T) = \operatorname {U n i f} \left(\left\{\boldsymbol {\Pi} = \left(\mathbf {m} ^ {1}, \dots , \mathbf {m} ^ {T}\right): | \mathbf {m} ^ {t} | = \frac {N}{T} \forall t \in [ T ] \right\}\right). \tag {12} +$$ + +Table 1: FIDs, ISs, Precisions, and Recalls for class-conditional generation on ImageNet [7]. † denotes the use of pretrained classifier for rejection sampling, gradient guidance, or training. + +
ParamsH × W × DFID↓IS↑Precision↑Recall↑
BigGAN-deep [5]112M-6.95202.60.870.23
StyleGAN-XL†[29]166M-2.3262.10.780.53
ADM [9]554M-10.94101.00.690.63
ADM-G†[9]608M-4.59186.70.820.52
ImageBART [12]3.5B16×16×121.1961.6--
VQ-Diffusion [15]518M16×16×111.89---
LDM-8 [27]395M32×3215.5179.030.650.63
LDM-8-G†[27]506M32×327.76209.520.840.35
MaskGIT [6]227M16×16×16.18182.10.800.51
VQ-GAN [13]1.4B16×16×115.7874.3--
RQ-Transformer [23]1.4B8×8×48.71119.00.710.58
RQ-Transformer [23]3.8B8×8×47.55134.00.730.58
RQ-Transformer†[23]3.8B8×8×43.80323.70.820.50
Contextual RQ-Transformer333M8×8×45.45172.60.810.49
Contextual RQ-Transformer821M8×8×43.45221.90.820.52
Contextual RQ-Transformer1.4B8×8×43.41224.60.790.54
Validation Data--1.62234.00.750.67
+ +We first define a procedure UPDATE(S, II) to update the sequence S as described in Algorithm 1, which updates $\mathbf{S}_n$ with $\mathbf{m}_n^t = 1$ for $t \in [T]$ . Then, Draft-and-Revise decoding in Algorithm 2 generates a draft from the empty sequence of code stacks and improves the quality of the draft. + +Draft phase In the draft phase, our model gradually infills the empty sequence of code stacks to generate a draft image, considering the global contexts of filled code stacks. Let $\mathbf{S}^{\mathrm{empty}}$ be an empty sequence of code stacks with $\mathbf{S}_n^{\mathrm{empty}} = [\mathbf{MASK}]^D$ for all $n$ . Given a partition size $T_{\mathrm{draft}}$ , our model generates a draft image as + +$$ +\mathbf {S} ^ {\text {d r a f}} = \operatorname {U P D A T E} \left(\mathbf {S} ^ {\text {e m p t y}}, \boldsymbol {\Pi}; \theta\right) \quad \text {w h e r e} \quad \boldsymbol {\Pi} \sim p (\boldsymbol {\Pi}; T _ {\text {d r a f}}). \tag {13} +$$ + +Revise phase The generated draft $\mathbf{S}^{\mathrm{draft}}$ is repeatedly revised to improve the visual quality of the image, while preserving the overall structure of the draft. Given a partition size $T_{\mathrm{revise}}$ and the number of updates $M$ , the draft $\mathbf{S}^{0} = \mathbf{S}^{\mathrm{draft}}$ is repeatedly updated $M$ times as + +$$ +\mathbf {S} ^ {m} = \operatorname {U P D A T E} \left(\mathbf {S} ^ {m - 1}, \boldsymbol {\Pi}; \theta\right) \quad \text {w h e r e} \quad \boldsymbol {\Pi} \sim p (\boldsymbol {\Pi}; T _ {\text {r e v i s e}}) \quad \text {f o r} m = 1, \dots , M. \tag {14} +$$ + +Note that Draft-and-Revise is not a tailored method, since we can adopt any mask-infilling-based generation method [4, 6] for UPDATE in Algorithm 1. For example, confidence-based decoding [6, 16], which iteratively updates S from high-confidence to low-confidence predictions, can be used for UPDATE. However, we find that confidence-based decoding generates low-diversity images with oversimplified contents, since a model tends to predict simple visual patterns with high confidence. In addition, confidence-based decoding often leads to biased unmasking patterns, which are not used in training. We attach the detailed discussion about confidence-based decoding in Appendix C. Thus, we use a uniformly random partition $\Pi$ in UPDATE as the most simplified rule, leaving investigations on sophisticated update methods as future work. + +We postulate that our Draft-and-Revise can generate high-quality images with diverse contents by explicitly dividing two phases. Specifically, a model first generates draft images with diverse visual contents despite the rather low quality of drafts. After semantically diverse images are generated as drafts, we use sampling strategies such as temperature scaling [19] and classifier-free guidance [20] in the revise phase to improve the visual quality of the drafts, while preserving the major semantic contents in drafts. Thus, our method can improve the performance of image generation by effectively controlling the quality-diversity trade-off. In addition, we emphasize that the two-phased decoding is intuitive and resembles the image generation process of human experts, who repeatedly refine their works to improve the quality after determining the overall contents first. + +![](images/1e1ecd1d8a7bea6f6343191c16e57446eecad6297532918c069209173516bb91.jpg) +Figure 3: The examples of generated $256 \times 256$ images of our model trained on (Top) ImageNet and (Bottom) CC-3M. The used text conditions are "Sunset over the skyline of a {beach, city}.", "an avocado {in the desert, on the seashore}.", and "a painting of a {dog, cat} with sunglasses." + +# 4 Experiments + +In this section, we show that our Draft-and-Revise with Contextual RQ-Transformer can outperform previous approaches for class- and text-conditional image generation. In addition, we conduct an extensive ablation study to understand the effects of Draft-and-Revise decoding on the quality and diversity of generated images, and the sampling speed. We use the publicly released RQ-VAE [23] to represent a $256 \times 256$ resolution of images as $8 \times 8 \times 4$ codes. For a fair comparison, we make Contextual RQ-Transformer have the same model size as the previous RQ-Transformer [23]. For training, the quarter-period of cosine is used as the mask scheduling function $\gamma$ in Eq. 10 following the previous studies [6, 24]. We include the implementation details in Appendix. + +# 4.1 Class-conditional Image Generation + +We train Contextual RQ-Transformer with 333M, 821M, and 1.4B parameters on ImageNet [7] for class-conditional image generation. For Draft-and-Revise decoding, we use $T_{\mathrm{draft}} = 64$ , $T_{\mathrm{revise}} = 2$ , and $M = 2$ . We use temperature scaling [19] and classifier-free guidance [20] only in the revise phase, while none of the strategies are applied in the draft phase. Fréchet Inception Distance (FID) [18], Inception Score (IS) [28], and Precision and Recall [22] are used for evaluation measures. + +Table 1 shows that Contextual RQ-Transformer significantly outperforms the previous approaches. Notably, Contextual RQ-Transformer with 333M parameters outperforms RQ-Transformers with 1.4B and 3.8B parameters on all evaluation measures, despite having only about $4.2 \times$ and $11.4 \times$ fewer parameters. In addition, the performance is improved as the number of parameters increases to 821M and 1.4B. Our model with 333M parameters is competitive with MaskGIT [6], and hence we conduct additional analysis on the effect of confidence-based decoding in Appendix C. Contextual RQ-Transformer can achieve the lower FID score without a pretrained classifier than ADM-G and 3.8B parameters of RQ-Transformer with the use of pretrained classifier. StyleGAN-XL also uses a pretrained classifier during both training and image generation and achieves the lowest FID in Table 1. However, our model with 1.4B parameters has higher precision and recall than StyleGAN-XL, implying that our model generates images of better fidelity and diversity without a pretrained classifier. Our high performance without a classifier is remarkable, since the gradient guidance and rejection sampling are the tailored techniques to the model-based evaluation metrics in Table 1. Considering that the performance is marginally improved as the number of parameters increases from 821M to 1.4B, an improved RQ-VAE can boost the performance of Contextual RQ-Transformer, since the reconstruction quality determines the best results of generated images. + +# 4.2 Text-conditional Image Generation + +We train our model with 333M and 654M parameters on CC-3M [32] for text-to-image (T2I) generation as described in Appendix A. A text condition is encoded into 32 tokens using Byte Pair Encoding [31, 34]. We report CLIP-score [25] with ViT-B/32 [11] as the correspondence between texts and images. + +![](images/01a5a094d911ba644570275b642dc97ffe509fcc534c97cdb049bbc41be666c1.jpg) +(a) + +![](images/8c762a29de380054c734f4e4b827aa15e1d6d69137f399dd31341237929a33c0.jpg) +(b) + +![](images/13fcaac615d4c36121922965f9fdbbe4e32a15ff10f5da2ab7a071fdb91af042.jpg) +(c) + +![](images/c929168cabc71ed06563ad9f15d2be2f99ee4b69cc6165adfe0a1b85520e8cb5.jpg) +Figure 4: Ablation study of Draft-and-Revise decoding. (a) FIDs with the partition sizes of the draft phase $T_{\mathrm{draft}}$ . (b) Precision and recall with the revision iterations $M$ . (c) FID with $T_{\mathrm{revise}}$ . +Figure 5: Examples of generated images in the draft phase (left) and revise phases at each iteration $M = 1,2,3,4,5$ . The draft images are generated with $T_{\mathrm{draft}} = 8$ (top) and $T_{\mathrm{draft}} = 64$ (bottom). + +Contextual RQ-Transformer in Table 2 outperforms the previous T2I generation models. Contextual RQ-Transformer with 333M parameters achieves better FID than RQ-Transformer with 654M parameters, and outperforms ImageBART and LDM-4, although our model has $12\times$ fewer parameters than ImageBART. When we increase the number of parameters to 654M, our model achieves state-of-the-art FID on CC3M. In Figure 3, our model generates images with unseen texts in CC-3M. + +Table 2: FIDs and CLIP scores [25] on the validation dataset of CC-3M [32] for T2I generation. + +
ParamsFID↓CLIP-s↑
VQ-GAN [13]600M28.860.20
ImageBART [12]2.8B22.610.23
LDM-4 [27]645M17.010.24
RQ-Transformer [23]654M12.330.26
Ours333M10.440.26
Ours654M9.800.26
+ +# 4.3 Conditional Image Inpainting + +We conduct conditional image inpainting where a model infills a masked area according to the given condition and contexts. Figure 1 shows the example of image inpainting by RQ-Transformer (middle) and Contextual RQ-Transformer (right), when the class-condition is school bus. RQ-Transformer cannot attend to the right and bottom sides of the masked area and fails to generate a coherent image with given contexts. However, our model can complete the image to be coherent with given contexts by exploiting global contexts. We attach more examples of image inpainting in Appendix. + +# 4.4 Ablation Study on Draft-and-Revise + +We conduct an extensive ablation study to demonstrate the effectiveness of Draft-and-Revise decoding of our framework. We use Contextual RQ-Transformer with 821M parameters trained on ImageNet. + +Quality improvement of draft images in the revise phase Figure 4(a) shows the effects of $T_{\mathrm{draft}}$ on draft images and their quality improvement in the revised phase with $T_{\mathrm{revise}} = 2$ and $M = 2$ . + +In the draft phase, FID is improved as $T_{\mathrm{draft}}$ increases from 4 to 64. At each inference, Contextual RQ-Transformer generates $N / T_{\mathrm{draft}}$ code stacks in parallel, starting with the empty sequence. Thus, the model with a large $T_{\mathrm{draft}}$ generates a small number of code stacks at each inference and can avoid generating incoherent code stacks in the early stage of the draft phase. Although FIDs in the draft phase are worse due to low precision, we intend to increase the diversity of generated images, since the precision is significantly improved in the revise phase as shown in Figure 4(b). + +Effect of revision iteration $M$ and partition size $T_{\text{revise}}$ in the revise phase Figure 4(b) shows the effects of the number of updates $M$ in the revise phase on the quality and diversity of generated images. Since the quality-diversity trade-off exists as the updates are repeated, we select $M = 2$ as the default hyperparameter to balance the precision and recall, considering that the increase of precision starts to slow down. Interestingly, Figure 5 shows that the overall contents remain unchanged even after $M > 2$ . Thus, we claim that Draft-and-Revise decoding does not harm the perceptual diversity of generated images throughout the revise phase despite the consistent deterioration of recall. + +Figure 4(c) shows the effects of $T_{\mathrm{revise}}$ on the quality of generated images. The FIDs are significantly improved in the revise phase regardless of the choice of $T_{\mathrm{revise}}$ , but increasing $T_{\mathrm{revise}}$ slightly deteriorates FIDs. We remark that some code stacks of a draft can be erroneous due to its low quality, and a model with large $T_{\mathrm{revise}}$ slowly updates a small number of code stacks at once in the revise phase. Therefore, the updates with large $T_{\mathrm{revise}}$ can be more influenced by the erroneous code stacks. Although $T_{\mathrm{revise}} = 2$ updates half of an image at once, our draft-and-revise decoding successfully improves the quality of generated images, while preserving the global contexts of drafts, as shown in Figure 5. The study on self-supervised learning [17] also reports similar results, where a masked auto-encoder reconstructs the global contexts of an image after masking half of the image. + +Quality-diversity control of Draft-and-Revise Our Draft-and-Revise decoding can effectively control the quality-diversity trade-off in generated images. Table 3 shows FID, precision (P), and recall (R) according to the use of classifier-free guidance [20] with a scale of 1.8, while applying temperature scaling with 0.8 only to the revise phase. Contextual RQ-Transformer without the guidance already outperforms RQ-Transformer with 3.8B parameters and demonstrates the effectiveness of our framework. When the guidance is used for both draft and + +revise phases, the precision dramatically increases but the recall decreases to 0.33. Consequently, FID becomes worse due to the lack of diversity in generated images. However, when the guidance is applied only to the revise phase, our model achieves the lowest FID, as the quality and diversity are well-balanced. Thus, the explicitly separated two phases of Draft-and-Revise can effectively control the issue of quality-diversity trade-off by generating diverse drafts and then improving their quality. + +Table 3: The effects of classifier-free guidance on the image generation. + +
DraftReviseFIDPR
5.780.720.58
✓3.450.820.52
✓✓8.900.920.33
+ +Trade-off between quality and sampling speed Table 4 shows that our framework can control the trade-off between the quality and sampling speed according to $T_{\mathrm{draft}}$ after we fix $T_{\mathrm{revise}} = 2$ and $M = 2$ . We generate 5,000 samples with batch size of 100 as the previous study [23]. Contextual RQ-Transformer with $T_{\mathrm{draft}} = 8$ outperforms both FID and sampling speed of VQGAN and RQ-Transformer with 1.4B parameters. Although the sampling speed becomes slow with increased $T_{\mathrm{draft}}$ , the FID scores are consistently improved. We remark that the sampling speed with $T_{\mathrm{draft}} = 64$ is about $3\times$ slower than RQ-Transformer, but our model outperforms 3.8B parameters of RQ-Transformer with rejec + +tion sampling in Table 1. The results show that our framework has inexpensive costs to generate high-quality images, considering that rejection sampling requires generating up to $20\times$ more samples. + +Table 4: Comparison of FID and the sampling speed of image generation. + +
FIDs/sample
VQGAN15.780.16
RQ-Transformer8.710.04
Contextual RQ-Transformer
\(T_{\text{draft}}=8\)5.410.03
\(T_{\text{draft}}=32\)3.730.06
\(T_{\text{draft}}=64\)3.450.10
+ +# 5 Conclusion + +In this study, we have proposed Draft-and-Revise for an effective image generation framework with Contextual RQ-Transformer. After an image is represented as a sequence of code stacks, Contextual RQ-Transformer is trained to infill a randomly masked sequence. Then, Draft-and-Revise decoding is used to generate high-quality images by first generating a draft image with diverse contents and then improving its visual quality based on the global contexts of the draft. Consequently, we can achieve state-of-the-art results on ImageNet and CC-3M, demonstrating the effectiveness of our framework. + +Our study has two main limitations to be further explored. Firstly, Draft-and-Revise decoding always updates all code stacks in the revise phase, although some code stacks might not need an update. In future work, a selective method can be developed to improve the efficiency of the revise phase by a sophisticated approach. Secondly, our generative model is not validated on various downstream tasks. Since masked token modeling is successful self-supervised learning for texts [8] and images [3, 17], a unified model for both generative and discriminative tasks [21] is worth exploration for future work. + +# 6 Acknowledgements + +This work was supported by Institute of Information & communications Technology Planning & Evaluation(IITP) grant funded by the Korea government(MSIT) (No.2018-0-01398: Development of a Conversational, Self-tuning DBMS, 35%; No.2021-0-00537: Visual Common Sense, 30%) and the National Research Foundation of Korea(NRF) grant funded by the Korea government(MSIT) (No. NRF-2021R1A2B5B03001551, 35%) + +# References + +[1] Jacob Austin, Daniel D Johnson, Jonathan Ho, Daniel Tarlow, and Rianne van den Berg. Structured denoising diffusion models in discrete state-spaces. Advances in Neural Information Processing Systems, 34:17981-17993, 2021. +[2] Jimmy Lei Ba, Jamie Ryan Kiros, and Geoffrey E Hinton. Layer normalization. arXiv preprint arXiv:1607.06450, 2016. +[3] Hangbo Bao, Li Dong, Songhao Piao, and Furu Wei. BEit: BERT pre-training of image transformers. In International Conference on Learning Representations, 2022. +[4] Sam Bond-Taylor, Peter Hessey, Hiroshi Sasaki, Toby P Breckon, and Chris G Willcocks. Unleashing transformers: Parallel token prediction with discrete absorbing diffusion for fast high-resolution image generation from vector-quantized codes. arXiv preprint arXiv:2111.12701, 2021. +[5] Andrew Brock, Jeff Donahue, and Karen Simonyan. Large scale GAN training for high fidelity natural image synthesis. In International Conference on Learning Representations, 2019. +[6] Huiwen Chang, Han Zhang, Lu Jiang, Ce Liu, and William T. Freeman. Maskgit: Masked generative image transformer. In The IEEE Conference on Computer Vision and Pattern Recognition (CVPR), June 2022. +[7] Jia Deng, Wei Dong, Richard Socher, Li-Jia Li, Kai Li, and Li Fei-Fei. Imagenet: A large-scale hierarchical image database. In 2009 IEEE conference on computer vision and pattern recognition, pages 248–255. IEEE, 2009. +[8] Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. Bert: Pre-training of deep bidirectional transformers for language understanding. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers), pages 4171–4186, 2019. +[9] Prafulla Dhariwal and Alexander Nichol. Diffusion models beat gans on image synthesis. Advances in Neural Information Processing Systems, 34, 2021. + +[10] Ming Ding, Zhuoyi Yang, Wenyi Hong, Wendi Zheng, Chang Zhou, Da Yin, Junyang Lin, Xu Zou, Zhou Shao, Hongxia Yang, et al. Cogview: Mastering text-to-image generation via transformers. Advances in Neural Information Processing Systems, 34, 2021. +[11] Alexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn, Xiaohua Zhai, Thomas Unterthiner, Mostafa Dehghani, Matthias Minderer, Georg Heigold, Sylvain Gelly, et al. An image is worth 16x16 words: Transformers for image recognition at scale. arXiv preprint arXiv:2010.11929, 2020. +[12] Patrick Esser, Robin Rombach, Andreas Blattmann, and Bjorn Ommer. Imagebart: Bidirectional context with multinomial diffusion for autoregressive image synthesis. Advances in Neural Information Processing Systems, 34, 2021. +[13] Patrick Esser, Robin Rombach, and Bjorn Ommer. Taming transformers for high-resolution image synthesis. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 12873-12883, 2021. +[14] Marjan Ghazvininejad, Omer Levy, Yinhan Liu, and Luke Zettlemoyer. Mask-predict: Parallel decoding of conditional masked language models. In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP), pages 6112-6121, 2019. +[15] Shuyang Gu, Dong Chen, Jianmin Bao, Fang Wen, Bo Zhang, Dongdong Chen, Lu Yuan, and Baining Guo. Vector quantized diffusion model for text-to-image synthesis. In The IEEE Conference on Computer Vision and Pattern Recognition (CVPR), June 2022. +[16] Ligong Han, Jian Ren, Hsin-Ying Lee, Francesco Barbieri, Kyle Olszewski, Shervin Minaee, Dimitris Metaxas, and Sergey Tulyakov. Show me what and tell me how: Video synthesis via multimodal conditioning. In The IEEE Conference on Computer Vision and Pattern Recognition (CVPR), June 2022. +[17] Kaiming He, Xinlei Chen, Saining Xie, Yanghao Li, Piotr Dólár, and Ross Girshick. Masked autoencoders are scalable vision learners. arXiv preprint arXiv:2111.06377, 2021. +[18] Martin Heusel, Hubert Ramsauer, Thomas Unterthiner, Bernhard Nessler, and Sepp Hochreiter. Gans trained by a two time-scale update rule converge to a local nash equilibrium. Advances in neural information processing systems, 30, 2017. +[19] Geoffrey Hinton, Oriol Vinyals, Jeff Dean, et al. Distilling the knowledge in a neural network. arXiv preprint arXiv:1503.02531, 2(7), 2015. +[20] Jonathan Ho and Tim Salimans. Classifier-free diffusion guidance. In NeurIPS 2021 Workshop on Deep Generative Models and Downstream Applications, 2021. +[21] Saehoon Kim, Sungwoong Kim, and Juho Lee. Hybrid generative-contrastive representation learning. arXiv preprint arXiv:2106.06162, 2021. +[22] Tuomas Kynkänniemi, Tero Karras, Samuli Laine, Jaakko Lehtinen, and Timo Aila. Improved precision and recall metric for assessing generative models. In H. Wallach, H. Larochelle, A. Beygelzimer, F. d'Alché-Buc, E. Fox, and R. Garnett, editors, Advances in Neural Information Processing Systems, volume 32. Curran Associates, Inc., 2019. +[23] Doyup Lee, Chiheon Kim, Saehoon Kim, Minsu Cho, and Wook-Shin Han. Autoregressive image generation using residual quantization. In The IEEE Conference on Computer Vision and Pattern Recognition (CVPR), June 2022. +[24] Alexander Quinn Nichol and Prafulla Dhariwal. Improved denoising diffusion probabilistic models. In International Conference on Machine Learning, pages 8162-8171. PMLR, 2021. +[25] Alec Radford, Jong Wook Kim, Chris Hallacy, Aditya Ramesh, Gabriel Goh, Sandhini Agarwal, Girish Sastry, Amanda Askell, Pamela Mishkin, Jack Clark, Gretchen Krueger, and Ilya Sutskever. Learning transferable visual models from natural language supervision. In Marina Meila and Tong Zhang, editors, Proceedings of the 38th International Conference on Machine Learning, volume 139 of Proceedings of Machine Learning Research, pages 8748-8763. PMLR, 18-24 Jul 2021. + +[26] Aditya Ramesh, Mikhail Pavlov, Gabriel Goh, Scott Gray, Chelsea Voss, Alec Radford, Mark Chen, and Ilya Sutskever. Zero-shot text-to-image generation. In Marina Meila and Tong Zhang, editors, Proceedings of the 38th International Conference on Machine Learning, volume 139 of Proceedings of Machine Learning Research, pages 8821-8831. PMLR, 18-24 Jul 2021. +[27] Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, and Björn Ommer. High-resolution image synthesis with latent diffusion models, 2021. +[28] Tim Salimans, Ian Goodfellow, Wojciech Zaremba, Vicki Cheung, Alec Radford, Xi Chen, and Xi Chen. Improved techniques for training gans. In D. Lee, M. Sugiyama, U. Luxburg, I. Guyon, and R. Garnett, editors, Advances in Neural Information Processing Systems, volume 29. Curran Associates, Inc., 2016. +[29] Axel Sauer, Katja Schwarz, and Andreas Geiger. Stylegan-xl: Scaling stylegan to large diverse datasets. arXiv preprint arXiv:2202.00273, 2022. +[30] Nikolay Savinov, Junyoung Chung, Mikolaj Binkowski, Erich Elsen, and Aaron van den Oord. Step-unrolled denoising autoencoders for text generation. In International Conference on Learning Representations, 2022. +[31] Rico Senrich, Barry Haddow, and Alexandra Birch. Neural machine translation of rare words with subword units. In Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 1715-1725, 2016. +[32] Piyush Sharma, Nan Ding, Sebastian Goodman, and Radu Soricut. Conceptual captions: A cleaned, hypernymed, image alt-text dataset for automatic image captioning. In Proceedings of the 56th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 2556–2565, Melbourne, Australia, July 2018. Association for Computational Linguistics. +[33] Aaron van den Oord, Oriol Vinyals, and koray kavukcuoglu. Neural discrete representation learning. In I. Guyon, U. V. Luxburg, S. Bengio, H. Wallach, R. Fergus, S. Vishwanathan, and R. Garnett, editors, Advances in Neural Information Processing Systems, volume 30. Curran Associates, Inc., 2017. +[34] Thomas Wolf, Lysandre Debut, Victor Sanh, Julien Chaumont, Clement Delangue, Anthony Moi, Pierrick Cistac, Tim Rault, Rémi Louf, Morgan Funtowicz, Joe Davison, Sam Shleifer, Patrick von Platen, Clara Ma, Yacine Jernite, Julien Plu, Canwen Xu, Teven Le Scao, Sylvain Gugger, Mariama Drame, Quentin Lhoest, and Alexander M. Rush. Transformers: State-of-the-art natural language processing. In Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing: System Demonstrations, pages 38-45, Online, October 2020. Association for Computational Linguistics. +[35] Zhu Zhang, Jianxin Ma, Chang Zhou, Rui Men, Zhikang Li, Ming Ding, Jie Tang, Jingren Zhou, and Hongxia Yang. UFC-BERT: Unifying multi-modal controls for conditional image synthesis. In A. Beygelzimer, Y. Dauphin, P. Liang, and J. Wortman Vaughan, editors, Advances in Neural Information Processing Systems, 2021. \ No newline at end of file diff --git a/draftandreviseeffectiveimagegenerationwithcontextualrqtransformer/images.zip b/draftandreviseeffectiveimagegenerationwithcontextualrqtransformer/images.zip new file mode 100644 index 0000000000000000000000000000000000000000..6df968cb0739cb730bafeac2bdb5510f4eca2fb5 --- /dev/null +++ b/draftandreviseeffectiveimagegenerationwithcontextualrqtransformer/images.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:00ad02b71ecb7af546fa896c6cbaa4a9a304e5eec1293be2d80a3560001da0da +size 502407 diff --git a/draftandreviseeffectiveimagegenerationwithcontextualrqtransformer/layout.json b/draftandreviseeffectiveimagegenerationwithcontextualrqtransformer/layout.json new file mode 100644 index 0000000000000000000000000000000000000000..d71cb8704cbdd48726e41119aa3b1d0e554d4681 --- /dev/null +++ b/draftandreviseeffectiveimagegenerationwithcontextualrqtransformer/layout.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6ae9d7d7971b0b30b59c249fad1c3f06daed06d0d62080ac2d9df65748243161 +size 434228 diff --git a/drawingoutofdistributionwithneurosymbolicgenerativemodels/005c4d28-ffc7-46e2-81d4-52d16d0e294e_content_list.json b/drawingoutofdistributionwithneurosymbolicgenerativemodels/005c4d28-ffc7-46e2-81d4-52d16d0e294e_content_list.json new file mode 100644 index 0000000000000000000000000000000000000000..0380b1239a0da917c0e1f83f8a105fe6cb349748 --- /dev/null +++ b/drawingoutofdistributionwithneurosymbolicgenerativemodels/005c4d28-ffc7-46e2-81d4-52d16d0e294e_content_list.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:433c59c59af53e1c7d1a79a27612dc4b1359b59412cce5edc7fbec0ef5a443be +size 65386 diff --git a/drawingoutofdistributionwithneurosymbolicgenerativemodels/005c4d28-ffc7-46e2-81d4-52d16d0e294e_model.json b/drawingoutofdistributionwithneurosymbolicgenerativemodels/005c4d28-ffc7-46e2-81d4-52d16d0e294e_model.json new file mode 100644 index 0000000000000000000000000000000000000000..4b3cd5172b9654ddd2d8535e14e8b7237893fbda --- /dev/null +++ b/drawingoutofdistributionwithneurosymbolicgenerativemodels/005c4d28-ffc7-46e2-81d4-52d16d0e294e_model.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bbdb3aad97605af8d133a98134f942fff6de43fe21153eb58b5a7da5b51cf291 +size 77714 diff --git a/drawingoutofdistributionwithneurosymbolicgenerativemodels/005c4d28-ffc7-46e2-81d4-52d16d0e294e_origin.pdf b/drawingoutofdistributionwithneurosymbolicgenerativemodels/005c4d28-ffc7-46e2-81d4-52d16d0e294e_origin.pdf new file mode 100644 index 0000000000000000000000000000000000000000..07584377f1c71a611e66b808661fe0aadaab3470 --- /dev/null +++ b/drawingoutofdistributionwithneurosymbolicgenerativemodels/005c4d28-ffc7-46e2-81d4-52d16d0e294e_origin.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:69979fddd8e6665df7e574a09c8e09e71ac4db51e4afeb4745684709e24929d8 +size 4266154 diff --git a/drawingoutofdistributionwithneurosymbolicgenerativemodels/full.md b/drawingoutofdistributionwithneurosymbolicgenerativemodels/full.md new file mode 100644 index 0000000000000000000000000000000000000000..a3be5bf6e521ca5811f8e1ae66f5580d289fb109 --- /dev/null +++ b/drawingoutofdistributionwithneurosymbolicgenerativemodels/full.md @@ -0,0 +1,245 @@ +# Drawing out of Distribution with Neuro-Symbolic Generative Models + +Yichao Liang $^{1,2}$ , Joshua B. Tenenbaum $^{2}$ , Tuan Anh Le $^{*,3}$ & N. Siddharth $^{*,4}$ + +1University of Oxford, 2MIT, 3Google, 4University of Edinburgh + +# Abstract + +Learning general-purpose representations from perceptual inputs is a hallmark of human intelligence. For example, people can write out numbers or characters, or even draw doodles, by characterizing these tasks as different instantiations of the same generic underlying process—compositional arrangements of different forms of pen strokes. Crucially, learning to do one task, say writing, implies reasonable competence at another, say drawing, on account of this shared process. We present Drawing out of Distribution (DooD), a neuro-symbolic generative model of stroke-based drawing that can learn such general-purpose representations. In contrast to prior work, DooD operates directly on images, requires no supervision or expensive test-time inference, and performs unsupervised amortised inference with a symbolic stroke model that better enables both interpretability and generalization. We evaluate DooD on its ability to generalise across both data and tasks. We first perform zero-shot transfer from one dataset (e.g. MNIST) to another (e.g. Quickdraw), across five different datasets, and show that DooD clearly outperforms different baselines. An analysis of the learnt representations further highlights the benefits of adopting a symbolic stroke model. We then adopt a subset of the Omniglot challenge tasks, and evaluate its ability to generate new exemplars (both unconditionally and conditionally), and perform one-shot classification, showing that DooD matches the state of the art. Taken together, we demonstrate that DooD does indeed capture general-purpose representations across both data and task, and takes a further step towards building general and robust concept-learning systems. + +# 1 Introduction + +Humans can learn representations of data that are general-purpose and meaningful. Being general-purpose permits effective reuse when characterizing novel observations, and being meaningful facilitates tasks like generating or classifying observations. Key to this is a generic process for characterizing observations—inferring what features are relevant and how they compose to generate the observations [9, 13, 33]. For example, when observing handwritten numbers, we learn to characterise them as sequential compositions (how) of different pen strokes (what). This is general-purpose as it allows characterizing novel observations, say doodles instead of numbers, simply as novel compositions of previously learnt pen strokes. It is also meaningful since pen-strokes themselves are symbolic and interpretable. + +![](images/2e5adfac8142b1de0ae09be6206d98888f2d23279671148f96d32ca5640d5f5f.jpg) +Figure 1: DooD trained on MNIST generalises to other data with no extra training. Each column denotes a target and its step-by-step reconstruction. + +Current computational approaches capture important aspects of generalizability, but none of these is simultaneously efficient, reliable, interpretable, and unsupervised [25]. At one end, symbolic approaches like Lake et al. [24] attribute generalization to an explicit hierarchical composition process involving sub-strokes, strokes, and characters, and build concomitant models that demonstrate human-like generalization abilities across different tasks. At the other end, neural approaches like deep generative models [9, 18, 29] and deep meta-learning [11, 32, 34] favour scalable learning from raw + +![](images/711f37b4c36bcf2f56f7051c91feb0406983a67f84d66148f2c4a10b9525bc2c.jpg) +Figure 2: The generative model sequentially samples both an image location $(l_{t})$ and a corresponding stroke $(s_t)$ at that location. The rendered stroke $x_{t}$ is composited onto intermediate rendering $x_{< t}$ to produce $x_{\leq t}$ . A binary on/off variable $(o_{t})$ determines when to continue drawing. Differentiable rendering $(\delta \bar{R})$ and differentiable affine transformations via Spatial Transformer Networks (STNs) [20] enables gradient-based learning. The recognition model conditions on a residual $\Delta x_{t} = x - x_{< t}$ to sample where to draw next $(l_{t})$ and what to draw next $(s_{t})$ , and whether to continue drawing $(o_{t})$ . Both models are autoregressive via two (shared) RNNs with hidden states $h_t^s$ and $h_t^l$ . + +![](images/c8b9b694abb1b8ca7ff73fee61ccc623499e7db574d4f45b5815d671293e89bb.jpg) + +![](images/6dbf7038bacb56e14bd08f65080a87782b269cd3fa7810c85be0bd6dd1b7d01d.jpg) + +perceptual data, unfettered by explicit representational biases such as strokes and their compositions. Each comes with its own shortcomings—symbolic approaches typically need additional supervision or data processing along with expensive special-purpose inference, and neural approaches fail to generalise well and don't capture interpretable representations. Neuro-symbolic approaches [10] seek to make the best of both worlds by judiciously combining neural processing of raw perceptual inputs with symbolic processing of extracted features, but typically involve a different set of trade-offs. + +We present Drawing out of Distribution (DooD), a neuro-symbolic generative model of stroke-based drawing that can learn general-purpose representations (Fig. 1). Our model operates directly on images, requires no supervision, pre-processing, or expensive test-time inference, and performs efficient amortised inference with a symbolic stroke model that helps with both interpretability and generalization, setting us apart from the current state-of-the-art in neuro-symbolic approaches [10, 17]. We evaluate on two axes (a) generalization across data, which measures how well the learnt representations can be reused to characterise out-of-distribution data, and (b) generalization across task, where we measure how useful the learnt representations are for auxiliary tasks drawn from the Omniglot challenge set [24]. We show that DooD significantly outperforms baselines on generalization across datasets, highlighting the quality of the learnt representations as a factor, and on generalization across tasks, show that it outperforms neural models, while being competitive against SOTA neuro-symbolic models without requiring additional support such as supervision or data augmentation. + +# 2 Method + +The framework for DooD involves a generative model over sequences of strokes and their layouts, a recognition model that conditions on a given observation to predict where to place what strokes, and an amortised variational-inference learning setup that uses these models to estimate an evidence lower bound (ELBO) as the objective. + +# 2.1 Generative Model + +Conceptually, the model can be seen as drawing a figure over a sequence of steps, building up to the final image (as seen in Fig. 1). At each step $t$ the model identifies a region of the image canvas to draw in, puts down Bezier curve control points within that region, renders the curve in a differentiable manner, and then composites this rendered stroke over the previously rendered canvas. We refer to these as the layout, stroke, rendering, and compositing modules respectively (elaborated below). + +The model sits on a substrate of recurrent neural networks (RNNs), one each for the layout and stroke modules, with hidden states $h_t^l$ and $h_t^s$ respectively. The complete setup is depicted in Fig. 2 along with example values (images) for the different variables involved. See Appendix B for details. + +Formally, the generative model defines a joint distribution over an image $x$ composed over $T$ steps, with latent variables $l_{t}$ and $s_t$ that characterise a stroke's location and form, and a binary latent variable $o_{t}$ that determines stopping, as + +$$ +\begin{array}{l} p (x, l _ {\leq T}, s _ {\leq T}, o _ {\leq T + 1}) \\ = \left(\prod_ {t = 1} ^ {T} p _ {\text {o n}} \left(o _ {t} \mid x _ {< t}\right) p _ {\text {s t r o k e}} \left(s _ {t} \mid l _ {t}, \tilde {x} _ {< t}, h _ {t} ^ {s}\right) p _ {\text {l a y o u t}} \left(l _ {t} \mid x _ {< t}, h _ {t} ^ {l}\right)\right) p _ {\text {c o m p}} \left(x \mid x _ {\leq T}\right) p _ {\text {o n}} \left(o _ {T + 1} \mid x _ {\leq T}\right), \tag {1} \\ \end{array} +$$ + +where terminal step $T$ is the last $t$ where $o_{t} = 1$ , $x_{t}$ the rendered stroke given $(s_{t},l_{t})$ , $x_{