Semi-Parametric Neural Image Synthesis
Abstract
Novel architectures have recently improved generative image synthesis leading to excellent visual quality in various tasks.
Much of this success is due to the scalability of these architectures and hence caused by a dramatic increase in model complexity and in the computational resources invested in training these models.
Our work questions the underlying paradigm of compressing large training data into ever growing parametric representations.
We rather present an orthogonal, semiparametric approach.
We complement comparably small diffusion or autoregressive models with a separate image database and a retrieval strategy.
During training we retrieve a set of nearest neighbors from this external database for each training instance and condition the generative model on these informative samples.
While the retrieval approach is providing the (local) content, the model is focusing on learning the composition of scenes based on this content.
As demonstrated by our experiments, simply swapping the database for one with different contents transfers a trained model post-hoc to a novel domain.
The evaluation shows competitive performance on tasks which the generative model has not been trained on, such as class-conditional synthesis, zero-shot stylization or text-to-image synthesis without requiring paired text-image data.
With negligible memory and computational overhead for the external database and retrieval we can signiﬁcantly reduce the parameter count of the generative model and still outperform the state-of-the-art.
Introduction
Deep generative modeling has made tremendous leaps; especially in language modeling as well as in generative synthesis of high-ﬁdelity images and other data types.
In particular for images, astounding results have recently been achieved [22, 15, 56, 59] and three main factors can be identiﬁed as the driving forces behind this progress: First, the success of the transformer [88] has caused an architectural revolution in many vision tasks [19], for image synthesis especially through its combination with autoregressive modeling [22, 58].
Second, since their rediscovery, diffusion models have been applied to high-resolution image generation [76, 78, 33] and, within a very short time, set new standards in generative image modeling [15, 34, 63, 59].
Third, these approaches scale well [58, 59, 37, 81]; in particular when considering the model- and batch sizes involved for high-quality models [15, 56, 58, 59] there is evidence that this scalability is of central importance for their performance.
However, the driving force underlying this training paradigm are models with ever growing numbers of parameters [81] that require huge computational resources.
Besides the enormous demands in energy consumption and training time, this paradigm renders future generative modeling more and more exclusive to privileged institutions, thus hindering the democratization of research.
Therefore, we here present an orthogonal approach.
Inspired by recent advances in retrieval-augmented NLP [4, 89], we question the prevalent approach of expensively compressing visual concepts shared between distinct
’Apurplesalamanderinthegrass.’ ’
Azebra-skinnedpanda.’ ’
Ateddybear ridingamotorcycle.’ ’
Imageofamonkey withthefurofaleopard.’
[Figure]
training examples into large numbers of trainable parameters and equip a comparably small generative model with a large image database.
During training, our resulting semi-parametric generative models access this database via a nearest neighbor lookup and, thus, need not learn to generate data ’from scratch’.
Instead, they learn to compose new scenes based on retrieved visual instances.
This property not only increases generative performance with reduced parameter count (see Fig. 1), and lowers compute requirements during training.
Our proposed approach also enables the models during inference to generalize to new knowledge in form of alternative image databases without requiring further training, what can be interpreted as a form of post-hoc model modiﬁcation [4].
We show this by replacing the retrieval database with the WikiArt [66] dataset after training, thus applying the model to zero-shot stylization.
Furthermore, our approach is formulated indepently of the underlying generative model, allowing us to present both retrieval-augmented diffusion ( RDM ) and autoregressive ( RARM ) models.
By searching in and conditioning on the latent space of CLIP [57] and using scaNN [28] for the NNsearch, the retrieval causes negligible overheads in training/inference time (0.95 ms to retrievenearest neighbors from a database of 20M examples) and storage space (2GB per 1M examples).
We show that semi-parametric models yield high ﬁdelity and diverse samples: RDM surpasses recent state-of-the-art diffusion models in terms of FID and diversity while requiring less trainable parameters.
Furthermore, the shared image-text feature space of CLIP allows for various conditional applications such as text-to-image or class-conditional synthesis, despite being trained on images only (as demonstrated in Fig. 2).
Finally, we present additional truncation strategies to control the synthesis process which can be combined with model speciﬁc sampling techniques such as classiﬁer-free guidance for diffusion models [32] or top- k sampling [23] for autoregressive models.
Related Work
Generative Models for Image Synthesis.
Generating high quality novel images has long been a challenge for deep learning community due to their high dimensional nature.
Generative adversarial networks (GANs) [25] excel at synthesizing such high resolution images with outstanding quality [5, 39, 40, 70] while optimizing their training objective requires some sort of tricks [1, 27, 54, 53] and their samples suffer from the lack of diversity [80, 1, 55, 50].
On the contrary, likelihood-based methods have better training properties and they are easier to optimize thanks to their ability to capture the full data distribution.
While failing to achieve the image ﬁdelity of GANs, variational autoencoders (VAEs) [43, 61] and ﬂow-based methods [16, 17] facilitate high resolution image generation with fast sampling speed [84, 45].
Autoregressive models (ARMs) [10, 85, 87, 68] succeed in density estimation like the other likelihood-based methods, albeit at the expense of computational efﬁciency.
Starting with the seminal works of Sohl-Dickstein et al.
[76] and Ho et al.
[33], diffusion-based generative models have improved generative modeling of artiﬁcial visual systems [15, 44, 90, 35, 92, 65].
Their good performance, however, comes at the expense of high training costs and slow sampling.
To circumvent the drawbacks of ARMs and diffusion models, several two-stage models are proposed to scale them to higher resolutions by training them on the compressed image features [86, 60, 22, 93, 63, 75, 21].
However, they still require large models and signiﬁcant compute resources, especially for unconditional image generation [15] on complex datasets like ImageNet [13] or complex conditional tasks such as text-to-image generation [56, 58, 26, 63].
To address these issues, given limited compute resources we propose to trade trainable parameters for an external memory which empowers smaller models to achieve high ﬁdelity image generation.
Retrieval-Augmented Generative Models.
Using external memory to augment traditional models has recently drawn attention in natural language processing (NLP)
For example,
RETRO [4] proposes a retrieval-enhanced transformer for language modeling which performs on par with state-of-the-art models [6] using signiﬁcantly less parameters and compute resources.
These retrieval-augmented models with external memory turn purely parametric deep learning models into semi-parametric ones.
Early attempts [51, 74, 83, 91] in retrieval-augmented visual models do not use an external memory and exploit the training data itself for retrieval.
In image synthesis, IC-GAN [8] utilizes the neighborhood of training images to train a GAN and generates samples by conditioning on single instances from the training data.
However, using training data itself for retrieval potentially limits the generalization capacity, and thus, we favor an external memory in this work.
Image Synthesis with Retrieval-Augmented Generative Models
Our work considers data points as an explicit part of the model .
In contrast to common neural generative approaches for image synthesis [5, 40, 70, 60, 22, 10, 9], this approach is not only parameterized by the learnable weights of a neural network, but also a (ﬁxed) set of data representations and a non-learnable retrieval function, which, given a query from the training data, retrieves suitable data representations from the external dataset.
Following prior work in natural language modeling [4], we implement this retrieval pipeline as a nearest neighbor lookup.
Sec. 3.1 and Sec.
3.2 formalize this approach for training retrieval-augmented diffusion and autoregressive models for image synthesis, while Sec.
3.3 introduces sampling mechanisms that become available once such a model is trained.
Fig.
3 provides an overview over our approach.
3.1 Retrieval-Enhanced Generative Models of Images
Unlike common, fully parametric neural generative approaches for images, we deﬁne a semiparametric generative image model p θ, D ,ξ k ( x ) by introducing trainable parameters θ and nontrainable model components D , ξ k , where D =
{ y i } Ni =1 is a ﬁxed database of images y i ∈
R H D × W D × 3 that is disjoint from our train data X .
Further, ξ k denotes a (non-trainable) sampling strategy to obtain a subset of D based on a query x , i.e. ξ k : x, D (cid:55)→ M ( k ) D , where M ( k ) D ⊆ D and |M ( k ) D | = k .
Thus, only θ is actually learned during training.
Importantly, ξ k ( x, D ) has to be chosen such that it provides the model with beneﬁcial visual representations from D for modeling x and the entire capacity of θ can be leveraged to compose consistent scenes based on these patterns.
For instance, considering query images x ∈ R H x × W x × 3 , a valid strategy ξ k ( x, D ) is a function that for each x returns the set of its k nearest neighbors, measured by a given distance function d ( x, · ) .
Next, we propose to provide this retrieved information to the model via conditioning , i.e. we specify a general semi-parametric generative model as
[Equation]
In principle, one could directly use image samples y ∈ M ( k ) D to learn θ .
However, since images contain many ambiguities and their high dimensionality involves considerable computational and storage cost 2 we use a ﬁxed , pre-trained image encoder φ to project all examples from M ( k ) D onto a low-dimensional manifold.
Hence, Eq.
(1) reads
[Equation]
where p θ ( x |· ) is a conditional generative model with trainable parameters θ which we refer to as decoding head .
With this, the above procedure can be applied to any type of generative decoding head and is not dependent on its concrete training procedure.
3.2 Instances of Semi-Parametric Generative Image Models
During training we are given a train dataset X =
{ x i } Mi =1 of images whose distribution p ( x ) we want to approximate with p θ, D ,ξ k ( x ) .
Our train-time sampling strategy ξ k uses a query example x ∼ p ( x ) to retrieve its k nearest neighbors y ∈ D by implementing d ( x, y ) as the cosine similarity in the image feature space of CLIP [57].
Given a sufﬁciently large database D , this strategy ensures that the set of neighbors ξ k ( x, D ) shares sufﬁcient information with x and, thus, provides useful visual information for the generative task.
We choose CLIP to implement ξ k , because it embeds images in a low dimensional space ( dim = 512 ) and maps semantically similar samples to the same neighborhood, yielding an efﬁcient search space.
Fig.
4 visualizes examples of nearest neighbors retrieved via a ViT-B/32 vision transformer [19] backbone.
[Figure]
Note that this approach can, in principle, turn any generative model into a semi-parametric model in the sense of Eq.
In this work we focus on models where the decoding head is either implemented as a diffusion or an autoregressive model, motivated by the success of these models in image synthesis [33, 15, 63, 56, 58, 22].
To obtain the image representations via φ , different encoding models are conceivable in principle.
Again, the latent space of CLIP offers some advantages since it is (i) very compact, which (ii) also reduces memory requirements.
Moreover, the contrastive pretraining objective (iii) provides a shared space of image and text representations, which is beneﬁcial for text-image synthesis, as we show in
Sec. 4.2.
Unless otherwise speciﬁed, φ ≡ φ CLIP is set in the following.
We investigate alternative parameterizations of φ in Sec.
E.2. Note that with this choice, the additional database D can also be interpreted as a ﬁxed embedding layer 3 of dimensionality |D|× 512 from which the nearest neighbors are retrieved.
3.2.1 Retrieval-Augmented Diffusion Models
In order to reduce computational complexity and memory requirements during training, we follow [63] and build on latent diffusion models (LDMs) which learn the data distribution in the latent space z = E ( x ) of a pretrained autoencoder.
We dub this retrieval-augmented latent diffusion model
RDM and train it with the usual reweighted likelihood objective [33], yielding the objective [76, 33] min θ L = E p ( x ) ,
[Equation]
where the expectation is approximated by the empirical mean over training examples.
In the above equation, (cid:15) θ denotes the UNet-based [64] denoising autoencoder as used in [15, 63] and t ∼
Uniform { 1 , . . , T } denotes the time step [76, 33].
To feed the set of nearest neighbor encodings φ CLIP ( y ) into (cid:15) θ , we use the cross-attention conditioning mechanism proposed in [63].
3.2.2 Retrieval-Augmented Autoregressive Models
Our approach is applicable to several types of likelihood-based methods.
We show this by augmenting diffusion models (Sec. 3.2.1) as well as autoregressive models with the retrieved representations.
To implement the latter, we follow [22] and train autoregressive transformer models to model the distribution of the discrete image tokens z q = E ( x ) of a VQGAN [22, 86].
Speciﬁcally, as for RDM , we train retrieval-augmented autoregressive models (RARMs) conditioned on the CLIP embeddings φ CLIP ( y ) of the neighbors y , so that the objective reads
[Equation]
where we choose a row-major ordering for the autoregressive factorization of the latent z q .
We condition the model on the set of neighbor embeddings φ CLIP ( ξ k ( x, D )) via cross-attention [88].
3.3 Inference for Retrieval-Augmented Generative Models
Conditional Synthesis without Conditional Training Being able to change the (non-learned) D and ξ k at test time offers additional ﬂexibility compared to standard generative approaches:
Depending on the application, it is possible to extent/restrict D for particular exemplars; or to skip the retrieval via ξ k altogether and provide a set of representations { φ CLIP ( y i ) } ki =1 directly.
This allows us to use additional conditional information such as a text prompt or a class label, which has not been available during training, to achieve more ﬁne-grained control during synthesis.
For text-to-image generation , for example, our model can be conditioned in several ways: Given a text prompt c text and using the text-to-image retrieval ability of CLIP, we can retrieve k neighbors from D and use these as an implicit text-based conditioning.
However, since we condition on CLIP representations φ CLIP , we can also condition directly on the text embeddings obtained via CLIP’s language backbone (since CLIP’s text-image embedding space is shared).
Accordingly, it is also possible to combine these approaches and use text and image representations simultaneously.
We show and compare the results of using these sampling techniques in Fig.
Given a class label c , we deﬁne a text such as ’An image of a t ( c ) .’
based on its textual description t ( c ) or apply the embedding strategy for text prompts and sample a pool ξ l ( c ) , k ≤ l for each class.
By randomly selecting k adjacent examples from this pool for a given query c , we obtain an inference-time class-conditional model and analyze these post-hoc conditioning methods in Sec. 4.2.
For unconditional generative modeling , we randomly sample a pseudo-query ˜ x ∈ D to obtain the set ξ test k (˜ x, D ) of its k nearest neighbors.
Given this set, Eq. (2) can be used to draw samples, since p θ ( x |· ) itself is a generative model.
However, when generating all samples from p θ, D ,ξ k ( x ) only from one particular set ξ test k (˜ x ) , we expect p θ, D ,ξ k ( x ) to be unimodal and sharply peaked around ˜ x .
When intending to model a complex multimodal distribution p ( x ) of natural images, this choice would obviously lead to weak results.
Therefore, we construct a proposal distribution based on D where
[Equation]
This deﬁnition counts the instances in the database D which are useful for modeling the training dataset X .
Note that p D (˜ x ) only depends on X and D , what allows us to precompute it.
Given p D (˜ x ) , we can obtain a set
[Equation]
of samples from the our model.
We can thus draw from the unconditional modeled density p θ, D ,ξ k ( x ) by drawing x ∼ Uniform ( P ) .
By choosing only a fraction m ∈ (0 , 1] of most likely examples ˜ x ∼ p D (˜ x ) , we can artiﬁcially truncate this distribution and trade sample quality for diversity.
See Sec. D.1. for a detailed description of this mechanism which we call top-m sampling and Sec.
4.5 for an empirical demonstration.
[Figure]
Experiments
This section presents experiments for both retrieval-augmented diffusion and autoregressive models.
To obtain nearest neighbors we apply the ScaNN search algorithm [28] in the feature space of a pretrained CLIP-ViT-B/32 [57].
Using this setting, retrieving 20 nearest neighbors from the database described above takes ∼ 0 . 95 ms.
For more details on our retrieval implementation, see Sec. F.1.
For quantitative performance measures we use FID [31], CLIP-FID [48], Inception Score (IS) [67] and Precision-Recall [47], and, for the diffusion models, generate samples with the DDIM sampler [77] with 100 steps and η = 1 .
For hyperparameters, implementation and evaluation details cf.
Sec. F.
4.1 Semi-Parametric Image Generation
Drawing pseudo-queries from the proposal distribution proposed in Sec.
3.3 and Eq.
(6) enables semi-parametric unconditional image generation.
However, before the actual application, we compare different choices of the database D train used during training and determine an appropriate choice for the value k of the retrieved neighbors during training.
Finding a train-time database D train .
Key to a successful application of semi-parametric models is choosing an appropriate train database D train , as it has to provide the generative backbone p θ with useful information.
We hypothesize that a large database with diverse visual instances is most useful for the model, since the probability of ﬁnding nearby neighbors in D train for every train example is highest for this choice. To verify this claim, we compare the visual quality and sample diversity of three RDMs trained on the dogs-subset of ImageNet [13] with i) WikiArt [66] ( RDM-WA ), ii) MS-COCO [7] ( RDM-COCO ) and iii) 20M examples obtained by cropping images (see App. F.1) from OpenImages [46] ( RDM-OI ) as train database D train with that of an LDM baseline with 1.3 × more parameters.
Fig 6 shows that i) a database D train , whose examples are from a different domain than those of the train set X leads to degraded sample quality, whereas ii) a small database from the same domain as X improves performance compared to the LDM baseline.
Finally, iii) increasing the size of D train further boosts performance in quality and diversity metrics and leads to signiﬁcant improvements of RDMs compared to LDMs .
[Table]
For the above experiment we used D train ∩ X = ∅ .
This is in contrast to prior work [8] which conditions a generative model on the train dataset itself, i.e., D train =
X .
Our choice is motivated by the aim to obtain a model as general as possible which can be used for more than one task during inference, as introduced in Sec. 3.3.
To show the beneﬁts of using D train ∩ X = ∅ we use
ImageNet [13] as train set X and compare RDM-OI with an RDM conditioned on X itself ( RDMIN ).
We evaluate their performance on the ImageNet train- and validation-sets in Tab. 1, which shows RDM-OI to closely reach the performance of RDM-IN in CLIP-FID [48] and achieve more diverse results.
When interchanging the test-time database between the two models, i.e., conditioning
RDM-OI on examples from ImageNet ( RDM-OI/IN ) and vice versa ( RDM-IN/OI )
we observe strong performance degradation of the latter model, whereas the former improves in most metrics and outperforms RDM-IN in CLIP-FID, thus showing the enhanced generalization capabilities when choosing D train ∩ X = ∅ .
To provide further evidence of this property we additionally evaluate the models on zero-shot text-conditional on the COCO dataset [7] in Tab. 1.
Again, we observe better image quality (FID) as well as image-text alignment (CLIP-score) of RDM-OI which furthermore outperforms LAFITE [94] in FID, despite being trained on only a third of the train examples.
How many neighbors to retrieve during training?
As the number k train of retrieved nearest neighbors during training has a strong inﬂuence on the properties of the resulting model after training, we ﬁrst identify hyperparameters obtain a model with optimal synthesis properties.
Hence, we parameterize p θ with a diffusion model and train ﬁve models for different k train ∈ { 1 , 2 , 4 , 8 , 16 } on ImageNet [13].
All models use identical generative backbones and computational resources (details in Sec. F.2.1). Fig.
7 shows resulting performance metrics assessed on 1000 samples.
For FID and IS we do not observe signiﬁcant trends.
Considering precision and recall, however, we see that increasing k train trades consistency for diversity.
Large k train causes recall, i.e. sample diversity, to deteriorate again.
We attribute this to a regularizing inﬂuence of non-redundant, additional information beyond the single nearest neighbor, which is fed to the respective model during training, when k train > 1 .
For k train ∈ { 2 , 4 , 8 } this additional information is beneﬁcial and the corresponding models appropriately mediate between quality and diversity.
Thus, we use k = 4 for our main RDM .
Furthermore, the numbers of neighbors has a signiﬁcant effect on the generalization capabilities of our model for conditional synthesis, e.g. text-to-image synthesis as in Fig.
We provide an in-depth evaluation of this effect in Sec.
and conduct a similar study for RARM in Sec. E.4.
Qualitative results.
Fig.
5 shows samples of RDM / RARM trained on ImageNet as well as
RDM samples on FFHQ [38] for different sets M ( k ) D (˜ x ) of retrieved neighbors given a pseudoquery ˜ x ∼ p D (˜ x ) .
We also plot the nearest neighbors from the train set to show that this set is disjoint from the database D and that our model renders new, unseen samples.
Quantitative results.
Tab. 2 compares our model with the recent state-of-the-art diffusion model
ADM [15] and the semi-parametric GAN-based model IC-GAN [8] (which requires access to the training set examples during inference) in unconditional image synthesis on ImageNet [13] 256 × 256 .
To boost performance, we use the sampling strategies proposed in Sec.
3.3 (which is also further detailed in Sec. D.1).
With classiﬁer-free guidance (c.f.g.), our model attains better scores than IC-GAN and ADM while being on par with ADM-G [15].
The latter requires an additional classiﬁer and the labels of training instances during inference.
Without any additional information about training data, e.g., image labels, RDM achieves the best overall performance. [Table] [Table]
For m = 0 .
1 , our retrieval-augmented diffusion model surpasses unconditional ADM for FID, IS, precision and, without guidance, for recall.
For s = 1 .
75 , we observe bisected FID scores compared to our unguided model and even reach the guided model ADM-G, which, unlike RDM , requires a classiﬁer that is pre-trained on noisy data representations.
The optimal parameters for FID are m = 0 .
05 , s = 1 . 5 , as in the bottom row of Tab. 2.
Using these parameters for RDM-IN results in a model which even achieves similar FID scores than state of the class-conditional models on ImageNet [63, 15, 70] without requiring any labels during training or inference.
Overall, this shows the strong performance of RDM and the ﬂexibility of top-
m sampling and c.f.g., which we further analyze in Sec. 4.5. Moreover we train an exact replicate of our ImageNet RDM-OI on the FFHQ [38] and summarize the results in Tab.
Since FID [31] has been shown to be “insensitive to the facial region” [48] we again use CLIP-based metrics.
Even for this simple dataset, our retrieval-based strategy proves beneﬁcial, outperforming strong GAN and diffusion baselines, albeit at the cost of lower diversity (recall).
4.2 Conditional Synthesis without Conditional Training
Text-to-Image Synthesis In Fig.
2, we show the zero-shot textto-image synthesis capabilities of our ImageNet model for user deﬁned text prompts.
When building the set M ( k ) D ( c text ) by directly using i) the CLIP encodings φ CLIP ( c text ) of the actual textual description itself (top row), we interestingly see that our model generalizes to generating ﬁctional descriptions and transfers attributions across object classes.
However, when using ii) φ CLIP ( c text ) together with its k − 1 nearest neighbors from the database D as done in [2], the model does not generalize to these difﬁcult conditional inputs (mid row).
When iii) only using the k CLIP image representations of the nearest neighbors, the results are even worse (bottom row).
We evaluate the text-to-image capabilities of RDMs on 30000 examples from the COCO validation set and compare with LAFITE [94].
The latter is also based on CLIP space, but unlike our method, the image features are translated to text features by utilizing a supervised model in order to address the mismatch between CLIP text and image features.
Tab. 1 summarizes the results and shows that our RDM-OI obtains better image quality as measured by the FID score.
Similar to Sec.
4.1 we investigate the inﬂuence of k train on the text-to-image generalization capability of RDM .
To this end we evaluate the zero-shot transferability of the ImageNet models presented in the last section to text-conditional image generation and, using strategy i) from the last paragraph, evaluate their performance on 2000 captions from the validation set of COCO [7].
Fig.
8 compares the resulting FID and CLIP scores on COCO for the different choices of k train .
As a reference for the train performance, we furthermore plot the ImageNet FID.
Similar to Fig.
7 we ﬁnd that small k train lead to weak generalization properties, since the corresponding models cannot handle misalignments between the text representation received during inference and image representations it is trained on.
Increasing k train results in sets M ( k ) D ( x ) which cover a larger feature space volume, what regularizes the corresponding models to be more robust against such misalignments.
Consequently, the generalization abilities increase with k train and reach an optimum at k train = 8 .
Further increasing k train results in decreased information provided via the retrieved neighbors ( cf.
Fig. 4) and causes deteriorating generalization capabilities. [Figure]
r i o r ﬂ o w p r i o r
We note the similarity of this approach to [59], which, by directly conditioning on the CLIP image representations of the data, essentially learns to invert the abstract image embedding.
In our framework, this corresponds to ξ k ( x ) =
φ CLIP ( x ) (i.e., no external database is provided).
In order to ﬁx the misalignment between text embeddings and image embeddings, [59] learns a conditional diffusion model for the generative mapping between these representations, requiring paired data.
We argue that our retrieval-augmented approach provides an orthogonal approach to this task without requiring paired data.
To demonstrate this, we train an “inversion model” as described above, i.e., use ξ k ( x ) =
φ CLIP ( x ) with the same number of trainable parameters and computational budget as for the study in Fig. 8.
When directly using text embeddings for inference, the model renders samples which generally resemble the prompt, but the visual quality is low (CLIP score 0 .
26 ± 0 .
05 , FID ∼ 87 ).
Modeling the prior with a conditional normalizing ﬂow [18, 62] improves the visual quality and achieves similar results in terms of text-consistency (CLIP score 0 .
26 ± 0 .
3 , FID ∼ 45 ), albeit requiring paired data.
See Fig.
9 for a qualitative visualization and Appendix F.2.1 for implementation and training details.
[Figure]
Class-Conditional Synthesis
Similarly we can apply our model to zero-shot class-conditional image synthesis as proposed in Sec. 3.3.
Fig.
10 shows samples from our model for classes from
ImageNet.
More samples for all experiments can be found in Sec. G.
4.3 Zero-Shot Text-Guided Stylization by Exchanging the Database
[Figure]
s t y l e D t r a i n In our semi-parametric model, the retrieval database D is an explicit part of the synthesis model.
This allows novel applications, such as replacing this database after training to modify the model and thus its output.
In this section we replace D train of the ImageNet- RDM built from OpenImages with an alternate database D style , which contains all 138k images of the
WikiArt dataset [66].
As in Sec.
4.2 we retrieve neighbors from D style via a text prompt and use the text-retrieval strategy iii) .
Results are shown in Fig.
11 (top row).
Our model, though only trained on ImageNet, generalizes to this new database and is capable of generating artwork-like images which depict the content deﬁned by the text prompts.
To further emphasize the effects of this post-hoc exchange of
D , we show samples obtained with the same procedure but using D train (bottom row).
4.4 Increasing Dataset Complexity
To investigate their versatility for complex generative tasks, we compare semi-parametric models to their fully-parametric counterparts when systematically increasing the complexity of the training data p ( x ) .
For both RDM and RARM , we train three identical models and corresponding fully parametric baselines (for details cf.
Sec. F.2) on the dogs-, mammals- and animals-subsets of ImageNet [13], cf.
Tab. 7, until convergence.
Fig. 12 visualizes the results.
Even for lower-complexity datasets such as IN-Dogs , our semi-parametric models improve over the baselines except for recall, where RARM performance slightly worse than a standard AR model.
For more complex datasets, the performance gains become more signiﬁcant.
Interestingly, the recall scores of our models improve with increasing complexity, while those of the baselines strongly degrade.
We attribute this to the explicit access of semi-parametric models to nearby visual instances for all classes including underrepresented ones via the p D (˜ x ) , cf.
Eq.
(6), whereas a standard generative model might focus only on the modes containing the most often occurring classes (dogs in the case of ImageNet).
4.5 Quality-Diversity Trade-Offs
Top-m sampling.
In this section, we evaluate the effects of the top-m sampling strategy introduced in
Sec. 3.3.
We train a RDM on the ImageNet [13] dataset and assess the usual generative performance metrics based on 50k generated samples and the entire training set [5].
Results are shown in Fig. 13a.
For precision and recall scores, we observe a truncation behavior similar to other inference-time sampling techniques [5, 15, 32, 23]: For small values of m , we obtain coherent samples, which all come from a single or a small number of modes, as indicated by large precision scores.
Increasing m , on the other hand, boosts diversity at the expense of consistency.
For FID and IS, we ﬁnd a sweet spot for m = 0 . 01 , which yields optima for both of these metrics.
Visual examples for different values of m are shown in the Fig.
Sec. E.5 also contains similar experiments for RARM .
[Figure]
Classiﬁer-free guidance.
Since RDM is a conditional diffusion model (conditioned on the neighbor encodings φ ( y ) ), we can apply classiﬁer-free diffusion guidance [32] also for unconditional modeling.
Interestingly, we ﬁnd that we can apply this technique without adding an additional ∅ -label to account for a purely unconditional setting while training (cid:15) θ , as originally proposed in [32] and instead use a vector of zeros to generate an unconditional prediction with (cid:15) θ .
Additionally, this technique can be combined with top-m sampling to obtain further control during sampling.
In Fig.
13b we show the effects of this combination for the ImageNet-model as described in the previous paragraph, with m ∈ { 0 . 01 , 0 . 1 } and classiﬁer scale s ∈ { 1 . 0 , 1 . 25 , 1 . 5 , 1 . 75 , 2 . 0 , 3 . 0 } , from left to right for each line.
Moreover we qualitatively show the effects of guidance in Fig. 18, demonstrating the versatility of these sampling strategies during inference.
Conclusion
This paper questions the prevalent paradigm of current generative image synthesis: rather than compressing large training data in ever-growing generative models, we have proposed to efﬁciently store an image database and condition a comparably small generative model directly on meaningful samples from the database.
To identify informative samples for the synthesis tasks at hand we follow an efﬁcient retrieval-based approach.
In the experiments our approach has outperformed the state of the art on various synthesis tasks despite demanding signiﬁcantly less memory and compute.
Moreover, it allows (i) conditional synthesis for tasks for which it has not been explicitly trained, and (ii) post-hoc transfer of a model to new domains by simply replacing the retrieval database.
Combined with CLIP’s joint feature space, our model achieves strong results on text-image synthesis, despite being trained only on images.
In particular, our retrieval-based approach eliminates the need to train an explicit generative prior model in the latent CLIP space by directly covering the neighborhood of a given data point.
While we assume that our approach still beneﬁts from scaling, it shows a path to more efﬁciently trained generative models of images.
Acknowledgements
This work has been funded by the Deutsche Forschungsgemeinschaft (DFG, German Research
Foundation) within project 421703927 and the German Federal Ministry for Economic Affairs and
Energy within the project KI-Absicherung - Safe AI for automated driving.