TIVE NETWORK MANIFOLDS WITHOUT RETRAINING
Year: 2021

Abstract:
Deep Generative Networks (DGNs) are extensively employed in Generative Adversarial Networks (GANs), Variational Autoencoders (VAEs), and their variants to approximate the data manifold and distribution. However, training samples are often distributed in a non-uniform fashion on the manifold, due to costs or convenience of collection. For example, the CelebA dataset contains a large fraction of smiling faces. These inconsistencies will be reproduced when sampling from the trained DGN, which is not always preferred, e.g., for fairness or data augmentation. In response, we develop MaGNET, a novel and theoretically motivated latent space sampler for any pre-trained DGN, that produces samples uniformly distributed on the learned manifold. We perform a range of experiments on various datasets and DGNs, e.g., for the state-of-the-art StyleGAN2 trained on FFHQ dataset, uniform sampling via MaGNET increases distribution precision and recall by 4.1% & 3.0% and decreases gender bias by 41.2%, without requiring labels or retraining. As uniform distribution does not imply uniform semantic distribution, we also explore separately how semantic attributes of generated samples vary under MaGNET sampling. Figure 1: Random batches of StyleGAN2 samples with 1024 × 1024 resolution, generated using standard sampling (left), uniform sampling via MaGNET on the learned pixel-space manifold (middle), and uniform sampling on the style-space manifold (right) of the same model. MaGNET sampling yields a higher number of young faces, better gender balance, and greater background/accessory variation, without the need for labels or retraining. Images are sorted by gender-age and color coded red-green (female-male) according to Microsoft Cognitive API predictions. Larger batches of images and attribute distributions are furnished in Appendix E.

text: Deep Generative Networks (DGNs) are extensively employed in Generative Adversarial Networks (GANs), Variational Autoencoders (VAEs), and their variants to approximate the data manifold and distribution. However, training samples are often distributed in a non-uniform fashion on the manifold, due to costs or convenience of collection. For example, the CelebA dataset contains a large fraction of smiling faces. These inconsistencies will be reproduced when sampling from the trained DGN, which is not always preferred, e.g., for fairness or data augmentation. In response, we develop MaGNET, a novel and theoretically motivated latent space sampler for any pre-trained DGN, that produces samples uniformly distributed on the learned manifold. We perform a range of experiments on various datasets and DGNs, e.g., for the state-of-the-art StyleGAN2 trained on FFHQ dataset, uniform sampling via MaGNET increases distribution precision and recall by 4.1% & 3.0% and decreases gender bias by 41.2%, without requiring labels or retraining. As uniform distribution does not imply uniform semantic distribution, we also explore separately how semantic attributes of generated samples vary under MaGNET sampling.

heading: 1 INTRODUCTION
text: Deep Generative Networks (DGNs) are Deep Networks (DNs) trained to learn latent representations of datasets; such frameworks include Generative Adversarial Networks (GANs) (Goodfellow et al., 2014), Variational Autoencoders (VAEs) (Kingma & Welling, 2013), flow-based models such as NICE (Dinh et al., 2014), and their variants (Dziugaite et al., 2015; Zhao et al., 2016; Durugkar et al., 2016; Arjovsky et al., 2017; Mao et al., 2017; Yang et al., 2019; Fabius & van Amersfoort, 2014; van den Oord et al., 2017; Higgins et al., 2017; Tomczak & Welling, 2017; Davidson et al., 2018; Dinh et al., 2016; Grathwohl et al., 2018; Kingma & Dhariwal, 2018). A common assumption that we will carry through our study is that the datasets of interest are not uniformly distributed in their ambient space, but rather are concentrated on, or around, manifolds of lower intrinsic dimension, e.g., the manifold of natural images (Peyré, 2009). Different DGN training methods have been developed and refined to obtain models that approximate as closely as possible the training set distribution. This becomes an Achilles heel when the training set, regardless of its size, is not representative of the true data distribution, i.e., when the training samples have been curated based on cost or availability that result in implicit/explicit biases. In such scenarios, while the training samples will lie on the true data manifold, the density distribution of the training set will be different from the natural distribution of the data.
Deploying a DGN trained with a biased data distribution can be catastrophic, in particular, when employed for tasks such as data augmentation (Sandfort et al., 2019), controlled data generation for exploration/interpretation (Thirumuruganathan et al., 2020), or estimation of statistical quantities of the data geometry, such as the Lipschitz constant of the data manifold (Gulrajani et al., 2017; Scaman & Virmaux, 2018). Biased data generation from DGNs due to skewed training distributions also raises serious concerns in terms of fair machine learning (Hwang et al., 2020; Tan et al., 2020). While ensuring semantic uniformity in samples is an extremely challenging task, we take one step in the more reachable goal of controlling the DGN sampling distribution to be uniform in terms of the sample distribution on the data manifold. To that end, we propose MaGNET (for Maximum entropy Generative NETwork), a simple and efficient modification to any DGN that adapts its latent space distribution to provably produce samples uniformly spread on the DGN learned manifold. Importantly, MaGNET can be employed on any pre-trained and differentiable DGN regardless of its training setting, reducing the requirement of fine-tuning or retraining of the DGN. This is crucial as many models, such as BigGAN (Brock et al., 2019) and StyleGAN (Karras et al., 2020), have significant computational and energy requirements for training. A plug-and-play method is thus greatly preferred to ease deployment in any already built/trained deep learning pipeline.
Previously, there has been rigorous work on DGNs aimed at improving the training stability of models, deriving theoretical approximation results, understanding the role of the DGN architectures, and numerical approximations to speed-up training and deployment of trained models (Mao et al., 2017; Chen et al., 2018; Arjovsky & Bottou; Miyato et al., 2018; Xu & Durrett, 2018; Liu et al., 2017; Zhang et al., 2017; Biau et al., 2018; Li et al., 2017; Kodali et al., 2017; Roy et al., 2018; Andrés-Terré & Lió, 2019; Chen et al., 2018; Balestriero et al., 2020a; Tomczak & Welling, 2016; Berg et al., 2018). Existing methods (Metz et al., 2016; Tanaka, 2019; Che et al., 2020) also try to tackle mode dropping by improving approximation of the data distribution, but this can potentially increase the bias learned implicitly by the DGNs. We are the first to consider the task of providing uniform sampling on the DGN underlying manifold, which has far-reaching consequences, ranging from producing DGNs stable to data curation and capable of handling inconsistencies such as repeated samples in the training set. We provide a first-of-its-kind provable uniform sampling on the data manifold that can be used to speed up estimation of various geometric quantities, such as estimation of the Lipschitz constant.
MaGNET applies to any (pretrained) DGN architecture (GAN, VAE, NF, etc.) using continuous piecewise affine (CPA) nonlinearities, such as the (leaky) ReLU; smooth nonlinearities can be dealt with via a first-order Taylor approximation argument. Our main contributions are as follows: [C1] We characterize the transformation incurred by a density distribution when composed with a CPA mapping (Sec. 3.1) and derive the analytical sampling strategy that enables one to obtain a uniform distribution on a manifold that is continuous and piecewise affine (Sec 3.2). [C2] We observe that current DGNs produce continuous piecewise affine manifolds, and we demonstrate how to leverage [C1] to produce uniform sampling on the manifold of any DGN (Sec. 3.2). [C3] We conduct several carefully controlled experiments that validate the importance of uniform sampling and showcase the performance of MaGNET on pretrained models such as BigGAN (Brock
et al., 2019), StyleGAN2 (Karras et al., 2020), progGAN (Karras et al., 2017), and NVAE (Vahdat & Kautz, 2020), e.g., we show that MaGNET can be used to increase distribution precision and recall of StyleGAN2 by 4.1% & 3.0% and decrease gender bias by 41.2%, without requiring labels or retraining (Sec. 4.2 and Sec. 4.3).
Reproducible code for the various experiments and figures will be provided upon completion of the review process. Computation and software details are provided in Appendix H, with the proofs of our results in Appendix I. Discussion on the settings in which MaGNET is desirable and on possible limitations is provided in (Sec. 5).

