Compressing GANs using Knowledge Distillation

02/01/2019 ∙ by Angeline Aguinaldo, et al. ∙ 0

Generative Adversarial Networks (GANs) have been used in several machine learning tasks such as domain transfer, super resolution, and synthetic data generation. State-of-the-art GANs often use tens of millions of parameters, making them expensive to deploy for applications in low SWAP (size, weight, and power) hardware, such as mobile devices, and for applications with real time capabilities. There has been no work found to reduce the number of parameters used in GANs. Therefore, we propose a method to compress GANs using knowledge distillation techniques, in which a smaller "student" GAN learns to mimic a larger "teacher" GAN. We show that the distillation methods used on MNIST, CIFAR-10, and Celeb-A datasets can compress teacher GANs at ratios of 1669:1, 58:1, and 87:1, respectively, while retaining the quality of the generated image. From our experiments, we observe a qualitative limit for GAN's compression. Moreover, we observe that, with a fixed parameter budget, compressed GANs outperform GANs trained using standard training methods. We conjecture that this is partially owing to the optimization landscape of over-parameterized GANs which allows efficient training using alternating gradient descent. Thus, training an over-parameterized GAN followed by our proposed compression scheme provides a high quality generative model with a small number of parameters.

READ FULL TEXT VIEW PDF
POST COMMENT

Comments

There are no comments yet.

Authors

page 3

page 5

page 6

page 8

This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

Generative Adversarial Networks (GANs) were first introduced in 2014 as a generative model that attempts to capture the underlying distribution of complex real world data sets (Goodfellow et al., 2014). GANs are applied to many real world applications including domain transfer, super resolution, and generation of novel celebrity faces (Karras et al., 2018) (Zhu et al., 2017) (Ledig et al., 2017)

. The first GAN implemented by Ian Goodfellow, used no more than 100,000 parameters, otherwise referred to as hidden units or neurons

(Goodfellow et al., 2014). In one of NVIDIA’s most recent publications, the company’s network used over 23 million parameters to generate realistic celebrity faces with high resolution (Karras et al., 2018). Most recently, Google’s BigGAN has over 158 million parameters used to generate photo-realistic still life imagery (Brock et al., 2018). We anticipate that the size of GANs will continue to increase, as their applicability continues to grow. If we want to make GANs practical for low SWaP (size, weight, and power) hardware, such as mobile devices, and for applications with real time capabilities then being able to compress models becomes an important issue to overcome.

There has been recent progress in the area of neural network compression

(Liu et al., 2019) (Ba & Caurana, 2013) (Urban et al., 2017) and various compression techniques have been exercised to solve this problem (Belagiannis et al., 2018) (Xu et al., 2017) (Yim et al., 2017) (Kim & Kim, 2017). The popular compression techniques can be mostly categorized into five schemes: quantization (Li et al., 2017), pruning and sharing weights, low rank factorization, compact convolutional filter, and knowledge distillation (Cheng et al., 2017). These techniques are able to reduce the number of parameters by up to 90% to 95% while retaining performance (Cheng et al., 2017). Some of these compression techniques also accompany corollary benefits. In the case of knowledge distillation, the compressed model may be able to generalize better in addition to being significantly smaller (Hinton et al., 2015).

Despite the aforementioned work, to our knowledge, there is no result involving the compression of GANs. This leads to the work described in this paper, where we show adaptations that must be made to the knowledge distillation paradigm in order to achieve optimal compression of networks in the generative setting. Serving as motivation for these adaptations is the idea that large over-parameterized networks have nicer loss landscapes than smaller ones, and are thus able to learn better quality mappings, regardless of whether an approximately equivalent mapping exists for smaller networks. We experimentally validate these methods on several datasets and via a number of objective measurements. Lastly, we discuss the limit of compression in the GAN setting and how it appears in empirical results.


Figure 1: The top row shows Inception Score and Frechet Inception Distance comparison for various sizes of GANs, where GAN size is determined by the depth scale factor, , and 3 different datasets - MNIST, CIFAR-10 and Celeb-A (left to right). The students are trained using the MSE loss training scheme 3.2. A high Inception Score is good and a low Frechet Inception Distance is good. The bottom row shows samples of generated images from the students and teacher GANs as a result of corresponding compression.

2 Background

2.1 Generative Adversarial Networks

