はじめに
GAN Compression: Efficient Architectures for Interactive Conditional GANsの日本語訳です.
DeepLに丸投げしただけなので違和感あるところが多々あります.
少しでも参考になればよいと思います.
元の論文はこちらです.
https://arxiv.org/pdf/2003.08936.pdf#page=9&zoom=100,412,525
前半の記事はこちら
https://qiita.com/m_tani_july/items/c31ed3de93e1e685a578
3.Method
Compressing conditional generative models for interactive applications is challenging for two reasons. Firstly, the training dynamic of GANs is highly unstable by nature. Secondly, the architectural differences between recognition and generative models make it hard to apply existing CNN compression algorithms directly. To address these issues, we propose a new training protocol tailored for efficient generative models (Section 3.1) and further increase the compression ratio with neural architecture search (NAS) (Section 3.2). The overall framework is illustrated in Figure 3.
対話型アプリケーションのために条件付き生成モデルを圧縮することは, 2つの理由から困難である. 第一に, GANの学習ダイナミックは性質上非常に不安定である. 第二に, 認識モデルと生成モデルの間のアーキテクチャの違いにより, 既存のCNN圧縮アルゴリズムを直接適用することが困難である. これらの問題を解決するために, 我々は効率的な生成モデルに合わせた新しい学習プロトコルを提案し(第3.1節), ニューラルアーキテクチャ探索(NAS)を用いて圧縮率をさらに向上させる(第3.2節). 全体的なフレームワークを図3に示す.
3.1 Training Objective
Unifying unpaired and paired learning.
Conditional GANs aim to learn a mapping function G between a source domain X and a target domain Y . They can be trained using either paired data $( \Bigl\{ { x_i , y_i} \Bigr\}^N_{i=1} where\;\;x_i∈X \;\; and \;\; y_i∈Y\;\;$ or unpaired data (source dataset $ \Bigl\{ { x_i } \Bigr\}^N_{i=1} $ to target dataset $ \Bigl\{ { x_i } \Bigr\}^M_{i=1} $. Here, N and M denote the number of training images. For simplicity, we omit the subscript i and j. Several learning objectives have been proposed to handle both paired and unpaired settings (e.g., [27, 45, 58, 69, 38, 26]). The wide range of training objectives makes it difficult to build a general-purpose compression framework. To address this limitation, we unify the unpaired and paired learning in the model compression process, regardless of how the teacher model is originally trained. Given the original teacher generator G′ , we can transform the unpaired training setting to the paired setting. In particular, for the unpaired setting, we can view the original generator’s output as our ground-truth and train our compressed generator G with a paired learning objective. Our learning objective can be summarized as:
\begin{equation}
\mathcal{L}_{\text {recon }}=\left\{\begin{array}{ll}
\mathbb{E}_{\mathbf{x}, \mathbf{y}}\|G(\mathbf{x})-\mathbf{y}\|_{1} & \text { if paired cGANs } \\
\mathbb{E}_{\mathbf{x}}\left\|G(\mathbf{x})-G^{\prime}(\mathbf{x})\right\|_{1} & \text { if unpaired cGANs. }
\end{array}\right. \:\: (1)
\end{equation}
Here we denote
\begin{equation}
\mathbb{E}_{\mathbf{x}} \triangleq \mathbb{E}_{\mathbf{x} \sim p_{\text {data }}(\mathbf{x})} \;\; and \;\; \mathbb{E}_{\mathbf{x}, \mathbf{y}} \triangleq \mathbb{E}_{\mathbf{x}, \mathbf{y} \sim p_{\text {data }}(\mathbf{x}, \mathbf{y})}
\end{equation}
for simplicity. $||||_{1}$ denotes L1 norm.
With such modifications, we can apply the same compression framework to different types of cGANs. Furthermore, As shown in Section 4.3, learning using the above pseudo pairs makes training more stable and yields much better results, compared to the original unpaired training setting. As the unpaired training has been transformed into paired training, we will discuss the following sections in the paired training setting unless otherwise specified.
アンペア学習とペア学習の統一
条件付きGANは, ソースドメインXとターゲットドメインYの間の写像関数Gを学習することを目的としている. 条件付きGANは,対になったデータ$( \Bigl\{ { x_i , y_i} \Bigr\}^N_{i=1} where\;\;x_i∈X \;\; and \;\; y_i∈Y\;\;$を用いて学習することも,対になっていないデータ(元データセット$ \Bigl\{ { x_i } \Bigr\}^N_{i=1} $から対象データセット$ \Bigl\{ { x_i } \Bigr\}^M_{i=1} $まで)を用いて学習することも可能である.ここで, nとmは学習画像の数を表す. 対になった設定と対になっていない設定の両方を扱うために,いくつかの学習目的が提案されている(例えば,[27, 45, 58, 69, 38, 26]).学習目的の範囲が広いため, 汎用圧縮フレームワークを構築することは困難である. この制限に対処するために,我々は教師モデルがどのように元々訓練されたかに関わらず,モデル圧縮の過程で非ペアリング学習とペアリング学習を統一する.元の教師生成器G′が与えられれば,非対になっていない学習設定を対になっている設定に変換することができる.特に, 対になっていない設定では, 元の教師生成器の出力を我々の基底真実とみなし, 我々の圧縮された教師生成器Gを対になった学習目的で訓練することができる. 学習目的は次のように要約できます.
\begin{equation}
\mathcal{L}_{\text {recon }}=\left\{\begin{array}{ll}
\mathbb{E}_{\mathbf{x}, \mathbf{y}}\|G(\mathbf{x})-\mathbf{y}\|_{1} & \text { if paired cGANs } \\
\mathbb{E}_{\mathbf{x}}\left\|G(\mathbf{x})-G^{\prime}(\mathbf{x})\right\|_{1} & \text { if unpaired cGANs. }
\end{array}\right. \:\: (1)
\end{equation}
ここでは, 簡単のために
\begin{equation}
\mathbb{E}_{\mathbf{x}} \triangleq \mathbb{E}_{\mathbf{x} \sim p_{\text {data }}(\mathbf{x})} \;\; and \;\; \mathbb{E}_{\mathbf{x}, \mathbf{y}} \triangleq \mathbb{E}_{\mathbf{x}, \mathbf{y} \sim p_{\text {data }}(\mathbf{x}, \mathbf{y})}
\end{equation}
と表す. (** $ \triangleq $ は定義するって意味.L1距離はマンハッタン距離)
このように変更することで,同じ圧縮フレームワークを異なるタイプのcGANにも適用することができる.さらに,4.3節で示したように,上記の疑似ペアを用いた学習は,元の非対をとった学習設定と比較して,より安定した学習を行い,より良い結果を得ることができます.非対をとった学習が対をとった学習に変換されているので, 以下の節では, 特に指定のない限り, 対をとった学習設定で議論することにする.
Inheriting the teacher discriminator.
Although we aim to compress the generator, a discriminator D stores useful knowledge of a learned GAN as D learns to spot the weakness of the current generator [3]. Therefore, we adopt the same discriminator architecture, use the pre-trained weights from the teacher, and fine-tune the discriminator together with our compressed generator. In our experiments, we observe that a pre-trained discriminator is better than a randomly initialized discriminator which leads to severe training instability and the degradation of image quality. The GAN objective is formalized as:
\begin{equation}
\mathcal{L}_{\mathrm{cGAN}}=\mathbb{E}_{\mathbf{x}, \mathbf{y}}[\log D(\mathbf{x}, \mathbf{y})]+\mathbb{E}_{\mathbf{x}}[\log (1-D(\mathbf{x}, G(\mathbf{x})))] \: \:(2)
\end{equation}
where we initialize the student discriminator D using the weights from teacher discriminator D′ . G and D are trained using a standard minimax optimization [14]
教師判別器を継承する
我々は生成器を圧縮することを目的としているが, 識別器Dは現在の生成器の弱点を見つけるために学習するため, 学習したGANの有用な知識を保存する[3]. そこで,我々は同じ識別器アーキテクチャを採用し,教師からの事前学習済みの重みを使用し,我々の圧縮された生成器と一緒に識別器を微調整する.実験の結果, ランダムに初期化された判別器よりも事前に学習された判別器の方が, 学習の不安定さと画質の劣化を招くことがわかりました. GANの目的は次のように形式化されます.
\begin{equation}
\mathcal{L}_{\mathrm{cGAN}}=\mathbb{E}_{\mathbf{x}, \mathbf{y}}[\log D(\mathbf{x}, \mathbf{y})]+\mathbb{E}_{\mathbf{x}}[\log (1-D(\mathbf{x}, G(\mathbf{x})))] \: \:(2)
\end{equation}
ここでは,教師識別器 D′からの重みを用いて,生徒識別器 D を初期化する.G と D は,標準的な最小化最適化 [14] を用いて学習される
Intermediate feature distillation.
A widely-used method for model compression is knowledge distillation, which matches the distribution of the output layer’s logits [23, 43, 9, 63, 33, 46, 10]. However, conditional GANs [27, 69] usually output a deterministic image, rather than a probabilistic distribution. Therefore, it is difficult to distill the dark knowledge from the teacher’s output pixels. Especially for paired training setting, output images generated by the teacher model essentially contains no additional information compared to ground-truth target images. Experiments in our arXiv show that for paired training, naively mimicking the teacher model’s output brings no improvement. To address the issue, we match the intermediate representations of the teacher generator instead, as explored in prior work [33, 66, 9]. The intermediate layers contain more channels, provide richer information, and allow the student model to acquire more information in addition to outputs. The distillation objective can be formalized as:
\begin{equation}
\mathcal{L}_{\text {distill }}=\sum_{t=1}^{T}\left\|G_{t}(\mathbf{x})-f_{t}\left(G_{t}^{\prime}(\mathbf{x})\right)\right\|_{2} \:\: (3)
\end{equation}
where $ G_t(\mathbf{x}) $ and $ G^{\prime}_t(\mathbf{x}) $ are the intermediate feature activations of the t-th chosen layer in the student and teacher models, and T denotes the number of layers. ft is a 1 × 1 learnable convolution that maps the channels from the student model to the teacher model, since they have different channel numbers. We jointly optimize Gt and ft to minimize the distillation loss Ldistill. Our arXiv details which layers we choose in practice.
中間特徴蒸留.
モデル圧縮のために広く使われている手法は知識蒸留であり、出力層のロジットの分布と一致する [23, 43, 9, 63, 33, 46, 10]。しかし、条件付きGAN[27, 69]は通常、確率的分布ではなく決定論的なイメージを出力する。そのため、教師の出力画素から暗部知識を蒸留することは困難である。特に対になった学習設定の場合,教師モデルによって生成される出力画像は,基本的に基底真実のターゲット画像と比較して,付加的な情報を含んでいません.我々のarXivでの実験では、ペア学習の場合、教師モデルの出力を素朴に模倣しても何の改善ももたらさないことが示されています。この問題に対処するために,先行研究[33, 66, 9]で検討されたように,教師生成器の中間表現をマッチさせました.中間層はより多くのチャンネルを含み、より豊富な情報を提供し、生徒モデルが出力に加えてより多くの情報を取得することを可能にします。蒸留目的は次のように形式化することができます。
\begin{equation}
\mathcal{L}_{\text {distill }}=\sum_{t=1}^{T}\left\|G_{t}(\mathbf{x})-f_{t}\left(G_{t}^{\prime}(\mathbf{x})\right)\right\|_{2} \:\: (3)
\end{equation}
ここで、$ G_t(\mathbf{x}) $ と $ G^{\prime}_t(\mathbf{x}) $ は、生徒モデルと教師モデルのt番目に選択された層の中間特徴活性化であり、Tは層の数を表す。我々は,蒸留損失Ldistillを最小化するためにGtとftを共同で最適化する.我々のarXivでは、実際にどの層を選択するかを詳細に説明しています。
Full objective.
Our final objective is written as follows:
\begin{equation}
\mathcal{L}=\mathcal{L}_{\mathrm{cGAN}}+\lambda_{\text {recon }} \mathcal{L}_{\text {recon }}+\lambda_{\text {distill }} \mathcal{L}_{\text {distill }} \:\: (4)
\end{equation}
where hyper-parameters $ \lambda_{\text {recon }} $ and $ \lambda_{\text {distill }} $ control the importance of each term. Please refer to Appendix 6.1 for more details.
目的は完全に達成された
最終的な目的は次のように書かれています.
\begin{equation}
\mathcal{L}=\mathcal{L}_{\mathrm{cGAN}}+\lambda_{\text {recon }} \mathcal{L}_{\text {recon }}+\lambda_{\text {distill }} \mathcal{L}_{\text {distill }} \:\: (4)
\end{equation}
ここで, ハイパーパラメータ $ \lambda_{\text {recon }} $ と $ \lambda_{\text {distill }} $ は各項の重要度を制御します. 詳細は付録6.1を参照してください.
3.2 Efficient Generator Design Space
Choosing a well-designed student architecture is essential for the final performance of knowledge distillation. We find that naively shrinking the channel numbers of the teacher model fails to produce a compact student model: the performance starts to degrade significantly above 4× computation reduction. One of the possible reasons is that existing generator architectures are often adopted from image recognition models [43, 19, 52, 43], and may not be the optimal choice for image synthesis tasks. Below, we show how we derive a better architecture design space from an existing cGAN generator and perform neural architecture search (NAS) within the space.
効率的な発電機設計空間
よく設計された学生アーキテクチャの選択は, 知識蒸留の最終的なパフォーマンスに不可欠である. 教師モデルのチャンネル数を単純に縮小すると, コンパクトな学生モデルを生成できないことがわかった. 考えられる理由の1つは, 既存の生成器アーキテクチャが画像認識モデル[43, 19, 52, 43]から採用されていることが多く, 画像合成タスクに最適な選択ではない可能性があることです. 以下では, 既存のcGANジェネレータからより良いアーキテクチャ設計空間を導出し, その空間内でニューラルアーキテクチャ探索(NAS)を行う方法を示す.
Convolution decomposition and layer sensitivity.
Existing generators usually adopt vanilla convolutions to follow the design of classification and segmentation CNNs. Recent efficient CNN designs widely adopt a decomposed version of convolutions (depthwise + pointwise) [25], which proves to have a better performance-computation trade-off. We find that using the decomposed convolution also benefits the generator design in cGANs.
Unfortunately, our early experiments have shown that directly applying decomposition to all the convolution layers (as in classifiers) will significantly degrade the image quality. Decomposing some of the layers will immediately hurt the performance, while other layers are more robust. Furthermore, this layer sensitivity pattern is not the same as recognition models. For example, in ResNet generator [19, 28], the resBlock layers consume the majority of the model parameters and computation cost while is almost immune to decomposition. On the contrary, the upsampling layers have much fewer parameters, but are fairly sensitive to model compression: moderate compression can lead to a large FID degradation. Therefore, we only decompose the resBlock layers. We conduct a comprehensive study regarding the sensitivity of layers in Section 4.4.
コンボリューション分解とレイヤー感度.
既存の生成器は通常,分類・セグメンテーションCNNの設計に倣ってバニラコンボリューションを採用している.最近の効率的なCNN設計では,畳み込みの分解版(深さ方向+点方向)を広く採用している[25].我々は,分解された畳み込みを用いることで,cGANの生成器設計にも利点があることを発見した.
残念ながら,我々の初期の実験では,(分類器のように)すべての畳み込みレイヤーに直接分解を適用すると,画質が著しく低下することが示されています.一部の層を分解するとすぐに性能が損なわれる一方で、他の層はより頑健である。さらに、この層の感度パターンは、認識モデルと同じではない。例えば、ResNetジェネレーター[19, 28]では、resBlock層がモデルパラメータと計算コストの大部分を消費する一方で、分解の影響をほとんど受けない。逆に、アップサンプリング層は、パラメータ数ははるかに少ないが、モデルの圧縮にはかなり敏感である。したがって、我々はresBlock層のみを分解する。我々は第4.4節でレイヤーの感度に関する包括的な研究を行う。
Automated channel reduction with NAS.
Existing generators use a hand-crafted (and mostly uniform) channel numbers across all the layers, which contains redundancy and is far from optimal. To further improve the compression ratio, we automatically select the channel width in the generators using channel pruning [21, 20, 41, 77, 44] to remove the redundancy, which can reduce the computation quadratically. We support fine-grained choices regarding the numbers of channels. For each convolution layers, the number of channels can be chosen from multiples of 8, which balances MACs and hardware parallelism [20].
NASを使用した自動化されたチャネル削減.
既存の生成器は, すべてのレイヤにわたって手作業で作成された(そしてほとんど一様な)チャネル番号を使用しており, これは冗長性を含んでおり, 最適とは程遠いものです. 圧縮率をさらに向上させるために, 我々は, 冗長性を除去するためにチャネル剪定[21, 20, 41, 77, 44]を用いて生成器のチャネル幅を自動的に選択し, 計算量を2次関数的に削減することができる. 我々は,チャンネル数に関するきめ細かな選択をサポートしている.各畳み込み層について,チャネル数を8の倍数から選択することができ,MACとハードウェアの並列性のバランスをとることができる[20].
Given the possible channel configurations
\begin{equation}
\left\{c_{1}, c_{2}, \ldots, c_{K}\right\}
\end{equation}
where K is the number of layers to prune, our goal is to find the best channel configuration
\begin{equation}
\left\{c_{1}^{*}, c_{2}^{*}, \ldots, c_{K}^{*}\right\}=\arg \min _{c_{1}, c_{2}, \ldots, c_{K}} \mathcal{L}, \quad \text { s.t. MACs }<F_{t}
\end{equation}
using neural architecture search, where Ft is the computation constraint. A straight-forward approach is to traverse all the possible channel configuration, train it to convergence, evaluate, and pick the generator with the best performance. However, as K increases, the number of possible configurations increases exponentially, and each configuration might require different hyper-parameters regarding the learning rates and weights for each term. This trial and error process is far too time-consuming.
可能なチャネル構成
\begin{equation}
\left\{c_{1}, c_{2}, \ldots, c_{K}\right\}
\end{equation}
(K はプルーンする層の数)があるとすると, 我々の目標は, ニューラルアーキテクチャ探索を用いて, 最良のチャネル構成
\begin{equation}
\left\{c_{1}^{*}, c_{2}^{*}, \ldots, c_{K}^{*}\right\}=\arg \min _{c_{1}, c_{2}, \ldots, c_{K}} \mathcal{L}, \quad \text { s.t. MACs }<F_{t}
\end{equation}
を見つけ出すことです(Ft は計算制約). 直截的なアプローチは, すべての可能なチャネル構成をトラバースし, 収束するように訓練し, 評価し, 最高の性能を持つジェネレータを選ぶことです. しかし, Kが増加すると, 可能な構成の数は指数関数的に増加し, 各構成は, 各項の学習率と重みに関して異なるハイパーパラメータを必要とする場合があります. この試行錯誤のプロセスは時間がかかりすぎます.
3.3. Decouple Training and Search
To address the problem, we decouple model training from architecture search, following recent work in one-shot neural architecture search methods [7, 6, 15]. We first train a “once-for-all” network [6] that supports different channel numbers. Each sub-network with different numbers of channels are equally trained and can operate independently. Sub-networks share the weights with the “once-for-all” network. Figure 3 illustrates the overall framework. We assume that the original teacher generator has $ \Bigl\{ { c^0_k } \Bigr\}^K_{k=1} $ channels. For a given channel number configuration $ \Bigl\{ { c_k } \Bigr\}^K_{k=1} $ , $c_k$ ≤ $c_k^0$ , we obtain the weight of the sub-network by extracting the first $ \Bigl\{ { c_k } \Bigr\}^K_{k=1} $ channels from the corresponding weight tensors of “once-for-all” network, following Guo et al. [15]. At each training step, we randomly sample a sub-network with a certain channel number configuration, compute the output and gradients, and update the extracted weights using our learning objective (Equation 4). Since the weights at the first several channels are updated more frequently, they play a more critical role among all the weights.
訓練と探索を分離して
この問題に対処するために, 最近のワンショット・ニューラル・アーキテクチャ探索手法[7, 6, 15]の研究に倣って, モデル学習をアーキテクチャ探索から切り離す. 我々はまず, 異なるチャネル数をサポートする「ワンスフォアオール」ネットワーク[6]を訓練する. 異なるチャンネル数を持つ各サブネットワークは等しく訓練され, 独立して動作することができる. サブネットワークは「ワンスフォアオール」ネットワークと重みを共有する. 図3は全体的なフレームワークを示しています. 元の教師生成器が{c 0 k }を持つと仮定します. K k=1 のチャンネル. 与えられたチャンネル番号構成{ck}に対して K k=1, ck ≤ c 0 k の場合,最初の {ck} を抽出することで,サブネットワークの重みを求める.Guoら[15]に倣って, "once-for-all "ネットワークの対応する重みテンソルから, K k=1チャンネルを抽出する. 各学習ステップでは, あるチャンネル番号の構成を持つサブネットワークをランダムにサンプリングし, 出力とグラディエントを計算し, 学習目的(式4)を用いて抽出された重みを更新します. 最初のいくつかのチャンネルの重みはより頻繁に更新されるので, すべての重みの中でより重要な役割を果たします.
Figure 3: GAN Compression:
➀ Given a pre-trained teacher generator G′ , we distill a smaller “once-for-all” [6] student generator G that contains all possible channel numbers through weight sharing. We sample different channel numbers {ck} K k=1 for G at each training step so that one generator can support all channel numbers.
➁ We then extract many sub-generators with different channel numbers from the “once-for-all” generator and evaluate their performance. No retraining is needed, which is the advantage of the “once-for-all” generator.
➂ Finally, we choose the best sub-generator given the compression ratio target and performance target (FID or mAP), perform fine-tuning, and obtain the final compressed model.
➀ 事前に訓練された教師生成器G′があるとすると,重みを共有することで可能なすべてのチャンネル番号を含む,より小さな「すべてに一度だけ」[6]の生徒生成器Gを作成する.我々は,異なるチャネル番号{ck}をサンプルとする.1 つの生成器がすべてのチャネル番号に対応できるように、各学習ステップで G に対して K k=1 を設定する。
➁ 次に、異なるチャネル番号を持つ多くのサブジェネレータを「ワンスフォアオール」ジェネレータから抽出し、その性能を評価する。再学習が不要であることが、「ワンスフォアオール」生成器の利点です。
➂ 最後に、圧縮率目標と性能目標(FIDやmAP)を与えられた最適なサブジェネレーターを選択し、微調整を行い、最終的な圧縮モデルを得る。
After the “once-for-all” network is trained, we find the best sub-network by directly evaluating the performance of each candidate sub-network on the validation set. Since the “once-for-all” network is thoroughly trained with weight sharing, no fine-tuning is needed. This approximates the model performance when it is trained from scratch. In this manner, we can decouple the training and search of the generator architecture: we only need to train once, but we can evaluate all the possible channel configurations without further training, and pick the best one as the search result. Optionally, we fine-tune the selected architecture to further improve the performance. We report both variants in Section 4.4.
「ワンスフォアオール」ネットワークを学習した後, 各候補サブネットワークの性能を検証セット上で直接評価することで, 最適なサブネットワークを見つける. ワンスフォアオール」ネットワークは, 重み分担を用いて徹底的に訓練されているので, 微調整は必要ありません. これは, モデルがゼロから訓練されたときの性能に近似しています. このようにして, ジェネレータ・アーキテクチャの学習と探索を切り離すことができます:一度だけ学習する必要がありますが, それ以上学習しなくても, 可能なすべてのチャネル構成を評価し, 探索結果として最適なものを選ぶことができます. オプションとして, 性能をさらに向上させるために, 選択したアーキテクチャを微調整する. 両方のバリエーションについては, セクション4.4で報告する.
4. Experiments
4.1 Setups
Models.
We conduct experiments on three conditional GAN models to demonstrate the generality of our method.
- CycleGAN [76], an unpaired image-to-image translation model, uses a ResNet-based generator [19, 28] to transform an image from a source domain to a target domain, without using pairs.
- Pix2pix [27] is a conditional-GAN based paired imageto-image translation model. For this model, we replace the original U-Net generator [52] by the ResNet-based generator [28] as we observe that the ResNet-based generator achieves better results with less computation cost, given the same learning objective. See Appendix 6.2 for a detailed U-Net vs. ResNet benchmark.
- GauGAN [49] is a state-of-the-art paired image-to-image translation model. It can generate a high-fidelity image given a semantic label map.
We re-trained the pix2pix and CycleGAN using the official PyTorch repo with the above modifications. Our retrained pix2pix and CycleGAN models (available at our repo) slightly outperform the official pre-trained models. We use these re-trained models as original models. For GauGAN, we use the pre-trained model from the authors. See Appendix 6.2 for more details.
我々の手法の一般性を実証するために, 3つの条件付きGANモデルで実験を行った.
- CycleGAN [76]は,対になっていない画像対画像変換モデルであり,ResNetベースの生成器[19, 28]を用いて,対を用いずに画像をソースドメインからターゲットドメインに変換する.
- Pix2pix [27]は, 条件付きGANベースの対になった画像対画像変換モデルである. このモデルでは, オリジナルの U-Net ジェネレータ [52] を ResNet ベースのジェネレータ [28] に置き換えていますが, これは, 同じ学習目的が与えられている場合, ResNet ベースのジェネレータの方が少ない計算コストでより良い結果が得られることがわかったからです. U-NetとResNetのベンチマークの詳細については付録6.2を参照のこと.
- GauGAN [49]は,最新の画像対画像変換モデルです.GauGAN [49]は,意味的ラベルマップが与えられたときに,高忠実度の画像を生成することができます.
今回, pix2pixとCycleGANをPyTorchの公式レポを使って, 上記の修正を加えて再学習しました. 再学習したpix2pixとCycleGANのモデルは, 我々のレポで公開されているもので, 事前に学習したモデルをわずかに上回る結果が得られました. これらの再訓練済みモデルをオリジナルモデルとして使用しています. GauGANについては, 著者による事前学習済みモデルを使用しています. 詳細は付録6.2を参照してください.
Datasets.
We use the following four datasets:
- Edges→shoes. We use 50,025 images from UT Zappos50K dataset [69]. We split the dataset randomly so that the validation set has 2,048 images for a stable evaluation of Frechet Inception Distance (FID) (see Section ´ 4.2). We evaluate the pix2pix model on this dataset. • Cityscapes. The dataset [12] contains the images of German street scenes. The training set and the validation set consists of 2975 and 500 images, respectively. We evaluate both the pix2pix and GauGAN model on this dataset.
- Horse↔zebra. The dataset consists of 1,187 horse images and 1,474 zebra images originally from ImageNet [13] and used in CycleGAN [76]. The validation set contains 120 horse images and 140 zebra images. We evaluate the CycleGAN model on this dataset.
- Map↔aerial photo. The dataset contains 2194 images scraped from Google Maps and used in pix2pix [27]. The training set and the validation set contains 1096 and 1098 images, respectively. We evaluate the pix2pix model on this dataset.
以下の4つのデータセットを使用しています.
- Edges→shoes. UT Zappos50Kデータセット[69]の50,025画像を使用しています. このデータセットをランダムに分割し, Frechet Inception Distance (FID)を安定的に評価するために2,048枚の画像が得られるようにしています(セクション´4.2参照). このデータセットを用いてpix2pixモデルの評価を行う. - 街並み. データセット[12]には,ドイツの街並みの画像が含まれています.学習集合は2975枚,検証集合は500枚である.このデータセットに対して,pix2pixモデルとGauGANモデルの両方を評価している.
- 馬↔ゼブラ. このデータセットは, ImageNet [13]の馬画像1,187枚と, CycleGAN [76]で使用されているゼブラ画像1,474枚からなる. 検証セットは120枚の馬画像と140枚のゼブラ画像からなる. このデータセットを用いてCycleGANモデルを評価する.
- 地図↔馬の写真. このデータセットには, Googleマップの画像2194枚が含まれており, pix2pix [27]で使用されている. 学習集合は1096枚, 検証集合は1098枚である. このデータセットを用いてpix2pixのモデルを評価しています.
Implementation details.
For the CycleGAN and pix2pix model, we use a learning rate of 0.0002 for both generator and discriminator during training in all the experiments. The batch sizes on dataset horse→zebra, edges→shoes, map→aerial photo, and cityscapes are 1, 4, 1, and 1, respectively. For the GauGAN model, we followed the setting in the original paper [49], except that the batch size is 16 instead of 32. We find that we can achieve a better result with a smaller batch size. See Appendix 6.1 for more implementation details.
実装の詳細.
CycleGANとpix2pixモデルについては, すべての実験において, 学習時に生成器と識別器の両方に0.0002の学習率を使用しています. データセットの馬→ゼブラ, エッジ→靴, 地図→空中写真, 街並みのバッチサイズはそれぞれ1, 4, 1, 1である. GauGANモデルについては,バッチサイズが32ではなく16であることを除いて,原著論文[49]の設定を踏襲した.バッチサイズを小さくすることで, より良い結果が得られることがわかりました. 実装の詳細については付録6.1を参照のこと.
4.2 Evaluation Metrics
We introduce the metrics for assessing the equality of synthesized images.
合成された画像の等質性を評価するためのメトリクスを紹介します.
Frechet Inception Distance (FID) [ ´ 22].
The FID score aims to calculate the distance between the distribution of feature vectors extracted from real and generated images using an InceptionV3 [58] network. The score measures the similarity between the distributions of real and generated images. A lower score indicates a better quality of generated images. We use an open-sourced FID evaluation code† . For paired image-to-image translation (pix2pix and GauGAN), we calculate the FID between translated test images to real test images. For unpaired image-to-image translations (CycleGAN), we calculate the FID between translated test images to real training+test images. This allows us to use more images for a stable FID evaluation, as done in previous unconditional GANs [29]. The FID of our compressed CycleGAN model slightly increases when we use real test images instead of real training+test images.
FIDスコアは, InceptionV3 [58]ネットワークを用いて, 実画像から抽出された特徴ベクトルの分布と生成画像から抽出された特徴ベクトルの分布の間の距離を計算することを目的としている. スコアは, 実画像と生成画像の分布の類似度を測定する. スコアが低いほど, 生成画像の品質が高いことを示す. 我々は, オープンソースのFID評価コード†を使用している. 対になる画像対画像変換(pix2pixとGauGAN)では,翻訳されたテスト画像と実際のテスト画像との間のFIDを計算します.非対になった画像対画像翻訳(CycleGAN)では, 翻訳されたテスト画像と実際のトレーニング+テスト画像との間のFIDを計算します. これにより, 以前の無条件GAN[29]で行われていたように, より多くの画像を使用して安定したFID評価を行うことができます. 我々の圧縮されたCycleGANモデルのFIDは, 実際のトレーニング+テスト画像の代わりに実際のテスト画像を使用すると, わずかに増加します.
Semantic Segmentation Metrics.
Following prior work [27, 76, 49], we adopt a semantic segmentation metric to evaluate the generated images on the Cityscapes dataset. We run a semantic segmentation model on the generated images and compare how well the segmentation model performs. We choose the mean Intersection over Union (mIoU) as the segmentation metric, and we use DRN-D-105 [70] as our segmentation model. Higher mIoUs imply that the generated images look more realistic and better reflect the input label map. We upsample the DRN-D-105’s output semantic map to 2048 × 1024, which is the resolution of Cityscapes ground truth images. Please refer to our code for more details.
意味的セグメンテーションメトリクス.
先行研究[27, 76, 49]に続き, セマンティックセグメンテーション手法を採用し, Cityscapesデータセット上の生成画像を評価する. 生成された画像に対してセマンティックセグメンテーションモデルを実行し, セグメンテーションモデルの性能を比較する. セグメンテーション指標として平均交差度(mIoU)を選択し, セグメンテーションモデルとしてDRN-D-105 [70]を用いた. mIoUが高いほど, 生成された画像はよりリアルに見え, 入力ラベルマップをよりよく反映していることを意味します. DRN-D-105の出力セマンティックマップを2048×1024(Cityscapesの地上真実画像の解像度)にアップサンプルしました. 詳細については, 当社のコードを参照してください.
4.3 Results
Quantitative Results
We report the quantitative results of compressing CycleGAN, pix2pix, and GauGAN on four datasets in Table 1. By using the best performing subnetwork from the “once-for-all” network, our method GAN Compression achieves large compression ratios. It can compress state-of-the-art conditional GANs by 9-21×, and reduce the model size by 5-33×, with only negligible degradation in the model performance. Specifically, our proposed method shows a clear advantage of CycleGAN compression compared to the previous Co-Evolution method [56]. We can reduce the computation of CycleGAN generator by 21.2×, which is 5× better compared to the previous CycleGANspecific method [56] while achieving a better FID by more than 30‡ .
結果 定量的な結果
CycleGAN, pix2pix, GauGANの4つのデータセットを用いた圧縮の定量的な結果を表1に示します. 我々の手法であるGAN圧縮は, "ワンスフォーオール "ネットワークの中から最も性能の良いサブネットワークを利用することで, 大きな圧縮率を実現している. この手法は,最新の条件付きGANを9-21倍に圧縮し,モデルサイズを5-33倍に縮小することができ,モデル性能の劣化は無視できる程度であった.具体的には,提案手法は従来のCo-Evolution法[56]と比較して,CycleGANの圧縮に明確な優位性を示している.提案手法では, 従来のCycleGAN特有の手法[56]と比較して, FIDを30‡以上向上させながら, CycleGAN生成器の計算量を21.2×(5×)削減することができた.
Performance vs. Computation Trade-off
Apart from the large compression ratio we can obtain, we verify that our method can consistently improve the performance at different model sizes. Taking the pix2pix model as an example, we plot the performance vs. computation trade-off on Cityscapes and Edges→shoes dataset in Figure 6.
First, in the large model size regime, prune + distill (without NAS) outperforms training from scratch, showing the effectiveness of intermediate layer distillation. Unfortunately, with the channels continuing shrinking down uniformly, the capacity gap between the student and the teacher becomes too large. As a result, the knowledge from the teacher may be too recondite for the student, in which case the distillation may even have negative effects on the student model.
On the contrary, our training strategy allows us to automatically find a sub-network with a smaller gap between the student and teacher model, which makes learning easier. Our method consistently outperforms the baselines by a large margin.
性能と計算量のトレードオフ
我々が得られる大きな圧縮率とは別に, 我々の手法が様々なモデルサイズで一貫して性能を向上させることができることを検証しています. pix2pixモデルを例に, 図6にCityscapesとEdges→shoesのデータセットについて, 性能と計算量のトレードオフをプロットします.
まず, 大きなモデルサイズの領域では, prune + distill (NASなし)がゼロからのトレーニングを上回り, 中間層蒸留の有効性を示しています. 残念ながら, チャネルが一様に縮小し続けると, 学生と教師の間のキャパシティギャップが大きくなりすぎます. その結果, 教師からの知識が学生には近すぎ, その場合, 蒸留は学生モデルに悪影響を及ぼす可能性がある.
これに対して, 本研究では, 生徒モデルと教師モデルの間のギャップが小さいサブネットワークを自動的に見つけることができるため, 学習が容易になります. 我々の手法は一貫してベースラインを大きく上回る結果を示しています
Qualitative Results
Figure 4 shows several example results. We provide the input, its ground-truth (except for unpaired setting), the output of the original model, and the output of our compressed model. Our compression method well preserves the visual fidelity of the output image even under a large compression ratio. For CycleGAN, we also provide the output of a baseline model (0.25 CycleGAN: 14.9×). The baseline model 0.25 CycleGAN contains 1 4 channels and has been trained from scratch. Our advantage is distinct: the baseline model can hardly create a zebra pattern on the output image, given a much smaller compression ratio. There might be some cases where compressed models show a small degradation (e.g., the leg of the second zebra in Figure 4), but compressed models sometimes surpass the original one in other cases (e.g., the first and last shoe images have a better leather texture). Generally, GAN models compressed by our method performs comparatively compared to the original model, as shown by quantitative results.
定性的な結果
図4にいくつかの結果例を示す.入力とその基底真実(不対の設定を除く), 元のモデルの出力, そして我々の圧縮モデルの出力を提供する. 我々の圧縮手法は, 大きな圧縮率であっても, 出力画像の視覚的な忠実度を十分に保持していることがわかる. CycleGANについては, ベースラインモデル(0.25 CycleGAN:14.9×)の出力も提供しています. ベースラインモデル0.25 CycleGANは1 4チャンネルを含み, スクラッチから学習されています. ベースラインモデルは, 圧縮率がかなり小さいため, 出力画像にゼブラパターンをほとんど作ることができません. 圧縮モデルが若干の劣化を示す場合もあるかもしれませんが(例:図4の2番目のシマウマの足), 圧縮モデルが元のモデルを上回る場合もあります(例:最初と最後の靴の画像はより良い革の質感を持っています). 一般的に, 我々の手法で圧縮されたGANモデルは, 定量的な結果が示すように, 元のモデルと比較して比較的高い性能を発揮します.
Accelerate Inference on Hardware
For real-world interactive applications, inference acceleration on hardware is more critical than the reduction of computation. To verify the practical effectiveness of our method, we measure the inference speed of our compressed models on several devices with different computational powers. To simulate interactive applications, we use a batch size of 1. We first perform 100 warm-up runs and measure the average timing of the next 100 runs. The results are shown in Table 2. The inference speed of compressed CycleGAN generator on edge GPU of Jetson Xavier can achieve about 40 FPS, meeting the demand of interactive applications. We notice that the acceleration on GPU is less significant compared to CPU, mainly due to the large degree of parallelism. Nevertheless, we focus on making generative models more accessible on edge devices where powerful GPUs might not be available, so that more people can use interactive cGAN applications.
ハードウェア上での推論の高速化
実世界のインタラクティブなアプリケーションでは, ハードウェア上での推論の高速化は計算量の削減よりも重要である. 我々の手法の実用的な有効性を検証するために, 計算能力の異なる複数のデバイスで圧縮モデルの推論速度を測定しました. 対話型アプリケーションをシミュレートするために, バッチサイズを1とし, まず100回のウォームアップ実行を行い, 次の100回の実行の平均タイミングを測定します. 結果を表2に示します. Jetson XavierのエッジGPU上で圧縮されたCycleGANジェネレータの推論速度は約40FPSを達成し, 対話型アプリケーションの要求を満たすことができる. GPU上での高速化はCPUと比較して有意ではないが, これは主に並列性が大きいためである. とはいえ, より多くの人がインタラクティブなcGANアプリケーションを利用できるように, 強力なGPUが利用できないかもしれないエッジデバイスでも, 生成モデルをより利用しやすくすることに焦点を当てています.
4.4 Ablation Study
Below we perform several ablation studies regarding our individual system components and design choices.
Advantage of unpaired-to-paired transform.
We first analyze the advantage of transforming unpaired conditional GANs into a pseudo paired training setting using the teacher model’s output.
Figure 7a shows the comparison of performance between the original unpaired training and our pseudo paired training. As our computation budget reduces, the quality of images generated by the unpaired training method degrades dramatically, while our pseudo paired training method remains relatively stable. The unpaired training requires the model to be strong enough to capture the complicated and ambiguous mapping between the source domain and the target domain. Once the mapping is learned, our student model can learn it from the teacher model directly. Additionally, the student model can still learn extra information on the real target images from the inherited discriminator.
アブレーション研究
以下では, 個々のシステムコンポーネントと設計の選択について, いくつかのアブレーション研究を行います.
非対対になる条件付きGANの変換の利点.
最初に, 教師モデルの出力を使用して, 非ペアリング条件付きGANを擬似ペアリング訓練設定に変換することの利点を分析します.
図7aは, 元の非ペアリング訓練と疑似ペアリング訓練の性能を比較したものです. 計算予算が減少するにつれて,不対付き訓練法で生成された画像の品質は劇的に低下しますが,我々の疑似ペア訓練法は比較的安定しています.非対をとった訓練では, ソースドメインとターゲットドメインの間の複雑で曖昧なマッピングを捉えるのに十分な強度を持つモデルが必要です. 一旦マッピングが学習されると, 我々の学生モデルは教師モデルから直接マッピングを学習することができます. さらに, 生徒モデルは, 継承された識別器から実際のターゲット画像に関する余分な情報を学習することができる.
The effectiveness of intermediate distillation and inheriting the teacher discriminator.
Table 3 demonstrates the effectiveness of intermediate distillation and inheriting the teacher discriminator on the pix2pix model. Solely pruning and distilling intermediate feature cannot render a significantly better result than the baseline from-scratch training. We also explore the role of the discriminator in the pruning. As a pre-trained discriminator stores useful information of the original generator, it can guide the pruned generator to learn faster and better. If the student discriminator is reset, the knowledge of the pruned student generator will be spoiled by the randomly initialized discriminator, which sometimes yields even worse results than the from-scratch training baseline.
中間蒸留と教師判別器の継承の効果
表3は, pix2pixモデルにおける中間抽出と教師判別器の継承の有効性を示しています. 中間特徴の剪定と蒸留だけでは, ベースラインのスクラッチ学習よりも有意に良い結果が得られないことがわかります. また, 剪定における判別器の役割についても検討しています. 事前に訓練された判別器は, 元の生成器の有用な情報を保存しているため, 剪定された生成器をより速く, より良い学習に導くことができる. 学生判別器がリセットされると, 剪定された学生ジェネレータの知識は, ランダムに初期化された判別器によって台無しにされる.
Effectiveness of convolution decomposition.
We systematically analyze the sensitivity of conditional GANs regarding the convolution decomposition transform. We take the ResNet-based generator from CycleGAN to test its effectiveness. We divide the structure of ResNet generator into three parts according to its network structure: Downsample (3 convolutions), ResBlocks (9 residual blocks), and Upsample (the final two deconvolutions). To validate the sensitivity of each stage, we replace all the conventional convolutions in each stage into separable convolutions [25]. The performance drop is reported in Table. 4. The ResBlock part takes a fair amount of computation cost, so decomposing the convolutions in the ResBlock can notably reduce computation costs. By testing both the architectures with ngf=64 and ngf=16, the ResBlock-modified architecture shows better computation costs vs. performance trade-off. We further explore the computation costs vs. performance trade-off of the ResBlock-modified architecture on Cityscapes dataset. Figure. 7b illustrates that such Mobilenet-style architecture is consistently more efficient than the original one, which has already reduced about half of the computation cost.
畳み込み分解の有効性
畳み込み分解変換に関する条件付きGANの感度を系統的に解析する. その有効性を検証するために, CycleGANのResNetをベースとした生成器を用いた. ResNet生成器の構造は, そのネットワーク構造に応じて3つの部分に分けられる. ダウンサンプル(3つの畳み込み), ResBlocks(9つの残差ブロック), アップサンプル(最後の2つのデコンボリューション)の3つに分けています. 各ステージの感度を検証するために,各ステージの従来の畳み込みをすべて分離可能な畳み込みに置き換えた[25].性能の低下を表に報告する.4. ResBlock 部分にはかなりの計算コストがかかるため, ResBlock 内の畳み込みを分解することで, 計算コストを大幅に削減することができます. ngf=64とngf=16の両方のアーキテクチャをテストしたところ, ResBlockを修正したアーキテクチャの方が計算コストと性能のトレードオフが良好であることがわかりました. さらに, Cityscapesデータセットを用いて, ResBlockを改良したアーキテクチャの計算コストと性能のトレードオフを調べてみました. 図7bは, このようなMobilenetアーキテクチャが 7bは, このようなMobilenetスタイルのアーキテクチャがオリジナルのものよりも一貫して効率的であることを示しており, すでに約半分の計算コストが削減されていることを示しています.
5. Conclusion
In this work, we proposed a general-purpose compression framework for reducing the computational cost and model size of generators in conditional GANs. We have used knowledge distillation and neural architecture search to alleviate training instability and to increase the model efficiency. Extensive experiments have shown that our method can compress several conditional GAN models while preserving the visual quality. Future work includes reducing the latency of models and efficient architectures for generative video models [62, 60]. Acknowledgments We thank NSF Career Award #1943349, MIT-IBM Watson AI Lab, Adobe, Intel, Samsung and AWS machine learning research award for supporting this research. We thank Ning Xu, Zhuang Liu, Richard Zhang, and Antonio Torralba for helpful comments. We thank NVIDIA for donating the Jetson AGX Xavier that runs our demo.
結論
本研究では, 条件付きGANにおける生成器の計算コストとモデルサイズを削減するための汎用圧縮フレームワークを提案した. 本研究では, 学習の不安定性を緩和し, モデルの効率を向上させるために, 知識蒸留とニューラルアーキテクチャ探索を用いた. 広範な実験により, 我々の手法が視覚的な品質を維持しつつ, 複数の条件付きGANモデルを圧縮できることが示された. 将来的には, モデルの待ち時間を短縮し, 生成的なビデオモデルのための効率的なアーキテクチャ [62, 60] を開発する予定である. 謝辞 本研究を支援していただいたNSF Career Award #1943349, MIT-IBM Watson AI Lab, Adobe, Intel, Samsung, AWS機械学習研究賞に感謝します. 役に立つコメントをいただいた Ning Xu 氏, Zhuuang Liu 氏, Richard Zhang 氏, Antonio Torralba 氏に感謝します. デモを実行するJetson AGX Xavierを寄贈してくださったNVIDIAに感謝します.
おわりに
次回は各章の要約を書いていこうと思います.