heading: 2 BACKGROUND
text: Continuous Piecewise Affine (CPA) Mappings. A rich class of functions emerge from piecewise polynomials: spline operators. In short, given a partition Ω of a domain RS , a spline of order k is a mapping defined by a polynomial of order k on each region ω ∈ Ω with continuity constraints on the entire domain for the derivatives of order 0,. . . ,k− 1. As we will focus entirely on affine splines (k = 1) we only define this case for concreteness. An affine spline S produces its output via
S(z) = ∑ ω∈Ω (Aωz + bω)1{z∈ω}, (1)
with input z and Aω, bω the per-region slope and offset parameters respectively, with the key constraint that the entire mapping is continuous on the domain S ∈ C0(RS). Spline operators and especially affine spline operators have been extensively used in function approximation theory (Cheney & Light, 2009), optimal control (Egerstedt & Martin, 2009), statistics (Fantuzzi et al., 2002) and related fields. Deep Generative Networks. A deep generative network (DGN) is a (nonlinear) operator GΘ with parameters Θ mapping a latent input z ∈ RS to an observation x ∈ RD by composing L intermediate layer mappings. The only assumption we require for our study is that the nonlinearities present in the DGN are continuous piecewise affine as is the case with (leaky-)ReLU, absolute value, max-pooling. For smooth nonlinearities, our results hold from a first-order Taylor approximation argument. Precise definitions of DGN operators can be found in Goodfellow et al. (2016). We will omit Θ from the GΘ operator for conciseness unless needed. It is also common to refer to z as the latent representation, and x as the generated/observed data, e.g., a time-series or image. One property of DGNs that employ nonlinearities such as (leaky-)ReLU, max-pooling, and the likes, is that the entire input-output mapping becomes a CPA spline with z as both the argument and region parameter.

heading: 3 CONTINUOUS PIECEWISE AFFINE MAPPING OF A PROBABILITY DENSITY
text: In this section, we study the properties of a probability density that is transformed by a CPA mapping. Our goal is to derive the produced density and characterize its properties, such as how the per-region affine mappings in Eq. 1 impact the density concentration. We present some key results that serve as the backbone of our core result in the next section: how to sample uniformly from the manifold generated by DGNs.