GAN was first proposed as a two player min-max optimization problem between a discriminator and a generator as in (1) (Goodfellow et al., 2014). The generator is tasked with generating realistic examples that fool the discriminator while the discriminator learns how to differentiate between the real and the generated samples.

(1)

The optimization in (1) has a global minimum and the system converges when at which point,

cannot classify a sample as being generated from

or from . Further, the optimal solution to (1) corresponds to minimizing the Jensen-Shannon (JS) divergence between the two distributions and (Goodfellow et al., 2014). However, training of GANs is often unstable because JS divergence is not well defined when and do not have the same support (Arjovsky et al., 2017). To solve the problem with using JS divergence, WGAN minimizes the Wasserstein’s distance between and in place of the JS divergence(Arjovsky et al., 2017), which is well defined even when and have disjoint support. Specifically, WGAN attempts to solve the optimization problem in (2), where is a Lipschitz bounded function. (Arjovsky et al., 2017).

(2)

WGAN was used in place of regular GAN for most of our experiments due to its favorable characteristics. However, empirically, we noticed that WGAN does not work as well for the Celeb-A dataset, so we reverted to using regular GAN for all Celeb-A related experiments.

2.2 Knowledge Distillation

Knowledge distillation refers to the technique of transferring the knowledge learned, from an ensemble of networks to a single network, or from a network with high number of parameters, to a network with relatively low number of parameters. We refer to the bigger network as the teacher network and the smaller network as the student network.

A student can learn to match any activation layer in the teacher network. Learning parameters from the final layer, called hard targets, lends itself to shorter training time but increased chance of over-fitting. The inputs to the softmax layer (logits) of the teacher network, referred to as soft targets, on the other hand, have more descriptive information about the samples and give better generalization characteristics to the student network

(Hinton et al., 2015), which makes training on soft targets more beneficial.

2.3 Over-parameterization of Networks

An over-parameterized network is described as one whose number of hidden units is polynomially large relative to the number of training samples (Allen-Zhu et al., 2018b). It has been shown that training a significantly over-parameterized GAN yields dramatically better results than those generated from a smaller network (Brock et al., 2018)

. This may be explained by a finding that showed that the over-parameterization of neural networks creates optimized loss functions with many good minima spread throughout the entire loss landscape allowing for efficient training with alternating gradient descent

(Allen-Zhu et al., 2018b) (Allen-Zhu et al., 2018a). This theory was bolstered by recent empirical studies of loss functions using visualization methods (Li et al., 2018). Therefore, it is necessary that a bigger network learn these mappings in a hyper-parameterized space before it can be distilled to a simpler model. Likewise, there has been empirical evidence that knowledge distillation, or model compression, is successful (Hinton et al., 2015) (Buciluǎ et al., 2006) (Yim et al., 2017). This success may be attributed to the aforementioned phenomena. Although training a teacher network might require a higher number of parameters, a reduced number of parameters is sufficient to describe the model with high fidelity.

3 Methods

The teacher (large, over-parameterized network) and student (small, few parameter network) GANs used either the original DCGAN architecture or a slightly modified DCGAN architecture (Radford et al., 2015), more closely resembling the WGAN (Arjovsky et al., 2017), referenced as the W-DCGAN.

The number of parameters in our networks is controlled by the depth scale factor, referenced throughout the paper as . The overall number of parameters increases approximately linearly to .

3.1 Selection of Teacher Network

We first trained W-DCGANs of various sizes until convergence, and then selected the best performing model to be the teacher network. This ensures that the teacher network has converged approximately to an optimal solution. Because there currently does not exist an exact measure of visual quality, we use Inception Score and Frechet Inception Distance as proxies for performance. Figure 2 illustrates the Inception Score performance and Frechet Inception Distance (FID) performance respectively, to be discussed in Section 4, with respect to layer depth, .

3.2 Training of Student Networks

We train several student networks with smaller capacities than the teacher network using two training schemes. Results for all three datasets were produced using the MSE Loss training scheme. Due to the complexity of the Celeb-A dataset, the joint loss training scheme was designed to combat observed blur artifacts of compression. Both training schemes are described below. For both functions, we monitored the convergence of the student network based on the generated outputs and the loss trajectory.


Figure 2: The Inception Score and Frechet Inception Distance was used to evaluate the best teacher GAN, parameterized by the depth scale factor . A high Inception Score is good and a low Frechet Inception Distance is good. From these results, we selected a teacher GAN size of for MNIST, for CIFAR-10 and for Celeb-A (left to right).

