T HE G EOMETRY OF D EEP G ENERATIVE I MAGE M ODELS AND ITS A PPLICATIONS
Anonymous authors
Paper under double-blind review
A BSTRACT
Generative adversarial networks (GANs) have emerged as a powerful unsupervised method to model the statistical patterns of real-world data sets, such as natural images.
These networks are trained to map random inputs in their latent space to new samples representative of the learned data.
However, the structure of the latent space is hard to intuit due to its high dimensionality and the non-linearity of the generator, which limits the usefulness of the models.
Understanding the latent space requires a way to identify input codes for existing real-world images (inversion), and a way to identify directions with known image transformations (interpretability).
Here, we use a geometric framework to address both issues simultaneously.
We develop an architecture-agnostic method to compute the Riemannian metric of the image manifold created by GANs.
The eigen-decomposition of the metric isolates axes that account for different levels of image variability.
An empirical analysis of several pretrained GANs shows that image variation around each position is concentrated along surprisingly few major axes (the space is highly anisotropic) and the directions that create this large variation are similar at different positions in the space (the space is homogeneous).
We show that many of the top eigenvectors correspond to interpretable transforms in the image space, with a substantial part of eigenspace corresponding to minor transforms which could be compressed out.
This geometric understanding uniﬁes key previous results related to GAN interpretability.
We show that the use of this metric allows for more efﬁcient optimization in the latent space (e.g. GAN inversion) and facilitates unsupervised discovery of interpretable axes.
Our results illustrate that deﬁning the geometry of the GAN image manifold can serve as a general framework for understanding GANs.
B ACKGROUND
Generative adversarial networks (GANs) learn patterns that characterize complex datasets, and subsequently generate new samples representative of that set.
In recent years, there has been tremendous success in training GANs to generate high-resolution and photorealistic images (Karras et al., 2017;
Brock et al., 2018; Donahue & Simonyan, 2019; Karras et al., 2020).
Well-trained GANs show smooth transitions between image outputs when interpolating in their latent input space, which makes them useful in applications such as high-level image editing (changing attributes of faces), object segmentation, and image generation for art and neuroscience (Zhu et al., 2016;
Shen et al., 2020; Pividori et al., 2019; Elgammal et al., 2017; Ponce et al., 2019).
However, there is no systematic approach for understanding the latent space of any given GAN or its relationship to the manifold of natural images.
Because a generator provides a smooth map onto image space, one relevant conceptual model for
GAN latent space is a Riemannian manifold.
To deﬁne the structure of this manifold, we have to ask questions such as: are images homogeneously distributed on a sphere? (White, 2016)
What is the structure of its tangent space — do all directions induce the same amount of variance in image transformation?
Here we develop a method to compute the metric of this manifold and investigate its geometry directly, and then use this knowledge to navigate the space and improve several applications.
To deﬁne a Riemannian geometry, we need to have a smooth map and a notion of distance on it, deﬁned by the metric tensor.
For image applications, the relevant notion of distance is in image space rather than code space.
Thus, we can pull back the distance function on the image space onto the latent space.
Differentiating this distance function on latent space, we will get a differential geometric structure (Riemannian metric) on the image manifold.
Further, by computing the Riemannian metric at different points (i.e. around different latent codes), we can estimate the anisotropy and homogeneity of this manifold.
The paper is organized as follows:
ﬁrst, we review the previous work using tools from Riemannian geometry to analyze generative models in section 2.
Using this geometric framework, we introduce an efﬁcient way to compute the metric tensor H on the image manifold in section 3, and empirically investigate the properties of H in various GANs in section 4.
We explain the properties of this metric in terms of network architecture and training in section 5.
We show that this understanding provides a unifying principle behind previous methods for interpretable axes discovery in the latent space.
Finally, we demonstrate other applications that this geometric information could facilitate, e.g. gradient-free searching in the GAN image manifold in section ?? .
R ELATED W ORK
Geometry of Deep Generative Model Concepts in Riemannian geometry have been recently applied to illuminate the structure of latent space of generative models (i.e. GANs and variational autoencoders, VAEs).
Shao et al.
(2018) designed algorithms to compute the geodesic path, parallel transport of vectors and geodesic shooting in the latent space; they used ﬁnite difference together with a pretrained encoder to circumvent the Jacobian computation of the generator.
While promising, this method did not provide information of the metric directly and could not be applied to GANs without encoders.
Arvanitidis et al.
(2017) focused on the geometry of VAEs, deriving a formula for the metric tensor in order to solve the geodesic in the latent space; this worked well with shallow convolutional VAEs and low-resolution images (28 x 28 pixels).
Chen et al.
(2018) computed the geodesic through minimization, applying their method on shallow VAEs trained on MNIST images and a low-dimensional robotics dataset.
In the above, the featured methods could only be applied to neural networks without ReLU activation.
Here, we apply the geometric analysis to modern largescale GANs (e.g. BigGAN, StyleGAN2) and we show it is compatible with any activation function.
Finally, all previous works assumed a L2 distance in image space, and here we extend this approach to any differentiable distance metric.
M ETHODS
Formulation A generative network, denoted by G , is a mapping from latent code z to image
I , G : R n → I =
R H
× W × 3 ,
z (cid:55)→ I .
Borrowing the language of Riemannian geometry, G ( z ) parameterizes a submanifold in the image space with z ∈ R n .
Note for applications in image domain, we care about distance in the image space.
Thus, given a distance function in image space
D : I × I → R + , ( I 1 , I 2 ) (cid:55)→ L , we can deﬁne the distance between two codes as the distance between the images they generate, i.e. pullback the distance function to latent space through G .
d : R n × R n → R + , d ( z 1 , z 2 ) :
= D ( G ( z 1 ) , G ( z 2 )) .
The Hessian matrix (second order partial derivative) of the squared distance function d 2 can be seen as the metric tensor of the image manifold (Palais, 1957).
The intuition behind this is as follows: consider the squared distance to a ﬁxed reference vector z 0 as a function of z , f z 0 ( z ) =
d 2 ( z 0 , z ) .
Obviously, z = z 0 is a local minimum of f z 0 ( z ) , thus f z 0 ( z ) can be locally approximated by a positive semi-deﬁnite quadratic form H ( z 0 ) as in Eq.1.
This matrix induces an inner product and deﬁnes a vector norm, (cid:107) v (cid:107) 2 H = v T H ( z 0 ) v .
This squared vector norm approximates the squared image distance, d 2 ( z 0 , z
+ δ z ) ≈ (cid:107) δ z (cid:107) 2 H
=
δ T z H ( z 0 ) δ z .
Thus, this matrix encodes the local distance information on the image manifold up to second order approximation.
This is the intuition behind Riemannian metric.
In this article, the terms ”metric tensor” and ”Hessian matrix” are used interchangeably.
We will call α H ( v ) = v T H v / v T v the approximate speed of image change along v as measured by metric H .
[Equation]
Numerical Method As deﬁned above, the metric tensor H can be directly computed by doubly differentiating the squared distance function d 2 .
Here we use a CNN-based distance metric called Learned Perceptual Image Patch Similarity (LPIPS) (Zhang et al., 2018), both because it is doubly differentiable and because it has been demonstrated to approximate perceptual similarity judgements.
We compute the Hessian by building a computational graph towards the gradient g ( z ) = ∂
z d 2 | z = z 0 and then computing the gradient towards each element in g ( z ) .
This method computes H column by column, therefore its time complexity is proportional to the latent-space dimensionality n and the backpropagation time through this graph.
For situations when computing the Hessian through column-by-column backpropagation is too slow (e.g. FC6GAN, StyleGAN2), we developed an approximation method to compute the major eigendimensions of the Hessian more efﬁciently.
The rationale is that these top eigenpairs are more useful than the full Hessian in applications like optimization and exploration; moreover, the top eigen-pairs form the best low-rank approximation to the Hessian.
As we will later discover, the spectra of these matrices have a fast decay, thus these Hessian matrices require far less than n eigenvectors to approximate, cf.
Sec 4.
As a matrix, the Hessian is a linear operator, which could be deﬁned as long as one can compute the Hessian vector product (HVP). Since the gradient to z commutes with inner product with v , HVP can be rewritten as the gradient to v T g , or the directional derivative to the gradient v T ∂ z g (Eq.2). The ﬁrst form ∂ z ( v T g ) is easy to compute in reverse-mode auto-differentiation, and the directional derivative is easy to compute in forward-mode auto-differentiation (or ﬁnite differencing as in Eq.2).
Then, Lanczos iterations are applied to the HVP operator deﬁned in these two ways to solve the largest eigen pairs, which can reconstruct an approximate Hessian matrix. The iterative algorithm using the two HVP deﬁnitions are termed Backward Iteration and Forward
Iteration respectively. For details and efﬁciency comparison, see Appendix A.2.
[Equation] Note a similar computational method has been employed to understand the optimization landscape of deep neural networks recently (Ghorbani et al., 2019), although it has not been applied towards the geometry of latent space of GANs before.
Connection to Jacobian This formulation and computation of the Riemannian metric can be generalized to any representational space beyond that of images.
Consider a mapping φ ( z ) : R n → R M , which could be the feature map of a middle layer in the GAN, or a CNN processing the generated image.
We can pull back the squared L2 distance and metric from R M , d 2 φ ( z 1 , z 2 ) = 12 (cid:107) φ ( z 1 ) − φ ( z 2 ) (cid:107) 22 , and deﬁne a manifold.
The metric tensor H φ of this manifold can be derived as Hessian of d 2 φ .
Note, there is a simple relationship between the Hessian of d 2 φ , H φ and the
Jacobian of φ , J φ (Eq. 3).
Through this we know the eigen spectrum of the Hessian matrix H φ is the square of the singular value spectrum of the Jacobian J φ , and the eigenvectors of H φ is the same as the right singular vectors of J φ .
This allows us to examine the geometry of the representation through out the GAN, and analyze how the geometry in the image space builds up.
[Equation]
In this work, we use LPIPS, which deﬁnes image distance based on the squared L2 distance of the ﬁrst few layers of a pretrained CNN.
If we concatenate the activations and denote this representational map by ϕ ( I ) : I → R F , then the metric tensor of the image manifold can be derived from the Jacobian of the generator compositing representation map ϕ , H ( z ) =
J Tϕ ◦ G J ϕ ◦
G , J ϕ ◦ G = ∂
z ϕ ( G ( z )) .
This connection is crucial for understanding how geometry depends on the network architecture.
E MPIRICAL O BSERVATIONS
Using the above method, we analyzed the geometry of the latent space of the following GANs:
DCGAN (Radford et al., 2015), DeePSiM/FC6GAN (Dosovitskiy & Brox, 2016), BigGAN (Brock et al., 2018), BigBiGAN (Donahue & Simonyan, 2019), Progressive Growing of GANs (PGGAN) (Karras et al., 2017), StyleGAN 1 and 2 (Karras et al., 2019; 2020) - model speciﬁcations reviewed in Sec.
A.3.
These GANs are progressively deeper and more complex, and some employ a stylebased architecture instead of a more conventional DCGAN architecture (e.g. StyleGAN1,2).
This diverse set of models allowed us to test the broad applicability of this new approach.
In the following sections, ”top” and ”bottom” eigenvectors refer to the eigenvectors with large and small eigenvalues.
Top Eigenvectors Capture Signiﬁcant Image Changes. In differential geometry, a metric tensor H captures an inﬁnitesimal notion of distance.
To determine whether this quantity represents evident image changes, we randomly picked a latent code z 0 , computed the metric tensor H ( z 0 ) and its eigendecomposition H ( z 0 )
= (cid:80) i λ i v i
v Ti .
Then we explored linearly in the latent space 1 along the eigenvectors G ( z 0 + µ i v i ) .
We found that images changed much faster when moving along top than along bottom eigenvectors, both per visual inspection and LPIPS (Fig 1).
More intriguingly, eigenvectors at different ranks encoded qualitatively different types of changes; for example, in BigGAN noise space, the top eigenvectors encoded head direction, proximity and size; while lower eigenvectors encoded background changes, shading or much more subtle pixel-wise changes.
Moreover, PGGAN and StyleGANs trained on the face dataset (FFHQ) have top eigenvectors that represent similar interpretable transforms of faces, such as head direction, sex or age (Fig. 9). These observations raised the possibility that top eigenvectors also captured perceptually relevant changes: we tested this directly with positive results (see Sec. 6).
[Figure]
[Table]
λ 2 =1.6e λ 3 =1.3e λ 5 =4.8e
λ 8 =9.7e
λ 17 =2.7e I m a g e D i s t a
[Figure]
Spectrum Structure of GANs.
To explore how eigenvalues were distributed, for each GAN, we randomly sampled 100-1000 z in the latent space, used backpropagation to compute H ( z ) and then performed the eigendecomposition.
In Fig.
2, we plotted the mean and 90% conﬁdence interval of the spectra and found that they spanned 5-10 orders of magnitude, with fast decays; each spectrum was dominated by a few eigenvectors with large eigenvalues.
In other words, only a small fraction of dimensions were responsible for major image changes (Table 2), while most dimensions introduced nuanced changes (e.g. shading, background) — GAN latent spaces were highly anisotropic.
We found this anisotropy in every GAN we tested, which raises the question of why it had not been reported previously.
One possibility is that the statistical properties of high dimensionality create
[Figure]
Spectra Compared Across
[Figure]
an illusion of isotropy. When traveling along a random direction v in latent space, the approximate rate of image change α H ( v ) = v T H v / v T v is a weighted average of all eigenvalues as in Eq. In Sec A.
[Figure]
we show analytically that the variance of α ( v ) across random directions will be 2 / ( n +2) times smaller than the variance among eigenvalues.
For example, in BigGAN latent space (256 dimensions), the eigenvalues span over six orders of magnitude, while the α ( v ) for random directions has a standard deviation less than one order of magnitude (Figs. 2, 6).
Further, the center of this distribution was closer to the top of the spectrum, and thus provided a reasonable rate of change, while masking the existence of eigendimensions of extremely large and small eigenvalues.
Global Metric Structure Because the metric H ( z ) describes local geometry, the next question is how it varies at different positions in the latent space.
We computed the metric H ( z ) at randomly selected z and examined their similarity using a statistic adopted from Kornblith et al.
In this statistic, we applied the eigenvectors
U i =
[ u 1 , ...u n ] from a metric tensor H i at position
z i to the metric tensor H j at z j , as u Ti H j u i .
These values formed a vector Λ ij , representing the effects of metric H j on eigenvectors of H i .
Then we computed the Pearson correlation coefﬁcient between Λ ij and the target eigenvalues, Λ j , as corr (Λ j , Λ ij ) .
This correlation measured the similarity of the action of metric tensors on eigenframes around different positions.
As the spectrum usually spanned several orders of magnitude, we computed the correlation on the log scale C Hlogij , where the eigenvalues distribute more uniformly. [Equation]
[Equation]
Using this correlation statistic, we computed the consistency of the metric tensor across hundreds of positions within each GAN latent space.
As shown in Fig.
3C, the average correlation between eigenvalues and vHv values of two points C Hlogij was 0.934 in BigGAN.
For DCGAN-type architecture, mean correlations on the log scale ranged from 0.92-0.99; for StyleGAN-1,2, 0.64-0.73 in the
Z space, and 0.87-0.89 in the W space (Fig.
3D, Tab.4).
Overall, this shows that the local directions that induce image changes of different orders of magnitude are highly consistent at different points in the latent space.
Because of this, the notion of a ”global” Hessian makes sense, and we estimated it for each latent space by averaging the Hessian matrices at different locations.
Implication of the Null Space As the spectra have a large portion of small eigenvalues and the metric tensors are correlated in space, the bottom eigenvectors create a global subspace, in which latent traversal will result in small or even imperceptible changes in the image. This is supported by our perceptual study, as over half of the subjects cannot see any change in image when latent vector move in bottom eigenspace. (Sec. 6). This perceptually ”null” space has implications about exploration in the GAN space and interpretable axes discovery.
As G ( z + v ) ≈ G ( z ) , if one axis u encodes an interpretable transform G ( z ) → G ( z + u ) , then shifting this vector by a vector in the null space v will still result in an interpretable axis G ( z ) → G ( z + v + u )
≈
G ( z + u ) .
Thus, each interpretable axis have a family of ”equivalent” axis which encode similar transforms, differing from each other by a vector in ”null” space.
However, adding component v in the null space will decrease the rate of image change along that axis.
In this sense, the vectors using a smallest step size to achieve that transform should be the ”purest” axis of the family.
Further, cosine angle between two interpretable axis may not represent the similarity of the transforms they encodes.
A large angle can be found between two axes of the same family but different image traversal speed.
We compared the axes from previous works in A.9 and observed that projecting out a large part of their axes will not affect the semantics encoded in it (Fig. 8).
[Figure]  M ECHANISM Above, we showed an intriguingly consistent geometric structure across multiple GANs.
Next, we sought to understand how this structure emerged through network architecture and training.
To link the metric tensor to the generator architecture, it is helpful to highlight the relationship between the metric tensor and Jacobian matrix H ( z ) =
J Tϕ ◦ G J ϕ ◦
G (Eq. 3).
As latent space gets warped and mapped onto image space, directions in latent spaces are scaled differently by the Jacobian of the map; speciﬁcally, directions that undergo the most ampliﬁcation will become the top eigenvectors (Fig. 4A).
As the Jacobian of the generator is a composition of Jacobians of each layer dψ i , the scaling effect on the image manifold is a product of the scaling effects of each intermediate layer.
We can analyze the scaling effect of different layers ψ i by applying a set of vectors onto the metric tensors of these layers H ψ i .
In BigGAN, when we apply the eigenvectors of the ﬁrst few layers onto the metric of other layers, the top eigenvectors are still strongly ampliﬁed by subsequent layers, thus forming the top eigendimensions of the manifold.
Of note, this is not true for a weight-shufﬂed control BigGAN: in that case, the top eigendimension of the ﬁrst few layers was not particularly ampliﬁed on the image manifold, and vice versa (Fig. 4 B).
This shows that the ampliﬁcation effect of layers becomes more aligned through training, with the top eigenspace shared across layers.
Further, as the ampliﬁcation effects are not lined up across layers of weight shufﬂed networks, these networks should exhibit a more isotropic geometry on their image manifold.
Indeed, we ﬁnd their spectra to be ﬂatter and the largest eigenvalue smaller (Fig. 7).
A PPLICATIONS
By deﬁning the geometry of the latent space via the metric tensor, we gain an understanding of which directions in this space are more informative than others.
This understanding leads to improvements
[Figure]
) in all major layers in BigGAN.
C. Same, but for weight-shufﬂed BigGAN.
in three applications: 1) gradient descent-based optimizers, 2) accelerating gradient-free search, 3) ﬁnding human-interpretable axes in the latent space. Improving Gradient-Based GAN Inversion. For applications like GAN-assisted drawing and photo editing (Zhu et al., 2016; Shen et al., 2020), one crucial step is to ﬁnd a latent code corresponding to a given natural image (termed GAN inversion).
For this problem, one basic approach is to minimize the distance between a generated image and the target image z ∗ =
arg min z D ( G ( z ) , I ) .
Although second-order information (Hessian) is valuable in optimization, they are seldom used as they are expensive to compute and update.
However, because we ﬁnd that local Hessian information is highly correlated at different points in latent space, we can pre-compute it once for each latent space and use the average Hessian information to boost ﬁrst-order optimization.
As an example,
ADAM is a ﬁrst-order optimization algorithm that adapts the learning rate of each parameter separately according to the moments of gradients on that parameter (Kingma & Ba, 2014).
It can be seen as a quasi-second order optimizer that approximates a diagonal Hessian matrix based on ﬁrst-order information.
However, if the true Hessian is far from diagonal, i.e. the space is anisotropic and the valley is not aligned with the coordinates, then this approximation could work poorly.
[Figure]
face rotating 3d space age facing directionNONE samerowLittle background NONE hairstyle slightly NO A B C
[Figure] To test whether the metric can help overcome this problem, we used the eigenvectors of the average Hessian to rotate the latent space; this orthogonal change of variables should make the Hessian more diagonal and thus accelerate ADAM.
This method can be seen as a preconditioning step which could be inserted into any pipeline involving ADAM.
We tested this modiﬁcation on the state-of-theart algorithm for inverting BigGAN, i.e. BasinCMA (Huh et al., 2020), which interleaves ADAM and CMAES steps.
We used our Hessian eigenbasis in the ADAM steps, and found that we could consistently lower the ﬁtted distance to the target when inverting ImageNet and BigGAN-generated images (Zhang et al., 2018)(Fig. 5). Similarly, eigenbasis preconditioning consistently improved inversion of PGGAN and StyleGAN2-Face for real image sampled from both FFHQ and CelebA using ADAM method.
In short, the understanding of homogeneity and anisotropy of the latent space can improve gradient-based optimization.
Improving Gradient-Free Search in Image Space
In some domains, it is important to optimize objectives in the absence of a gradient, for example, in black-box attacks against image recognition systems via adversarial images, or when searching for activity-maximizing stimuli for neurons in primate visual cortex, or when optimizing perceptual evaluation in the user (Ponce et al., 2019; Xiao & Kreiman, 2020; Chiu et al., 2020).
These applications usually involve a low-dimensional parameter space (such as GANs) and an efﬁcient gradient-free search algorithm, such as covariance matrix adaptation evolution strategy or CMAES.
CMAES explores the latent space using a Gaussian distribution and adapts the shape of the Gaussian (covariance matrix) according to the search history and local landscape.
However, online learning of a covariance matrix in high-dimensional space is computationally costly, and inaccurate knowledge of it can be detrimental to optimization.
Here we applied the prior geometric knowledge of the space to build the covariance matrix instead of learning it from scratch.
For example, as illustrated by natural gradient descent (Amari, 1998), one simple heuristic for optimizing on the image manifold is to move in smaller steps along dimensions that change the image faster and vice versa.
We used this heuristic to improve CMAES (a combined approach we refer to as CMAES-Hessian).
With our method, the search can be limited to the most informative directions, which should increase sampling efﬁciency, and as the space is anisotropic, our method further tunes the exploration step size in a way that is inversely proportional to the rate of image change.
To test this approach, we applied the novel CMAES-Hessian algorithm to the problem of searching for activation maximizing stimuli for units in AlexNet (Nguyen et al., 2016) in the latent space of two GANs (FC6GAN and BigGAN).
We found that the dimensionality of the search space could be reduced from 4096 to 500 for FC6GAN without impairing maximal activation values.
Further, we found that CMAES-Hessian consistently led to higher activation values compared to the classic CMAES algorithm in BigGAN space (Fig. 5).
Interpretable Axes Discovery When users wish to manipulate GAN-based images via their latent code, it is useful to reduce the number of variables needed to effectuate this given manipulation.
Our method provides a systematic way to compute the most informative axes (top eigenspace) in the latent space to use as variables, and the resulting eigenvalues can serve to compute appropriate step sizes along each corresponding axes.
We applied this method to FC6GAN, BigGAN, BigBiGAN, StyleGAN1,2, PGGAN, and plotted the changes corresponding to the top eigenvectors (Fig. 1).
These eigenvectors appeared to capture interpretable transformations like zooming, head direction and object position. To test if this was apparent to people other than the authors, we conducted a study using Amazon’s
Mechanical Turk.
We tested the perceptual properties of the axes identiﬁed by the metric tensor, including the top 10 eigenvectors, random vectors orthogonal to the top 15d eigenspace, and bottom 10 eigenvectors.
Images were generated using four different GANs (PGGAN, BigGAN noise space,
StyleGAN2-Cat and -Face), and were presented to 185 participants.
In each trial, ﬁve randomly sampled reference images were perturbed along a given axis, and participants were asked if they could a) perceive a change, b) indicate an estimate of its magnitude [0%-100%] c) describe a common change in their own words and how many of the ﬁve images shared this change, c) indicate how similar were the 5 image changes (consistency, score of 1-9, 9 most similar) and ﬁnally, d) state how difﬁcult it was to describe this change (difﬁculty score, scale of 1-9, 9 most difﬁcult). Only 48.5% of the subjects reported to see any change happen for bottom eigenvectors, the fraction was 93.5% and 89.8% for top and orthogonal directions respectively. Further, when subjects observed some change, they reported that the image transformations induced by top eigenvectors were larger ( 70 . 3% ± 0 . than those of orthogonal directions ( 66 .
8% ± 0 .
{+9% , P = 7 . 
+}
× 10 − 4 , 2 sample T-test) and than those of bottom eigenvectors ( 61 . 5% ± 1 .
6% , P = 2 .
1 × 10 − 10 ).
This was true even though we picked a 5-10 times smaller step size in the top eigenspace than in the orthogonal and bottom eigenspaces.
Further, subjects reported the top 10 eigenvectors had a higher mean perceptual consistency score ( 6 . 72 ± 0 . 06) , n = 929 responses) than the orthogonal ( 6 . 42 ± 0 .
09 , P = 5 .
8 × 10 − 3 , n = 448 ) and bottom eigenvectors ( 6 . 12 ± 0 .
14 , P = 1 . 3 × 10 − 5 , n = 242 ). Participants reported that the top eigenvectors were easier to interpret ( 4 . 91 ± 0 . 08 ) than the bottom eigenvectors ( 5 . 69 ± 0 . 14 , P = 3 .
8 × 10 − 6 , albeit comparably to the orthogonal eigenvectors 4 .
82 ± 0 .
11 , P = 0 . 5 ).
Thus, overall we conclude that the Hessian eigenvectors not only capture informative axes of image transformations, but that these were also perceptually relevant, corresponding to similar semantic changes when applied to different reference vectors (Fig. 10) — axes interpretable not just in local sense, but in a global sense.
D ISCUSSION AND F UTURE D IRECTIONS
In this work, we developed an efﬁcient and architecture-agnostic way to compute the geometry of the manifold learnt by generative networks.
This method discovers axes accounting for the largest variation in image transformation, which frequently represent semantically interpretable changes.
Subsequently, this geometric method can facilitate image manipulation, increase explainability, and accelerate optimization on the manifold (with or without gradients).
There have been multiple efforts directed at identifying interpretable axes in latent space using unsupervised methods, including (H ¨ ark ¨ onen et al., 2020; Shen & Zhou, 2020; Voynov & Babenko, 2020).
Our described connection between the metric tensor of the image manifold and the Jacobian matrices of intermediate layers uniﬁes these previous results.
As we have showed, the top right singular vectors of the weights (i.e. Jacobian) of the ﬁrst few layers (as used in Shen & Zhou (2020)), correspond to the top eigenvectors of the metric tensor of the image manifold, and these usually relate to interpretable transforms (as will be shown in Sec.6).
Similarly, the top principal components (PCs) of intermediate layer activations H ¨ ark ¨ onen et al.
(2020) roughly correspond to the top left singular vectors of the Jacobian, thus also to the interpretable top eigenvectors of the metric on the image manifold (although note that these PCs measure the global ampliﬁcation of the map, not the local ampliﬁcations measured by our metric tensor).
Regarding (Voynov & Babenko, 2020), we empirically compared their interpretable axes and our eigenvectors, and found that in some of the GANs, the discovered axes have a signiﬁcantly larger alignment with our top eigenspace and they are highly concentrated on individual top axes than expected from random mixing. We refer the reader to Appendix A.9 and Fig.8 for further information. Although we have answered how the anisotropy comes into being mechanistically, there remains the question of why it should exist at all.
Anisotropy may result from gradient training: theoretical ﬁndings on deep-linear networks for classiﬁcation show that gradient descent aligns the weights of layers, resulting in a highly anisotropic Jacobian (Ji & Telgarsky, 2018).
Whether that analysis transfers to the setting of generative networks remains to be investigated.
Alternatively, assuming that a well-trained GAN faithfully represents the data distribution, this anisotropy may reveal the intrinsic dimensionality of the data manifold.
Statistical dependencies of variation in real-world images (e.g. uniform changes in skin color, head direction) imply that the images reside in a statistical manifold of much lower dimension.
Further, among transformations that happen on this manifold, there will be some dimensions that transform images a lot and some that do not (e.g. skin color versus facial expression).
In that sense, our method may be equivalent to performing a type of nonlinear PCA of the image space through the generator map.
In fact, we have found that GANs trained on similar datasets (e.g. PGGAN, StyleGAN1,2 trained on the human face dataset [CelebA,FFHQ]) have top eigenvectors that represent the same set of transforms (e.g. head direction, gender, age; Fig. 9).
This supports the ”PCA” hypothesis, as these transformations may account for much of the pixelwise variability in face space; the GANs are able to learn to represent these transformations as linear directions, which our method can then identify.
This further raises the intriguing possibility that if the dataset is actually distributed on a lower dimensional space, one could learn generators with smaller latent spaces; or alternatively, it may be easier to learn generators with large latent spaces and reduce them after intensive training.
These are questions worth exploring.
A A PPENDIX A. C ONNECTION TO I NFORMATION G EOMETRY
It is useful to compare our work to the ”information geometry”(Amari, 2016) on the space of distributions.
In this formulation, KL divergence is a pseudo-metric function on the space of distributions, and its Hessian matrix towards parameters of distribution is the Fisher information matrix.
In information geometry, this Fisher information matrix could be considered as the metric on the manifold of distributions; this metric information can be further used to assist optimization on the manifold of distributions, termed natural gradient descent.(Amari, 1998)
In our formulation, the squared image difference function D 2 is analogous to this KL-divergence; the image G ( z ) as parameterized by latent code z is analogous to the distribution p θ parameterized by θ .
The metric tensor we computed is comparable to the Fisher information matrix in their setting.
Thus our way of using metric information to assist optimization on manifold is analogous to natural gradient descent.
A. M ETHODS FOR C OMPUTING THE H ESSIAN
One direct way to compute the Hessian towards a given objective (e.g. squared distance d 2 in our case), is to compute g z
( z ) =
∂
z d 2 | z = z 0 , create a computational graph from code z to the gradient g z 0 ( z ) , and back propagate from gradient vector g z
( z ) element by element.
In this way the computational time is linear to time of a single backward pass times the hidden space dimension n .
Given a large hidden space or a deep network (e.g. 4096d in FC6GAN, or 512d in StyleGAN2), this method can be very slow.
However, as the eigenspace of small eigenvalues represent directions that do not change images much, the exact eigenvector does not matter.
An efﬁcient way is to use the
Hessian vector product (HVP) operator and iterative eigenvalue algorithms to ﬁnd the eigenvectors corresponding to eigenvalues of high amplitudes.
In Power Iteration or Lancsoz Iterations, the
Hessian vector product is used to ﬁnd the largest amplitude eigen pairs.
However, to ﬁnd the smallest amplitude eigen pairs, Inverse Hessian vector product operator is required, it is much more expensive to compute such operator, but practically, there is little practical use for those dimensions.
Thus we can deﬁne an arbitrary basis in the ”null” space complementing to the eigenspace with higher amplitude eigenvalues.
There are two ways of constructing a Hessian vector product operator: one way requires the computational graph from z to the gradient g ( z ) , and computes the HVP by back-prop, i.e.
HV P backward ; the other way is to use the ﬁrst-order gradient and ﬁnite difference to compute HVP i.e. HV P forward .
As it doesn’t require backpropagation, a single operation of HV P forward is much faster than HV P backward
but it is less accurate and takes more iterations to converge.
We use the ARPACK(Lehoucq et al., 1998) implementation of the Lancosz algorithm as the iterative eigenvalue solver,
[Equation]
We denote the direct method Full BackProp (BP), the iterative method using HV P backward and
HV P forward Backward Iteration and Forward Iteration respectively.
Empirically, we computed the
Hessian at the same z 0 using these three methods in different GANs and compared their temporal cost in Table A.2.
Note, our method can be employed to compute the singular values and right singular vectors of the
Jacobian from latent space towards any intermediate layer representation.
To obtain the left singular vector, we need to push forward the right singular vectors through the Jacobian, which is feasible through forward-mode autodiff or ﬁnite difference.
A. S PECIFICATION OF GAN L ATENT S PACE
The pretrained GANs used in the paper are from the following sources.
[Table] DCGAN model is obtained from [Table]
https://pytorch.org/hub/ facebookresearch_pytorch-gan-zoo_dcgan/ .
It’s trained on 64 by 64 pixel fashion dataset.
It has a 120d latent space, using Gaussian as latent space distribution.
P rogressive Growing GAN (PGGAN) is obtained from torch hub https://pytorch.org/ hub/facebookresearch_pytorch-gan-zoo_pgan/
and we use the 256 pixel version.
It’s trained on celebrity faces dataset (CelebA).
It has a 512d latent space, using Gaussian as latent space distribution.
DeePSim, FC6GAN model is customly rewritten and translated into pytorch, with weights obtained from ofﬁcial page https://lmb.informatik.uni-freiburg.de/people/ dosovits/code.html of Dosovitskiy & Brox (2016).
The architecture is designed to mirror that of AlexNet, and the FC6GAN model is trained to invert AlexNet’s mapping from image to
FC6 layer.
Thus it has 4096 d latent space.
This model is highly expressive, but not particularly photorealistic.
BigGAN model is obtained through huggingface’s translation of DeepMind’s
Tensorﬂow implementation https://github.com/huggingface/pytorch-pretrained-BigGAN , we use biggan-deep-256 version.
It’s trained on ImageNet dataset in a class conditional way.
It has a 128d latent space called noise space, and a 128d embedding space for the 1000 classes called class space.
The 2 vectors are concatenated and sent into the network.
The distribution used to sample in noise space is truncated normal.
Here we analyze the metric tensor computed in the concatenated 256d space (BigGAN) or in the 128d noise space or class space separately (BigGAN-noise, class).
BigBiGAN model is obtained via a translation of DeepMind’s
Tensorﬂow implementation https: //tfhub.dev/deepmind/bigbigan-resnet50/1 , we use bigbigan-resnet50 version.
It’s trained on ImageNet dataset in unconditioned fashion.
It has a 120d latent space, using Gaussian as latent distribution.
Note, the latent vector is split into six 20d trunks and sent into different parts of the model, which explains why the spectrum of BigBiGAN has the staircase form (in Fig. 2).
StyleGAN model is obtained via a translation of NVIDIA’s
Tensorﬂow implementation https:// github.com/rosinality/style-based-gan-pytorch .
We use the 256 pixel output.
It has a 512d latent space called Z space, where the latent distribution is Gaussian distribution.
This Z distribution gets warped into another 512d latent space called W space, by a multi-layer perceptron.
The latent vector W is sent into a style-based generative network, in which the latent vector modulates the feature maps in the conv layers, instead of just serves as a spatial input as in
DCGAN,FC6GAN,PGGAN.
We analyzed the geometry of Z space and W space separately, and ﬁnd that the metric in W space is signiﬁcantly ﬂatter and more homeogeneous!
StyleGAN2 models are obtained via a translation of NVIDIA’s Tensorﬂow implementation https://github.com/rosinality/stylegan2-pytorch .
It’s similar to StyleGAN: it has a similar structure of the 512d Z and W space, and the style-based generative network.
The various pre-trained models are fetched from https://pythonawesome.com/ [Table] a-collection-of-pre-trained-stylegan-2-models-to-download .
More speciﬁcally StyleGAN2-Face256 and 512 are both trained on FFHQ dataset, while Face generate lower resolution images and use narrower conv layers.
StyleGAN2-Cat is trianed on
LSUN cat dataset at 512 resolution.
WaveGAN model is obtained from the repository https://github.com/ mostafaelaraby/wavegan-pytorch/ .
Its architecture resembles that of DCGAN, but applied in 1 dimension wave form generation problem.
We customly trained it on the wave forms from clips of piano performance.
It has a 100d latent space, using Gaussian as latent space distribution.
A. Q UANTIFICATION OF P OWER D ISTRIBUTION IN S PECTRA
We quantiﬁed the anisotropy of the space, i.e. the low rankness of the metric tensor in Table 2.
To do this, we computed the number of eigenvalues needed such that their sum will account for a fraction of 0.99, 0.999, 0.9999, 0.99999 of the sum of all eigenvalues.
This can be thought of as the fraction of dimensions one needs to achieve a low rank approximation of the Jacobian with 0.01, 0.001, 0.0001, 0.00001 residue in terms of the Frobenius norm. A. G EOMETRIC S TRUCTURE IS R OBUST TO THE I MAGE D ISTANCE M ETRIC
Our work used the LPIPS distance metric to compute the Riemannian metric tensor.
To determine how much of the results depended on this choice of metric, we computed the metric tensor at the same hidden vector using different image distance functions, speciﬁcally a) structural similarity index measure (SSIM) and b) Mean Squared Error (MSE) in pixel space, which do not depend on
CNN. We computed the Hessian at 100 random sampled vectors in BigGAN, Progressive Growing GAN (Face), StyleGAN2 (Face 256), using MSE, SSIM and LPIPS, and then compared the Hessian spectrum and eigenvectors. We found that the entry-wise correlation across the Hessian matrices ( d 2 elements) ranged from [0.94-0.99].
The correlation of eigenvalue spectra ranged from [0.9870.995].
Measuring Hessian similarity using the statistics we derived C Hlog and C Hlin resulted in correlations concentrated at 0.99. Thus, we found that the Hessian matrix and its spectra were highly correlated across image distance metrics, and that the Hessian matrices had a similar effect on the eigenvectors of each other. One major difference across Hessians from different Image Distance Metric was evident in the scale of the eigenvalues. We regressed the log Hessian spectra induced by SSIM or MSE onto the log Hessian spectrum induced by LPIPS, and found the intercepts of the regression were usually
We experimented with BigGAN, PGGAN and StyleGAN2 (FFHQ 256 resolution), we compared the
Hessian computed by LPIPS and that by MSE or SSIM
100 hidden showed
[Table]
not zeros (Tab. 5).
This result showed different image distance metrics exhibit different ”unit” or intrinsic scale, although they all factored out the same structure in the GAN.
This result is contextualized by Section 5.
As equation 3 showed, the Riemannian metric or Hessian of the GAN manifold is the inner product matrix of the Jacobian of the representational map.
The effect of image difference metric on the Riemannian metric is to add a few more terms to the top of the chain of Jacobians.
The Jacobian terms from the layers of GAN seem to have a larger effect than the ﬁnal terms coming from the image dissimilarity metric.
Note that this doesn’t mean that the choice of sample space distance function is irrelevant.
Going beyond image generation, when applying our method to an audio generating GAN, the WaveGAN, we found that the choice of distance function in the space of sound waves will substantially affect the Hessian obtained.
We used the MSE of wave forms and MSE of spectrograms (denoted by
STFT) to compute metric tensor of that sound wave manifold.
We found the element-wise Hessian correlation between these is around 0.53, while the other Hessian similarity metric are also lower than the counterparts for BigGAN, PGGAN and StyleGAN2 (5).
We think the MSE of spectrograms are better and more perceptual distance measure of sound wave than MSE of wave forms, and this difference are reﬂected in their geometry property i.e. anisotropy and homogeneity (Tab. 2, 4).
Thus, when and how the sample space distance metric will affect the geometry of generative model still requires more development to be answered.
Here we give a simple derivation of why a highly ill-conditioned Hessian matrix may appear normal, under the probe of random vectors.
Given a symmetric matrix H , and its eigen decomposition
U Λ U T , we computed its effect on an isotropic random vector v , α ( v ) = v T H v / v T v , and v ∼
N (0 , I ) .
This random variable represents the effect of the symmetric matrix on random directions.
Note that a change of variable using the orthogonal matrix w =
U T v will not change the distribution w ∼ N (0 , I ) .
Through this the random variable α could be rewritten as
[Equation] [Equation]
As each element in w is distributed as i.i.d. unit normal, w 2 i is distributed as i.i.d.
chi-square distribution of parameter 1.
w 2 i ∼ χ 2 (1) ∼ Γ( 12 , 12 ) .
Thus the normalized weights c i =
w 2 i / (cid:80) i
w 2 i conform to a Dirichlet distribution c ∼ Dirichlet ( 12 , 12 , ... 12 ) .
Through moment formula of Dirichlet distribution, it is straightforward to compute the mean and variance of α ( w ) =
c T λ
[Equation]
As we can see, the variance of the effect on random directions scales 1 /n relative to the variance of original eigenvalue distribution.
This is why the distribution is much tighter than the whole eigenvalue distribution.
This phenomenon may explain why the perceptual path length regularization as used in Karras et al.
(2020) doesn’t really result in a ﬂat spectrum.
This regularization is to minimize E v (cid:107) α ( v ) − b (cid:107) 2 , which is to minimize the variance of the distribution of α ( v ) with v sampled from normal distribution, as in Fig.
The global minimizer for this regularization is indeed a mapping with ﬂat spectrum.
However, through our derivation, we can see even for highly anisotropic spectrum, this variance will not be very large.
Thus we should expect a limited effect of this regularization.
A. M ETHOD TO Q UANTIFY M ETRIC S IMILARITY
We developed our own statistic to quantify the similarity of metric tensor between different points.
Here we discuss the beneﬁts and caveats of it.
Angles between eigenvectors per se are not used, because eigenvectors are likely to rotate into each other when computing eigendecomposition in the presence of close-by eigenvalues (Van der Sluis & Van der Vorst, 1987).
However, the statistics should be invariant to this eigenvector mixing, and take the eigenvalues into account.
We applied the eigenvectors U 1 =
[ u 1 ,i , ... ] of one matrix
H 1 to the other H 2 and examined the length of these vectors as measured by the other matrix as the metric tensor, α H 2 ( u 1 ,i ) =
u Ti H 2 u i .
Recall that α H 1 ( u 1 ,i ) =
u T 1 ,i H 1 u 1 ,i = λ
1 ,i and α H 2 ( u 2 ,i ) =
u T 2 ,i H 2 u 2 ,i = λ
2 ,i .
If the eigenvectors fall in the eigenspace of the same eigenvalue in H 2 , then α ( u 1 ,i ) will equal the eigenvalue, and thus our statistic is invariant to rotation within the eigenspace.
If the eigenvectors are totally uncorrelated, the resulting α ( u 1 ,i ) will distribute in a tight distribution.
As we compute the correlation between the eigenvalue λ 2 ,i = α H 2 ( u 2 ,i ) and the α H 2 ( u 1 ,i ) , we summarize the similarity of action of H 2 on eigenvectors U 1 and U 2 .
However, this method assumes an anisotropy of spectra in both metric tensors.
For example, if both tensors are identity matrices H 1 = H
=
I , then this correlation will give NaN, as there is no variation in the spectra to be correlated.
Similarly,if metric has has a spectrum closer to ﬂat, then it will generally have a smaller correlation with others.
In that sense, spectral anisotropy also plays a part in our statistics for metric similarity or homogeneity of the manifold.
In all the GAN space we examined, there is a strong anisotropy in the metric spectra, thus this correlation works ﬁne.
But there is caveat for comparing this correlation between two GANs when there is also difference in the anisotropy in their spectra, as a smaller anisotropy can also results in a smaller metric similarity.
Finally, we are aware that several measures of distance in the space of symmetric positive deﬁnite matrices (SPSD) have been proposed (Yuan et al., 2020).
Thus, there are different ways to compute an average metric tensor using these distance function.
Here we picked the simplest one: averaging the metric tensors element by element.
A. G EOMETRIC S TRUCTURE OF W EIGHT -S HUFFLED GAN S
Here we show the geometric analysis for the shufﬂed controls for all our GANs.
Speciﬁcally, we shufﬂed the elements of each layer weight tensor to keep the overall weight distribution unchanged. [Table] u e n c y D e n s i t y DCGAN
{+Theory 4.8e-2(3.5e-2) Empir 4.9e-2(3.5e-2) −12 −10 − − − −
 FC6GAN+}