heading: 3.1 DENSITY ON THE GENERATED MANIFOLD
text: Consider an affine spline operator S (Eq. 1) going from a space of dimension S to a space of dimension D with D ≥ S. The image of this mapping is a CPA manifold of dimension at most S, the exact dimension is determined by the rank of the per-region slope matrices. Formally, the image of S is given by
Im(S) , {S(z) : z ∈ RS} = ⋃ ω∈Ω Aff(ω;Aω, bω) (2)
with Aff(ω;Aω, bω) = {Aωz+bω : z ∈ ω} the affine transformation of region ω by the per-region parameters Aωbω .
From Eq. 2 we observe that the generated manifold i.e., surface is made of regions that are the affine transformations of the latent space partition regions ω ∈ Ω based on the coordinate change induced by Aω and the shift induced by bω . We visualize this in Fig. 2 for a toy spline operator with 2- dimensional latent space and 3-dimensional ambient/output space. In the remainder of our study we will denote for conciseness S(ω) , Aff(ω;Aω, bω).
Figure 2: Visual depiction of Eq. 2 with a toy affine spline mapping S : R2 7→ R3. Left: latent space partition Ω made of different regions shown with different colors and with boundaries shown in black. Right: affine spline image Im(S) which is a continuous piecewise affine surface composed of the latent space regions affinely transformed by the per-region affine mappings (Eq. 1). The per-region colors are the same on the left and on the right.
When the input space is equipped with a density distribution, then this density is transformed by the mapping S and “lives” on the surface of the CPA manifold generated by S. Given a distribution pz over the latent space, we can explicitly compute the output distribution after the application of S, which leads to an intuitive result exploiting the CPA property of the generator. For this result, we require that operator S be bijective between its domain and its image. That is, each slope matrix Aω,∀ω ∈ Ω should be full rank, and there should not be any folding of the generated CPA surface that intersects with itself, i.e., S(ω) ∩ S(ω′) 6= {} ⇐⇒ ω = ω′. We now derive the key result of this section that characterizes the density distribution lying on the manifold.
Lemma 1. The volume of a region ω ∈ Ω denoted by µ(ω) is related to the volume affinely transformed region S(ω) by,
µ(S(ω)) µ(ω) = √ det(ATωAω), (3)
where µ(S(ω)) is using the measure on the S-dimensional affine subspace spanned by the CPA mapping. (Proof in Appendix I.1.)
Theorem 1. The probability density pS(x) generated by S for latent space distribution pz is given by,
pS(x) = ∑ ω∈Ω pz
(( ATωAω )−1 ATω (x− bω) ) √
det(ATωAω) 1{x∈S(ω)}. (4)
(Proof in Appendix I.2.)
In words, the distribution obtained in the output space naturally corresponds to a piecewise affine transformation of the original latent space distribution, weighted by the change in volume of the perregion mappings from (Eq. 3). For Gaussian and Uniform pz , we use the above results to obtain the analytical form of the density covering the output manifold, we have provided proof and differential entropy derivations in Appendix B.

heading: 3.2 MAKING THE DENSITY ON THE MANIFOLD UNIFORM
text: The goal of this section is to build on Thm. 1 to provide a novel latent space distribution such that the density distribution lying on the generated manifold is uniform.
One important point that we highlight is that having a Uniform density distribution in the latent space of the affine spline is not enough to have a uniform density lying on the manifold; it would be if det(ATωAω) = det(A T ω′Aω′),∀ω 6= ω′, in words, the change in volume of the per region mapping is equal for all ω. This is evident from Appendix B (Eq. 8). So we propose here a novel latent space sampler with the purpose that once transformed by the affine spline i.e., the DGN, that distribution becomes uniform on the DGN manifold. We focus here on the technical aspect and provide precise motivations behind such construction in the next section that deals with practical applications. To obtain K samples uniformly distributed on the output manifold of S:
1. For K MaGNET samples, sample N K (as large as possible) iid latent vectors with U being the latent space domain of S (z1, . . . ,zN ), with zi ∼ U(U)
2. Compute the per-region slope matrices Ai , JS(zi) (Eq. 1) and the change of volume scalar (σ1, . . . , σN ) , (√ det(AT1 A1), . . . , √ det(ATNAN ) ) , where Ai = Aω1{zi∈ω}
3. Sample (with replacement)K latent vectors (z1, . . . ,zK) with probability∝ (σ1, . . . , σN )
We discuss the possible choices of N and K in Appendix D, where we observe that, even for stateof-the-art models like StyleGAN2, N =250,000 is sufficient to provide a stable approximation of the true latent space target distribution. In practice, Ai is simply obtained through backpropagation as it is the Jacobian matrix of the DGN at zi, as in Ai = JS(zi).
The above provides a Monte-Carlo approximation that does not require knowledge of the partition Ω nor the per-region slope matrices (Eq. 1). Those are computed on-demand as zi are sampled. The above procedure produces uniform samples on the manifold learned by a DGN regardless of how it has been trained.

heading: 4 MAGNET: MAXIMUM ENTROPY GENERATIVE NETWORK SAMPLING
text: The goal of this section is to first bridge current DGNs with affine splines, then leverage Thm. 1 and Sec. 3.2 in order to effectively produce uniform samples on the manifold of current Deep Generative Networks such as BigGAN, StyleGAN. We build this affine splines-DGN bridge and propose carefully motivation for uniform sampling in Sec. 4.1 and finally present various experiments across architectures in Sec. 4.2, 4.3 and 4.4.

heading: 4.1 UNIFORM SAMPLING ON THE DEEP GENERATIVE NETWORK MANIFOLD
text: We proposed in the previous section a thorough study of affine splines and how those mappings transform a given input distribution. This now takes high relevance as per the following remark.
Remark 1. Any DGN (or part of it) that employs CPA nonlinearities (as in Sec. 2) is itself a CPA; that is, the input-output mapping can be expressed as in (Eq. 1).
This observation in the context of classifier DNs goes back to Montufar et al. (2014) and has been further studied in Unser (2018); Balestriero & Baraniuk (2018b). We also shall emphasize that operators such as Batch-Normalization (Ioffe & Szegedy, 2015) are not continuous piecewise affine during training but become affine operators during evaluation time. For completeness, we also provide that analytical form of the per-region affine mappings Aω, bω of Eq. 1 in the case of DGNs in Sec. C in the appendix. The key for our method is thus to combine the above with the results from Sec. 3.2 to obtain the following statement.
Theorem 2. Consider a training set sampled from a manifold M and a (trained) CPA DGN S. As long as M ⊂ Im(S), sampling from S as per Sec. 3.2 produces uniform samples on M, regardless of the training set sampling. (Proof in I.4.)
This result follows by leveraging the analytical DGN distribution from Thm. 1 and by replacing pz with the proposed one, leading to pS(x) ∝ ∑ ω∈Ω 1{x∈S(ω)} i.e. being uniform on the DGN manifold. By using the above one can take any (trained) DGN and produce uniform samples on the learned underlying manifold. Hence, our solution allows to produce a generative process that becomes invariant to the training set distribution. While this provides a theoretical guarantee for uniform sampling, it also highlight the main limitation of MaGNET: the uniform samples will be lying on a continuous piecewise affine manifold. That is, unless the true manifold M is also continuous, MaGNET will occasionally introduce abnormal samples that correspond to sampling from the regions of discontinuity of M. We will see in the following sections how even on high-quality image datasets, MaGNET produces very few abnormal samples, one reason being that for complicated data manifold, state-of-the-art DGNs are often built with a (class) conditioning. That is, the above continuity assumption on M lessens only to a within-class continuity assumption which is a much more realistic assumption. Sampling uniformly on the DGN manifold has many important applications that are deferred to the following sections.