Figure 3: Student-teacher training framework with mean squared error (MSE) loss for student training. The teacher generator was trained using DCGAN framework (Radford et al., 2015) including WGAN modifications (Arjovsky et al., 2017). A mathematical analogy is shown in (3).

Mean Squared Error (MSE) loss. This method uses the MSE as the student training loss function using a pre-trained teacher W-DCGAN. A schematic of the training framework is illustrated in Figure 3. The MSE loss minimizes the pixel-level error between the images generated from the student and the teacher. Specifically, we train the student by solving the following optimization problem:

(3)

Joint loss. The generated images tend to be slightly blurry when using the MSE loss, especially for the Celeb-A dataset. To combat the blurriness, we propose a joint loss function that supervises regular GAN training with MSE loss. Specifically, the joint loss train the student by solving the following optimization problem:


Figure 4: Student-teacher training framework with joint loss for student training. The teacher generator was trained using DCGAN framework (Radford et al., 2015). A mathematical analogy is shown (4).
(4)

The parameter controls the weight between the MSE loss and the regular GAN training. A schematic of the training framework is illustrated in Figure 4.

4 Analysis

In the case of classification networks, the performance can be measured by the classification accuracy. Unlike classification networks, GANs do not have an explicit measure for performance. The performance of GANs could be naively measured by human judgment of visual quality (Goodfellow et al., 2014). For example, one could collect scores (1 to 10) of visual quality from various subjects and average the scores to understand the performance of GANs. However, the method is very expensive. The score could also vary significantly based on the design of the interface used to collect the data (Goodfellow et al., 2014)

. To evaluate the performance of GANs more systematically, the field has developed several quantitative metrics. Some of the popular metrics are Inception Score and Frechet Inception Distance (FID). Additionally, we used Variance of Laplacian to evaluate the blurring artifacts inherent to compressing GANs trained on complex datasets.


Figure 5:

A comparison of the student and the teacher on inputs interpolated between a representation of ”8” and a representation of ”1”.

4.1 Inception Score (IS)

There are two important things that we would like to see in images generated from good GANs. First, we would like it to generate diverse images. We would like to be relatively equal across different classes (Goodfellow et al., 2014). Secondly, given a generated image, we would like to be confident of the class in which the image belongs. Given a generated image x, we would like to be very concentrated in a particular class (Goodfellow et al., 2014). To take both of the desired qualities into account, the cross entropy, , between and can be taken, otherwise known as the Inception Score.

(5)

If is similar across classes and is very concentrated in a particular class, then the cross entropy between the two distributions will be high. Consequently, the Inception Score will be high.

The Inception Scores makes a few assumptions. First, it assumes that the image can be classified yielding and

, but not all images can be classified. For example, in our experiments with the Celeb-A dataset, we could not use Inception Score because the data set does not have labels associated with them. Second, the Inception Score is sensitive to the weights of the classification network. The Inception Score assumes a network architecture designed for classification, and the Inception Score could change drastically with different networks. Further, the calculation of Inception Score assumes that the soft-max layer of a neural network is equivalent to the probability distribution. It can be said that soft-max layer of a neural network is not necessarily the probability distribution despite summing to unity.

Finally, the Inception Score is not able to detect memorization of examples. For example, if a GAN remembers exactly one image from each class, then the Inception Score will be very high as will be exactly the same across all classes and will be very concentrated.

Despite the aforementioned, it is one of the most commonly used metrics for GAN evaluation. It is also found to correlate well with human judgment of image qualities (Goodfellow et al., 2014). Therefore, we used Inception Score to select the best MNIST teacher model and to evaluate the MNIST student models.

4.2 Frechet Inception Distance (FID)

To improve upon the Inception Score, Frechet Inception Distance was introduced to identify GANs that simply memorized a few images from each class (Heusel et al., 2017). The Frechet Inception Distance assumes that when differing images are fed through the same network, their corresponding values from the same activation layer will have different distributions. If the activation distributions of the generated images and the real images differ greatly, then it is likely that the generated images look significantly different from the real images and vice versa. Formally, Frechet Inception Distance measures the difference of the activation distributions with Frechet distance (Heusel et al., 2017):

(6)

Empirically, it has been shown that Frechet Inception Distance almost always increases monotonically as you increase the distortion to a real images (such that they look less like real images), regardless of the type of distortion applied (Heusel et al., 2017). Additionally, it is robust in detecting mode collapse in GANs (Lucic et al., 2018).