Theory 1.6e-4(3.8e-5)
Empir 1.6e-4(3.6e-5) −   4 0.
F r e q u e n c y D
e n s i t y
BigGAN
Theory 1.1e2(8.4e1)
Empir 1.1e2(8.3e1) − − 0 0.
PGGAN
Theory 7.4e-2(4.3e-2)
Empir 7.4e-2(4.2e-2) − − −  2 0.
BigBiGAN
Theory 3.9e0(2.3e0)
Empir
[Figure]
[Figure]
[Figure]
[Figure]
Amplification of random vector
Apparent and Real Spectral
Anisotropy Comparison
[Figure]
(FC6GAN, DCGAN, BigGAN, BigBiGAN, PGGAN, StyleGAN, StyleGAN2)
The apparent speed of image change α ( v ) has much smaller variability than the variability in the whole spectra.
Eq.can predict the mean and std of the apparent variability.
To show how learning affected the geometry of the image manifold, we computed the spectra and the associated metric consistency statistic for weight-shufﬂed GANs 2 .
In Fig.
7, we showed that the shufﬂed controls exhibited a ﬂatter spectrum and a smaller top eigenvalue.
There, the correlation of metric tensors in shufﬂed GANs shows an unclear result.
In some
GANs, there remains strong correlations in the metrics across locations, while in some, the correlation is close to zero.
We think the reason is that our statistic for homogeneity (i.e. a correlation of action of metric tensors C Hlogij ) somewhat entangles homogeneity with the anisotropy of the space.
That is, when the space has a totally ﬂat spectrum (the map is isometric), then the correlation coefﬁcient of action will be zero, although the metric tensor will be the same everywhere.
Thus the change of anisotropy and the change of homogeneity may interfere with each other, thus shufﬂing can result in a mixed result.
We are working to develop new statistics that will measure the similarity of the Hessian, invariant of anisotropy.
[Table] [Table]
A. D ETAILED C OMPARISON TO P REVIOUS U NSUPERVISED W AYS TO D ISCOVER I NTERPRETABLE A XES
Here we compare the axes discovered by our method with those from a previous approach.
Specifically, we applied our method to the same pre-trained GANs used in Voynov & Babenko (2020), comparing the axes they discovered versus our Hessian structure.
Although this method follows a much more different approach compared to ours and those of (H¨ark¨onen et al., 2020; Shen & Zhou, 2020), we thought it would be interesting to determine if the interpretable axes discovered in their approach had a relationship with the Hessian structure deﬁned above.
If so, this could serve as independent conﬁrmation of the effectiveness of both types of approaches.
In their work, for each generative network G , two additional models were simultaneously trained to discover interpretable axes: a ”deformator” M and a ”latent shift predictor” P .
The ”deformator” M learned to propose vectors { v i } to alter the image, which were used to create images pairs ( G ( z ) , G ( z + v i )) using random reference vectors z ; the ”latent shift predictor” P took in the images pairs and learned to classify the direction in which the latent code shifted ˆ v i =
P ( G ( z ) , G ( z + v i )) .
The axes learned by the deformator M were subsequently annotated and a subset was selected by humans.
Using their code, we compared these annotated axes with the Hessian structure we computed on their GANs (PGGAN512, BigGAN noise and StyleGAN Face).
In PGGAN512, we found that their discovered axes had a signiﬁcantly larger v T Hv (i.e. approximate rate of image change) than
[Figure]
l o g ( e i g e n v a l u
[Figure] [Figure]
l o g ( e i g e n v a l u e )
[Figure]
random vectors in that space; in other words, their axes were signiﬁcantly more aligned with the top eigen space ( P ¡ 0.05 for all axes).
Further, we wanted to investigate whether their axes aligned with individual eigenvectors identiﬁed by our Hessian or whether their axes randomly mixed with our top eigen space.
To achieve this goal
[Figure]
we search for the power coefﬁcients that are signiﬁcantly higher than expected from projection of unit random vector.
In fact, for each and every of the discovered axes, we found 1-3 eigenvectors that they are signiﬁcantly ( p < 5 × 10 − 4 ) aligned to.
Moreover, these strongly aligned eigenvectors are all in our top 60 eigen dimensions, in fact, 3 of their axes aligned with eigenvector 11 and 2 of their axes aligned with our eigenvector 6.
(Fig.8 A)
Moreover, we ”purify” their axes by a) retaining projection coefﬁcients only in top 60 eigenvectors, or b) retaining the coefﬁcients only in the 1-3 strongly aligned eigen vectors and set all the other 500+ coefﬁcients to zero, and compared their effect on a same set of reference vectors, using the same step size.
We found that by project out coefﬁcients in the lower space, the image transformation is perceptually very similar (Fig.8 B,C).
If we only retains the eigenvectors that it highly aligns to, the image transform will be more different, but the annotated semantics in the transform seems to keep (Fig.8 D,E).
Thus, their method also discovered that the top eigenspace of PGGAN contained informative transformations, and further conﬁrmed that optimizing interpretability may improve alignment with individual eigen vectors rather than mixing all the eigen dimensions.
Note, as we project out coefﬁcients, the resulting vector has a smaller than unit norm, thus we are moving a smaller distance in latent space using the same step size (8 B-E title).
If we renormalize the vector to unit norm we will need to take a smaller step size to achieve the same transform.
This is conﬁrming our predictions in Sec. 4: Each interpretable axis has a family of equivalent axes, which add a direction in the lower eigenspace or null space of the GAN.
These axes encode the same transforms but the speeds of image change on them are different.
In this sense, the top eigenspace could be used to provide a ”purer” version of the interpretable axes discovered elsewhere.
Although both types of approaches are promising, by removing the need to train additional networks, our method can be viewed as a more efﬁcient way to identify informative axes.
Further work comparing axes discovered by different methods will elucidate the connection between interpretable axes and the Hessian structure more.
eigen rank
A nn o t a t e d
A x e s
LatentDiscovery Axes         eigen rank 45 r a n d o m v e s t
o r s
Random Control
PGGAN512 Annotated Axes Proj
Hess Frame 0.010.
AlignedEigenvector Id
[Figure] [Figure] [Figure]
of Action of Eigenvector
on
Difference References
[Figure]