heading: 4.2 QUANTITATIVE VALIDATION: -BALL CONCENTRATION, GMM LIKELIHOOD AND
text: FRÉCHET INCEPTION DISTANCE
We now report three controlled experiments to validate the applicability of the theoretical results from Sec. 3.2 for the MaGNET sampling procedure.
First, we consider MNIST and assume that the entire data manifold is approximately covered by the training samples. Regardless of the training data distribution on the manifold (uniform or not), we can pick a datum at random, count how many generated samples (η) are within this datum -ball
neighborhood and repeat this process for 10,000 training samples. If this count does not vary between training datum, then it strongly indicates that the generated samples are uniformly distributed on the manifold covered by the training data. We perform this experiment using a pretrained stateof-the-art variational autoencoder NVAE (Vahdat & Kautz, 2020) to compare between standard and MaGNET sampling with the number of generated samples N ranging from 1,000 to 10,000. We report the distribution of counts in Fig. 3. Again, uniform sampling is equivalent to having the same count for all training samples, i.e., a Dirac distribution in the reported histograms. We can see that MaGNET sampling approaches that distribution while standard sampling has a heavy-tail count distribution, i.e., the generated digits have different concentration at different parts of the data manifold. Another quantitative measure consists of fitting a Gaussian Mixture Model (GMM) with varying number of clusters, on the generated data, and comparing the likelihood obtained for standard and MaGNET sampling. As we know that in both cases the samples lie on the same manifold and domain, the sampling with lower likelihood will correspond to the one for which samples are spread more uniformly on the manifold. We report this in Fig. 4, further confirming the ability of MaGNET to produce uniformly spread samples. We report the generated samples in Appendix E. Lastly, we compare the Fréchet Inception Distance (FID) (Heusel et al., 2017) between 50,000 generated samples and 70,000 training samples for StyleGAN2 trained on FFHQ. Since uniform sampling via MaGNET increases the diversity of generated samples, we see that MaGNET sampling improves the FID for truncation (Karras et al., 2019; Brock et al., 2019), ψ = {.4, .5, .6, .7} by 2.76 points on average (see Appendix F). While for the aforementioned ψ MaGNET samples alone provide an improved FID, for higher ψ values, we introduce an increasing amount of MaGNET samples for FID calculation. We observe in Fig. 4 that by progressively increasing the percentage of MaGNET samples, we are able to exceed the state-of-the-art FID of 2.74 for StyleGAN2 (ψ = 1), reaching an FID of 2.66 with ∼ 4% of MaGNET samples.

heading: 4.3 QUALITATIVE VALIDATION: HIGH-DIMENSIONAL STATE-OF-THE-ART IMAGE GENERATION
text: We now turn into the qualitative evaluation of MaGNET sampling, to do so we propose extensive experiments on various state-of-the-art image DGNs. We also remind the reader that in all cases, standard and MaGNET sampling are performed on the same DGN (same weights) as discussed in Sec. 3.2.
2-Dimensional Dataset and Colored-MNIST. The first set of controlled experiments are designed such that the training set contains inconsistencies while it is known that the original distribution is uniform on the data manifold. Such inconsistencies can occur in real datasets due to challenges related to dataset compilation. We provide illustrative examples in Fig. 5, where we demonstrate that unless uniform sampling is employed, the trained DGN reproduces the inconsistencies present in the training set, as expected. This toy dataset visualization validates our method from Sec. 3.2. Going further, we take the MNIST dataset (in this case, only digit 8 samples) and apply imbalanced
coloring based on the hue distribution provided in Appendix Fig. 12, that favors cyan color. We train a β-VAE DGN (BVAE) on that cyan-inclined dataset, and present in Fig. 6 the hue distributions for samples obtained via standard sampling and MaGNET sampling. We observe that MaGNET corrects the hue distribution back to uniformity. Uniform Face Generation: CelebA-HQ and Flickr-Faces-HQ with progGAN and StyleGAN2. Our first experiment concerns sampling from the StyleGAN2 (Karras et al., 2020) model pretrained on the Flickr-Faces-HQ (FFHQ) dataset. StyleGAN2 has two DGNs, one that maps to an intermediate latent space, termed style-space and another DGN that maps style-space vectors to the pixels-space (output of StyleGAN2). Implementation details are contained in Appendix H. We focus here on applying MaGNET onto the entire StyleGAN2 model (the composition of both DGNs), in Sec. 4.4 we discuss applying MaGNET to the style-space DGN. In Fig. 1 we provide random samples from the same StyleGAN2 model obtained via standard and MaGNET sampling. Upon qualitative evaluation it can be seen that the samples obtained via MaGNET (MaGNET StyleGAN2) have a significantly larger variety of age distribution, background variations and wearable accessories compared to standard sampling. For experiments with CelebA-HQ dataset, we adopt the DGN of Progressively Growing GAN (progGAN) (Karras et al., 2017), trained on 1024 × 1024 resolution images. In Fig. 9 & we provide
random samples from standard and MaGNET sampling, the latter portraying more qualitative diversity. We see that uniform manifold sampling via MaGNET recovers samples containing number of attributes that are generally underrepresented in the samples generated by vanilla progGAN. (See Appendix E) for larger batches and attribute distributions). Notice that uniform sampling not only recovers under-represented groups e.g., age< 30, head-wear, and bald hair, it also increases the presence of neutral emotion and black hair. One interesting observation is that MaGNET also increases the number of samples off the true data manifold (images that are not celebrity faces), exposing regions where the manifold is not well approximated by progGAN. Conditionally Uniform Generation: ImageNet with BigGAN. We present experiments on the state-of-the-art conditional generative model BigGAN (Brock et al., 2019) using MaGNET sampling. In Fig. 7 we provide random samples from standard and MaGNET sampling. More experiments on different classes are presented in Appendix E. We see that uniform sampling on the learned data manifold yields a large span of backgrounds and textures, including humans, while standard sampling produces examples closer to the modes of the training dataset. This is quite understandable considering that ImageNET was curated using a large number of images scraped from the internet. MaGNET therefore could possibly be used for data exploration/model interpretation and also as a diagnostic tool to assess the quality of the learned manifold a posteriori of training.