Though Frechet Inception Distance still suffers from similar downsides as Inception Score, its ability to identify mode collapse makes it more robust compared to Inception Score. It is used in our experiments to select the best teacher GAN and to evaluate the performance of the student GANs for CIFAR-10 and Celeb-A datasets.

4.3 Variance of Laplacian (VoL)

The variance of laplacian of an image gives a measure of the sharpness of the image (Pech-Pacheco et al., 2000). The Laplacian filter, when applied on an image, gives the second order derivative of the discrete image function. It thus highlights the regions of an image containing rapid intensity changes - the edges. A sharper image will have more well defined edges than a blurred image. The Variance of Laplacian metric quantifies the amount of edges in an image. Higher VoL corresponds to sharper images. We use this metric to compare the outputs of the student generator trained using the MSE loss versus those trained using the joint loss.

5 Results

Figure 7: Comparison between results from teacher GAN , student GAN , and a regularly trained GAN of depth (control) on the CIFAR-10 dataset using the MSE loss training scheme as described in Figure 3.
Figure 6: Comparison between results from teacher GAN , student GAN , and a regularly trained GAN of depth (control) on the MNIST dataset using the MSE loss training scheme as described in Figure 3.
Figure 7: Comparison between results from teacher GAN , student GAN , and a regularly trained GAN of depth (control) on the CIFAR-10 dataset using the MSE loss training scheme as described in Figure 3.
Figure 8: Comparison between results from teacher GAN , student GAN , and a regularly trained GAN of depth (control) on the Celeb-A dataset using the MSE loss training scheme as described in Figure 3.
Figure 6: Comparison between results from teacher GAN , student GAN , and a regularly trained GAN of depth (control) on the MNIST dataset using the MSE loss training scheme as described in Figure 3.

5.1 MSE Loss Training

Quantitative Results. We compare the performance of the compressed GANs with the teacher WGAN and the regular WGANs of the same sizes. Ideally, the compressed GAN will perform close to the teacher WGAN and better than the regular WGANs of the same sizes. Again, because there currently does not exist an exact measure of visual quality, we use Inception Score and Frechet Inception Distance as proxies for performance.

From Figure 1 and Table 1, we can see that the student GANs consistently outperform the regular GAN across all compression level on the MNIST data set. Also, the student GANs perform comparable to the teacher GAN which has significantly larger capacity. In the most extreme case for MNIST, we were able to compress the student model by 1,669 times while retaining 83% of the teacher’s Inception Score.

Similarly, we see that the student GANs consistently outperform the regular GANs of the same sizes, on the CIFAR-10 and Celeb-A dataset. However, because the CIFAR-10 and Celeb-A datasets have images with more complex features than the MNIST dataset, we were unable to achieve the same magnitude of compression as that of the MNIST dataset.

We found that the compression strategy is extremely robust to hyperparameter tuning, datasets, and evaluation metrics. The compressed student models consistently outperform W-DCGANs of similar size with respect to all changes in our setups.

GAN Size ()
2 4 8 16 32 48 64 128
No. of Parameters 28,351 62,077 145,657 377,329 109,8721 216,4177 3,573,697 12,652,417
MNIST Ratio 1669:1 762:1 325:1 125:1 43:1 13:1 4:1
IS (Stu.) 5.80 6.41 6.60 6.83 6.87 6.93 6.97
IS (Reg.) 1.86 3.63 4.73 5.07 6.08 6.51 6.63
CIFAR-10 Ratio 126:1 58:1 25:1 9:1 3:1 2:1
FID (Stu.) 11.76 11.00 9.57 8.39 7.80 7.58
FID (Reg.) 38.72 14.28 11.85 9.90 7.86 7.64
Celeb-A Ratio 446:1 204:1 87:1 34:1 12:1 6:1 4:1
FID (Stu.) 12.15 10.97 8.78 6.29 4.84 4.54
FID (Reg.) 45.49 18.72 11.06 9.14 5.05 4.62
Table 1: Compression Ratios and Image Quality Metrics for MNIST, CIFAR-10, Celeb-A. The respective metrics (IS, Inception Score and FID, Frechet Inception Distance) are shown for both the student GAN (Stu.) compared to a regularly trained GAN (Reg.) of corresponding size. For MNIST, CIFAR-10, and Celeb-A, the ratio shown is with respect to a teacher generator size of depth (47,324,929 parameters, IS = 7.02), (3,573,697 parameters, FID = 7.42), and (12,652,417 parameters, FID = 4.39) respectively. All teacher GANs were trained with a discriminator of corresponding teacher depth.