heading: 4.4 APPLICATION: MONTE-CARLO ESTIMATION AND ATTRIBUTE REBALANCING
text: We conclude this section with two more practical aspects offered by MaGNET. Reduced-Variance Monte-Carlo Estimator. The first is to speed-up (in term of number of required samples) basic Monte-Carlo estimation of arbitrary topological quantities of the generated manifold. In fact, suppose one’s goal is to estimate the Lipschitz constant of a DGN. A direct estimation method would use the known bound given by maxz ‖JS(z)‖F (Wood & Zhang, 1996). This estimation can be done by repeatedly sampling latent vectors z from the same distribution that one used for training a DGN. However this implies that the produced samples will not be uniformly distributed on the manifold in turn leading to slower convergence of the estimator. Instead, we propose to use MaGNET, and report our findings in Fig. 8. More domains of application, where MaGNET can be used for estimator variance reduction, can be found in Baggenstoss (2017). Style-space MaGNET sampling rebalances attributes. When thinking of uniform sampling on a manifold, it might seem natural to expect fairness i.e., fair representation of different attributes such
as equal representation of gender, ethnicity, hair color, etc. However, this is not necessarily true in all cases. In fact, it is trivial to show that each attribute category will be equally represented iff their support on the true data manifold is of equal volume (integrated with respect to the data manifold). Fortunately, as we mentioned in Sec. 4.3, architectures such as StyleGAN2 have explicitly built a style-space, which is a latent space in which attributes are better organized along affine subspaces and occupy nearly the same volume (Karras et al., 2019) i.e., MaGNET applied on the style-space DGN should improve fairness. By applying MaGNET sampling on the style-space, we are able to reduce gender bias from 67–33% (female-male) in standard StyleGAN2 to 60–40%. This simple result demonstrates the importance of our proposed sampling and how it can be used to increase fairness for DGNs trained on biased training sets. MaGNET in the style-space also yields improvements in terms of recall and precision (Sajjadi et al., 2018). Given a reference distribution (e.g., FFHQ dataset) and a learned distribution, precision measures the fidelity of generated samples while recall measures diversity. We compare the metrics for face images generated via latents z ∼ N(0, aI) where a ∈ 0.5, 1, 1.5, 2, z ∼ U [−2, 2], and MaGNET sampling on style-space. For 70K samples generated for each case, MaGNET sampling obtains a recall and precision of (0.822, 0.92) with a 4.12% relative increase in recall and 3.01% relative increase in precision compared to other latent mz sampling methods (metrics were averaged for 10 seeds).

heading: 5 CONCLUSIONS, LIMITATIONS AND FUTURE WORK
text: We have demonstrated how the affine spline formulation of DGN offers a rich portal to obtain theoretical results to provably provide uniform sampling on the manifold learned by a DGN. This allows to become robust to possibly incorrect training set distribution that any DGN would learn to replicate after during its training. We provided various experiments using pretrained state-of-the-art generative models and demonstrated that uniform sampling on the manifold offers many benefits from data exploration to statistical estimation. Beyond the sole goal of uniform sampling on a manifold, MaGNET opens many avenues, yet MaGNET is not a “one size fits all” solution. When not to sample uniformly. We can identify to general cases in which one should not employ uniform sampling of the DGN manifold. The first case occurs whenever the true manifold is known to be discontinuous and one imperatively needs to avoid sampling in those regions of discontinuities. In fact, in the discontinuous case, DGN training, will adapt its weight to put zero (or near zero) density in those discontinuous regions preventing standard sampling to reach those regions (Balestriero et al., 2020b). However, MaGNET will reverse this process and introduce samples back in those regions. The second case occurs if one aims to produce samples from the exact same distribution as the training set distribution (assuming training of the DGN was successful). In fact, in this scenario one should use the exact same latent distribution at evaluation time than the one used during training. Future work. Currently, there are two main limitations of our MaGNET sampling strategy. The first one lies in the assumption that the trained DGN is able to learn a good enough approximation of the true underlying data manifold. In future work, we plan to explore how MaGNET can be used to test such an assumption. One potential directions is as follows. Train a DGN using several different sub-sampled datasets (similar to bootstrap methods) and then study if MaGNET samples populate manifolds that all coincide between the different DGNs. If training was successful, then those sampled manifolds should coincide. The second one lies in understanding the relationship between uniform sampling and uniform attribute representation. We demonstrated how uniform sampling in the style-space of StyleGAN2 ensures that relationship by construction. However, doing MaGNET sampling arbitrarily on any DGN might not always produce better attribute distributions. Hence, developing novel theoretical results to characterize those two effects is one crucial future direction to equip MaGNET with theoretical fairness guarantees.

heading: 6 REPRODUCIBILITY STATEMENT
text: Reproducible code for the various experiments and figures will be provided upon completion of the review process. Computation and software details are provided in Appendix H, with the proofs of our results in Appendix I. Discussion on the settings in which MaGNET is desirable and on possible limitations is provided in (Sec. 5).

heading: A BACKGROUND ON CONTINUOUS PIECEWISE AFFINE DEEP NETWORKS
text: A max-affine spline operator (MASO) concatenates independent max-affine spline (MAS) functions, with each MAS formed from the point-wise maximum of R affine mappings (Magnani & Boyd, 2009; Hannah & Dunson, 2013). For our purpose each MASO will express a DN layer and is thus an operator producing a D` dimensional vector from a D`−1 dimensional vector and is formally given by
MASO(v; {Ar, br}Rr=1) = max r=1,...,R Arv + br, (5)
where Ar ∈ RD `×D`−1 are the slopes and br ∈ RD `
are the offset/bias parameters and the maximum is taken coordinate-wise. For example, a layer comprising a fully connected operator with weights W ` and biases b` followed by a ReLU activation operator corresponds to a (single) MASO with R = 2,A1 = W `,A2 = 0, b1 = b`, b2 = 0. Note that a MASO is a continuous piecewiseaffine (CPA) operator (Wang & Sun, 2005).
The key background result for this paper is that the layers of DNs constructed from piecewise affine operators (e.g., convolution, ReLU, and max-pooling) are MASOs (Balestriero & Baraniuk, 2018b;a):
∃R ∈ N∗,∃{Ar, br}Rr=1 s.t. MASO(v; {Ar, br}Rr=1) = g`(v),∀v ∈ RD `−1 , (6)
making the entire DGN a composition of MASOs. The CPA spline interpretation enabled from a MASO formulation of DGNs provides a powerful global geometric interpretation of the network mapping based on a partition of its input space RS into polyhedral regions and a per-region affine transformation producing the network output. The partition regions are built up over the layers via a subdivision process and are closely related to Voronoi and power diagrams (Balestriero et al., 2019). We now propose to greatly extend such insights to carefully characterize and understand DGNs as well as provide theoretical justifications to various observed behaviors e.g. mode collapse.

heading: B UNIFORM AND GAUSSIAN MANIFOLD DISTRIBUTIONS
text: We now demonstrate the use of the above result by considering practical examples for which we are able to gain insights into the DGN data modeling and generation. We consider the two most common cases: (i) the latent distribution is set as z ∼ N(0, 1) and (ii) the latent distribution is set as z ∼ U(0, 1) (on the hypercube of dimension S). We obtain the following result by direct application of Thm. 1.
Corollary 1. The generated density distribution pS of the Gaussian and uniform densities are given by
pS(x) = ∑ ω∈Ω e− 1 2 (x−bω) T (A+ω ) TA+ω (x−bω)√ (2π)S det(ATωAω) 1{x∈G(ω)}, (Gaussian) (7)
pS(x) = ∑ ω∈Ω 1√ det(ATωAω) 1{x∈S(ω)}. (Uniform) (8)
The two above formulae provide a precise description of the produced density given that the latent space density is Gaussian or Uniform. In the Gaussian case, the per-region slope matrices act upon
the `2 distance by rescaling it from the coordinates of Aω and the per-region offset parameters bω are the mean against which the input x is compared against. In the Uniform case, the change of volume (recall Eq. 3) is the only quantity that impacts the produced density. We will heavily rely on this observation for the next section where we study how to produce a uniform sampling onto the CPA manifold of an affine spline.
We derive the analytical form for the case of Gaussian and Uniform latent distribution in Appendix I.3. From the analytical derivation of the generator density distribution, we obtain its differential entropy.
Corollary 2. The differential Shannon entropy of the output distribution pG of the DGN is given by E(pG) = E(pz) + ∑ ω∈Ω P (z ∈ ω) log( √ det(ATωAω)).
As a result, the differential entropy of the output distribution pG corresponds to the differential entropy of the latent distribution pz plus a convex combination of the per-region volume changes. It is thus possible to optimize the latent distribution pz to better fit the target distribution entropy as in Ben-Yosef & Weinshall (2018) and whenever the prior distribution is fixed, any gap between the latent and output distribution entropy imply the need for high change in volumes between ω and G(ω).

heading: C PER-REGION AFFINE MAPPINGS
text: For completeness we also provide that analytical form of the per-region affine mappings
Aω = ( L−1∏ i=0 diag ( σ̇L−i(ω) ) WL−i ) , (9)
bω =b L + L−1∑ `=1 [( L−`−1∏ i=0 diag ( σ̇L−i(ω) ) WL−i ) diag ( σ̇`(ω) ) b` ] , (10)
where σ̇`(z) is the pointwise derivative of the activation function of layer ` based on its input W `z`−1 + b`, which we note as a function of z directly. For precise definitions of those operators see Balestriero & Baraniuk (2020). The diag operator simply puts the given vector into a diagonal square matrix. For convolutional layers (or else) one can simply replace the corresponding W ` with the correct slope matrix parametrization as discussed in Sec. 2. Notice that since the employed activation functions σ`,∀` ∈ {1, . . . , L} are piecewise affine, their derivative is piecewise constant, in particular with values [σ̇`(z)]k ∈ {α, 1} with α = 0 for ReLU, α = −1 for absolute value, and in general with α > 0 for Leaky-ReLU for k ∈ {1, . . . , D`}.