Qualitative Results. Because of the deficiencies of the Inception Score and Frechet Inception Distance, it is important to qualitatively review the results. In Figures 8, 8, and 8, we are able to see a direct comparison between the teacher, student, and a regular GAN of comparable size to the student. A visual review shows that the student is able to approximate the teacher without compromising the visual integrity of the image despite having a high compression ratio. One drawback however, is the presence of blur in the outputs from the student generator. This blur becomes more prominent as the compression ratio increases. The student generator is able to generate the basic structure of the image but fails to add details. This is unlike the control generator of the same size, which, although generates sharp images, misses on the basic image structure.

The student GAN thus outperforms the control GAN of the same size. This demonstrates the superiority of compressing an over-parameterized GAN, rather than training a small sized generator using the adversarial framework. Figure 5

shows the output of interpolating the student and the teacher between two input vectors. We can see that the student is able to generate comparable images to that of the teacher’s for each interpolation delta. This demonstrates that the student is learning to approximate the teacher’s generation function, and not memorizing specific trained outputs.

5.2 Joint Loss Training

In Figure 9, student GANs trained with joint loss outperform networks trained with only MSE loss in terms of slightly better FID scores. In Figure 10, the joint loss GANs perform significantly better in terms of VoL metric, meaning that they produce much sharper images compared to the MSE loss GANs. This can also be observed visually through comparisons of the generated images in Figure 11.


Figure 9: Frechet Inception Distance comparison for various sizes of GANs using the joint training scheme. A low FID score is good.

Figure 10: Variance of Laplacian (VoL) comparison to evaluate blurriness in generated images from the student GAN trained using MSE loss, and the student GAN trained using joint loss. The values are reported as a ratio of the VoL score for student to the VoL score of the teacher, for both the students. The scores have been averaged across 10 different generated images. A higher value means the image is more sharp.

Figure 11: Compression artifacts on the Celeb-A dataset from images generated from a teacher GAN (), student GAN trained using MSE loss and student GAN trained using joint loss at .

6 Discussion

6.1 Limit to Compression

Through visual examination, the degradation of generated images seem to happen at higher compression ratio for more complex datasets, assuming that complexity grows in the following order: MNIST, CIFAR-10, Celeb-A. The bottom row of Figure 1 show the outputs as a result of different compression ratios. The compressed MNIST GANs seem to have minimal compression artifacts across all compression levels whereas the compressed CIFAR-10 GANs seem to suffer significant degradation when . For the compressed Celeb-A GANs, the degradation happens at an even lower compression ratio for Celeb-A GANs at . The compression ratios referenced in the abstract is based on the smallest compressed GANs before significant observable degradation is present in the generated images. This observation suggests a potential limit to compression depending on the complexity of the data set.

6.2 Our Contributions

Our work contributes to the topic of GAN compression. To summarize, we have made the following contributions in this paper:

  • We have developed two compression schemes for GANs using a student-teacher learning architecture (Figures 3, 4).

  • We have evaluated the proposed compression methods over MNIST, CIFAR-10, and Celeb-A datasets. Our results show that the quality of generated imagery is maintained at high compression rates (1669:1, 58:1, 87:1 respectively) as measured by the Inception Score and Frechet Inception Distance metrics.

  • We show that training a GAN of the same size without knowledge distillation produces comparatively diminished results, supporting the conjecture that over-parameterization is both helpful and necessary for neural networks to find a good function for GANs.

  • We observe a qualitative limit to GAN’s compression for all the aforementioned datasets. We conjecture that there exists a fundamental compression limit of GANs similar to Shannon’s compression theory (MacKay, 2002).

7 Conclusion

Overall, we have demonstrated that applying the knowledge distillation method to GAN training can produce compressed generators without loss of quality or generalization. More specifically, we demonstrated that the student generators are able to outperform a traditionally trained GAN of the same size and approximate the underlying function of the teacher generator for the whole latent space. This further supports the necessity for over-parameterization when training an effective generator prior to distillation. Further, a qualitative limit to GAN compression has been observed for MNIST, CIFAR-10 and Celeb-A datasets.

References