heading: D NUMBER OF SAMPLES AND UNIFORMITY
text: Exact uniformity is reached when the Monte Carlo samples have covered each region of the DGN partition boundary. For large state-of-the-art models this condition requires sampling on the order of millions. However, we conducted an experiment to see how the number of samples really impacted the uniformity of the generated manifold as follows. We compute precision and recall metrics [4] for StyleGAN2 with K generated samples obtained from N Monte Carlo samples based on our sampling strategy by varying N . We use K = 5000 and N ranging from 10, 000 to 500, 000. Based on the metrics, we identify that increasing beyond K = 250, 000 no longer impacts the metrics, showing that this number of monte carlo samples is enough to converge (approximately) to the uniform sampling in that case, see Fig. 10.
We report here the Jacobian computation times for Tensorflow 2.5 with CUDA 11 and Cudnn 8 on an NVIDIA Titan RTX GPU. For StyleGAN2 pixel space, 5.03s/it; StyleGAN2 style-space, 1.12s/it; BigGAN 5.95s/it; ProgGAN 3.02s/it. For NVAE on Torch 1.6 it takes 20.3s/it. Singular value calculation for StyleGAN2 pixel space takes .005s/it, StyleGAN2 style space .008s/it, BigGAN .001s/it, ProgGAN .004s/it and NVAE .02s/it on NumPy.

heading: E EXTRA FIGURES
text: This section contains samples from our proposed methods, more samples along with attribute data and pretrained weights are available at our project link.
Figure 10: Evolution of the precision/recall curves for varying number of samples N form the monte-carlo sampling against the number of samples K = 5k for StyleGAN2.
0.00 0.25 0.50 0.75 1.00 Recall
0.0
0.2
0.4
0.6
0.8
1.0
Pr e ci
si o n
Vanilla MaGNET
Figure 11: Precision-recall curves for K = 70k samples from Vanilla StyleGAN2 and MaGNET StyleGAN2
0.0 0.5 1.0 1.5 2.0 0.000 0.001 0.002 0.003 0.004 0.005 0.006 0.007 Original
Figure 12: Depiction of the imbalance hue distribution applied to color the MNIST digits.

heading: F EXTRA TABLES

heading: G ALGORITHMS
text: Algorithm 1: MaGNET Sampling as described in Sec. 3.2 Input: Latent space domain, U ; Generator G; Number of regions to sample N ; Number of samples K; Output: MaGNET Samples, {xi}Ki=1; Initialize, Z, S← [], [] ; for n = 1, . . . , N do
z ∼ U(U); Get Slope Matrix, A = JG(z); Get volume scalar at z, σz = √ det(ATA); Z.append(z); S.append(σz)
end for n = 1, . . . ,K do
i ∼ Categorical(prob = softmax(S)); xi ← Z[i]
end
Algorithm 2: Online Rejection Sampling algorithm for MaGNET Input: Latent space domain, U ; Generator G; N change of volume scalars {σ1, σ2, ..., σN}; Output: MaGNET Sample, x; while True do
Sample z ∼ U(U); Sample α ∼ U[0, 1]; Get Slope Matrix, A = JG(z); Get volume scalar at z, σz = √ det(ATA); if σz σz+ ∑N i=1 σi ≥ α then
x = G(z); break;
end end

heading: H ARCHITECTURE, HARDWARE AND IMPLEMENTATION DETAILS
text: All the experiments were run on a Quadro RTX 8000 GPU, which has 48 GB of high-speed GDDR6 memory and 576 Tensor cores. For the software details we refer the reader to the provided codebase. In short, we employed TF2 (2.4 at the time of writing), all the usual Python scientific libraries such as NumPy and PyTorch. We employed the official repositories of the various models we employed with official pre-trained weights. As a note, most of the architectures can not be run on GPUs with less or equal to 12 GB of memory.
For StyleGAN2, we use the official config-e provided in the GitHub StyleGAN2 repo1, unless specified. We use the recommended default of ψ = 0.5 as the interpolating stylespace truncation, to ensure generation quality of faces for the qualitative experiments. For BigGAN we use the BigGANdeep architecture with no truncation, available on TFHub2. We also use the NVAE3 and ProgGAN4 models and weights from their respective official implementations. For the Jacobian determinant calculation of images w.r.t latents, we first use a random orthogonal matrix to project generated images into a lower dimensional space, calculate the Jacobian of the projection w.r.t the latents and calculate the singular values of the jacobian to estimate the volume scalar. We use a projection of 256 dimensions for StyleGAN2-pixel, ProgGAN and BigGAN, and 128 dimensions for NVAE. To estimate the volume scalar we use the top 30, 20, 15 singular values for StyleGAN2 MaGNET pixel, ProgGAN and BigGAN; 40 for StyleGAN2 MaGNET style, and 30 for NVAE.

heading: I PROOFS
text: I.1 PROOF OF LEMMA 1
Proof. In the special case of an affine transform of the coordinate given by the matrixA ∈ RD×D the well known result from demonstrates that the change of volume is given by |det(A)| (see Theorem 7.26 in Rudin (2006)). However in our case the mapping is a rectangular matrix as we span an affine subspace in the ambient space RD making |det(A)| not defined.
First, we shall note that in the case of a Riemannian manifold (as is the produced surface from the per-region affine mapping) the volume form used in the usual change of variable formula can be defined via the square root of the determinant of the metric tensor. Now, for a surface of intrinsic dimension n embedded in Euclidean space of dimension m (in our case, the per-region affine mapping produces an affine subspace) parametrized by the mapping M : Rn 7→ Rm (in our case this mapping is simply the affine mapping M(z) = zωz + bω for each region) the metric tensor is given by g = DMTDM with D the jacobian/differential operator (in our case g = ATωAω for each region). This result is also known as Sard’s theorem (Spivak, 2018). We thus obtain that the change of volume from the region ω to the affine subspace G(ω) is given by √ det(ATA) which can also be written as follows with USV T the svd-decomposition of the matrix A:√ det(ATA) = √ det((USV T )T (USV T )) = √ det((V STUT )(USV T ))
= √ det(V STSV T )
= √ det(STS)
= ∏ i:σi 6=0 σi(A)
leading to ∫ Aff(ω,A,b) dx = 1√ det(ATA) ∫ ω dz
1https://github.com/NVlabs/stylegan2 2https://tfhub.dev/deepmind/biggan-deep-256/1 3https://github.com/NVlabs/NVAE 4https://github.com/tkarras/progressive growing of gans
I.2 PROOF OF THEOREM 1 Proof. We will be doing the change of variables z = (ATωAω)
−1ATω (x − bω) = A+ω (x − bω), also notice that JG−1(x) = A+. First, we know that PG(z)(x ∈ w) = Pz(z ∈ G−1(w)) =∫ G−1(w) pz(z)dz which is well defined based on our full rank assumptions. We then proceed by
PG(x ∈ w) = ∑ ω∈Ω ∫ ω∩w pz(G −1(x)) √ det(JG−1(x)TJG−1(x))dx
= ∑ ω∈Ω ∫ ω∩w pz(G −1(x)) √ det((A+ω )TA + ω )dx
= ∑ ω∈Ω ∫ ω∩w pz(G −1(x))( ∏ i:σi(A + ω )>0 σi(A + ω ))dx
= ∑ ω∈Ω ∫ ω∩w pz(G −1(x))( ∏ i:σi(Aω)>0 σi(Aω)) −1dx Etape 1
= ∑ ω∈Ω ∫ ω∩w pz(G −1(x)) 1√ det(ATωAω) dx
Let now prove the Etape 1 step by proving that σi(A+) = (σi(A))−1 where we lighten notations as A := Aω and USV T is the svd-decomposition of A:
A+ = (ATA)−1AT =((USV T )T (USV T ))−1(USV T )T
=(V STUTUSV T )−1(USV T )T
=(V STSV T )−1V STUT
=V (STS)−1STUT
=⇒ σi(A+) = (σi(A))−1 with the above it is direct to see that √ det((A+ω )TA + ω ) =
1√ det(ATωAω) as follows√ det((A+ω )TA + ω ) = ∏ i:σi 6=0 σi(A + ω ) = ∏ i:σi 6=0 σi(Aω) −1
=  ∏ i:σi 6=0 σi(Aω) −1 = 1√
det(ATωAω)
which gives the desired result.
I.3 PROOF OF COROLLARY 1 Proof. We now demonstrate the use of Thm. 1 where we consider that the latent distribution is set as z ∼ N(0, 1). We obtain that
pG(x ∈ w) = ∑ ω∈Ω ∫ ω∩w 1x∈G(ω)pz(G −1(x)) det(ATωAω) − 12 dx
= ∑ ω∈Ω ∫ ω∩w 1x∈G(ω) 1 (2π)S/2 √ det(ATωAω) e− 1 2‖G −1(x)‖22dx
= ∑ ω∈Ω ∫ ω∩w 1x∈G(ω) 1 (2π)S/2 √ det(ATωAω) e− 1 2 ((A + ω (x−bω)) T ((A+(x−bω))dx
= ∑ ω∈Ω ∫ ω∩w 1x∈G(ω) 1 (2π)S/2 √ det(ATωAω) e− 1 2 (x−bω) T (A+ω ) TA+ω (x−bω)dx
giving the desired result that is reminiscent of Kernel Density Estimation (KDE) (Rosenblatt, 1956) and in particular adaptive KDE (Breiman et al., 1977), where a partitioning of the data manifold is performed on each cell (ω in our case) different kernel parameters are used.
Proof. We now turn into the uniform latent distribution case on a bounded domain U in the DGN input space. By employing again Thm. 1, the given formula one can directly obtain that the output density is given by
pG(x) =
∑ ω∈Ω 1x∈ω det(A T ωAω) − 12
V ol(U) (11)
I.4 PROOF OF THM. 2 As we assume successful training, then regardless of the actual distribution px, the DGN will learn the correct underlying manifold, and learn the best approximation to px as possible onto this manifold. Now, applying MaGNET sampling i.e. Sec. 3.2 is equivalent to sampling from a distribution pmz such that after DGN mapping, that distribution is uniform on the learned manifold (see Thm. 1). As we assumed that regardless of px the DGN approximates correctly the true manifold, and as we then adapt the sampling distribution pmz to always obtain uniform sampling on that manifold, we see that this final sampling becomes invariant upon the data distribution (on the manifold) leading to the desired result.

Review summaries:
This paper concerns with uniform sampling from deep generative networks such as GANs and VAEs. The training samples of DGNs are often biased as they are obatined based on preferences, costs, or convenience that leads to DGNs producing biased examples. This paper gives a gemoetry based sampler MaGNET, that given any trained DGN, produces samples that are uniformly distributed on the learned manifold. It theoretically proves, and empirically shows that the MaGNET produces a uniform distrbution on the manifold regardless of the training set distribution. The theoretical proofs require that the DGNs only comprise continuous piecewise affine (CPA) non-linearities, such as ReLu, absolute value, max-pooling. The three main contributions of the paper are as following: (a) It characterizes the transformation incurred by a density distribution when composed with a CPA mapping. (b) It derives an analytical sampling strategy that allows to obtain a uniform distribution on a manifold that is continuous and piecewise affine. (c) It provides multiple numerical experiments validating the gains of their proposed method MaGNET. 

The authors propose a uniform sampling technique for deep generative networks (DGNs) inspired by the probabilistic change of variables formula. The technique works with any already trained DGN and does not involve any further training. (Though it does require back propagation w.r.t. the input $x$.) In essence, the algorithm works by drawing many samples N >> K from the DGN, then sampling from these $N$ samples with probability inversely related to their pushforward density (as computed by the change-of-variables formula).