Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Glow の紹介

Avatar for ALBERT Inc. ALBERT Inc.
February 04, 2020

Glow の紹介

Avatar for ALBERT Inc.

ALBERT Inc.

February 04, 2020
Tweet

More Decks by ALBERT Inc.

Other Decks in Technology

Transcript

  1. www.albert2005.co.jp/ 本社 〒169-0074 東京都新宿区北新宿2-21-1 新宿フロントタワー15F TEL: 03-5937-1610 FAX: 03-5937-1612 東海⽀社

    〒451-6008 愛知県名古屋市⻄区⽜島町6-1 名古屋ルーセントタワー8F TEL: 052-433-3701 FAX: 052-433-3702 Glowの紹介 2020/02/04 Data Science Café @ 新宿 データソリューション部 古川 遼
  2. ⽣成モデルとは n ⽣成モデルは, データの⽣成過程をモデル化したもの. モデルは, 確率分布によって表す. n 問題設定 Ø データに対応する確率変数

    とその確率分布 ! ∗ (真の分布) を考える. Ø 真の分布 ! ∗ をモデル分布 !,$ (: パラメータ) で近似する. n 今回の発表での前提 Ø 今回は, 確率変数は ℝ% 値, 確率変数の確率分布は連続なものを考える*. *: 確率変数は Euclid 空間上のボレル集合族に値をとるものを考え, 確率変数の確率分布はルベーグ測度に関して絶対連続とする. ⽣成モデルとは 4 ! ∗ !,$
  3. Kullback-Leibler divergence と対数尤度 n 分布の近さを測る基準 Ø Kullback-Leibler divergence Ø Jensen-Shannon

    divergence Ø Wasserstein distance Ø etc Ø 今回は, Kullback-Leibler divergence の最⼩化を扱う. n Kullback-Leibler divergence と対数尤度 Ø ! ∗ の !,$ に対する Kullback-Leibler divergence &' (! ∗||!,$ ) は, 確率密度関数 ! ∗ , !,$ を使って次のように書ける; &' (! ∗||!,$ ) = , ! ∗ log ! ∗ !,$ = (! ∗ log ! ∗ − (! ∗ log !,$ . Ø 対数尤度の期待値を最⼤化するように !,$ のパラメータ推定を⾏う. Ø i.i.d. データセット ) , = 1,2, … を⽤いて, 次の推定量を最⼩化する; 1 # !"# $ − log %, ' ! . 5 Flow-based ⽣成モデルとは 対数尤度関数
  4. 深層⽣成モデルの種類 n ⽣成モデルに, 深層学習を⽤いることを考える. n 深層⽣成モデルで, 代表的なものとして次の 3 つがある; Ø

    GANs (Generative Adversarial Networks). Ø VAEs (Variational Auto-encoders). Ø Flow-based ⽣成モデル. 上記は, いずれも潜在変数を持つモデル. ⽣成モデルとは 6 学習⽅法 学習するもの 潜在変数への 推論 GANs 敵対的学習 (min-max) ⽣成モデル 分類モデル () モデル化されない VAEs 変分下界最⼤化 ⽣成モデル (|) 推論モデル (|) 事後分布の近似 により可能. Flow-based 対数尤度最⼤化 (可逆な) フロー = フローにより可能 出典: [Weng., 2018.] LilʼLog: Flow-based Deep Generative Models. https://lilianweng.github.io/lil-log/2018/10/13/flow-based-deep-generative-models.html 参考 : [Suzuki., 2019.] DL輪読会のスライド: Flow-based Deep Generative Models https://www.slideshare.net/DeepLearningJP2016/dlflowbased-deep-generative-models
  5. Flow-based モデルの考え⽅ n Flow-based モデルでは, データ分布 ! ∗ (: ℝ%値)

    の⽣成過程として, 潜在変数の分布 * (: ℝ%値) を⽤いて 次のようなものを考える; = . ここで, : ℝ% → ℝ% は可逆な写像 (特に, 微分同相写像). n 潜在変数の分布として, 標準正規分布などが⽤いられる. n 特徴 Ø が決定的な関数である. Ø が可逆である. Ø 潜在変数 とデータの確率変数 がともに ℝ% に値をとる. 7 Flow-based ⽣成モデルとは =
  6. Flow-based モデルの考え⽅ n Flow-based モデルでは, 例えば, 有限個の可逆な写像の合成 $ = &

    ∘ &+, ∘ ⋯ ∘ , と潜在変数の分布 * を⽤いて, モデル !,$ を作る. n 有限個の可逆な写像の列 (あるいは, それに従ってできる確率変数の列) を finite flow という. 8 Flow-based ⽣成モデルとは ℎ! = z ℎ" ℎ# ℎ$ = " # $ ・・・ ・・・ % % &" # &" " &" $ &" ' ' &" Normalizing direction Generative direction % ! ∗, !,$
  7. Flow-based ⽣成モデルにおける対数尤度の計算 n Flow-based ⽣成モデルでは対数尤度の期待値を最⼤化する. n モデルの尤度は, 変数変換を⾏なって次のように書ける; %,' =

    - det = - det $ +, = * () E )-, & det ℎ)+, ℎ) , ここで, ./. /0 0 .0 は $ +, の Jacobi ⾏列. n モデルの対数尤度は次のように計算できる. log %,'() = log - + log det = log * () + log det $ +,() = log - () + # !"# . log det ℎ)+, ℎ) . ここでは, ⾏列式の絶対値の対数 log det ・ を log-determinant と呼ぶことにする. 9 Flow-based ⽣成モデルとは ℎ! = ℎ" ℎ# ℎ$ = " # $ ・・・ ・・・ % % &" # &" " &" $ &" ' ' &"
  8. Flow-based ⽣成モデルにおける⼯夫 n Flow-based モデルでは, Jacobi ⾏列の log-determinant の計算量をどう抑えるかがポイント. n

    変換をうまく設計 (制限) して, Jacobi ⾏列を三⾓⾏列にする⽅法が⽤いられることがある. Ø 三⾓⾏列の⾏列式は, 対⾓成分の掛け算. Ø ⾏列式の計算量が (1) から ()  正⽅⾏列の次数) になる. 10 Flow-based ⽣成モデルとは ∗ 0 0 ∗ ∗ 0 ∗ ∗ ∗ ⾏列式の計算は 対⾓成分の掛け算
  9. 紹介する論⽂ n 今回は Flow-based ⽣成モデルの論⽂の紹介をする. l 論⽂: Glow: Generative Flow

    with Invertible 1×1 Convolutions l 著者: Diederik P. Kingma (OpenAI), Prafulla Dhariwal (OpenAI) Ø 雑誌: NIPS 2018 (Advances in Neural Information Processing Systems) Ø arXiv: https://arxiv.org/abs/1807.03039 Ø GitHub: https://github.com/openai/glow Ø Blog: https://openai.com/blog/glow/ n 概要 Ø Invertible 1×1 convolution を使った flow-based ⽣成モデルを提案. Ø 標準 benchmark データセットで対数尤度を向上させた. Ø 対数尤度を最適化する⼿法で, ⾼解像度の画像の合成と操作が可能であることを⽰した. n メモ Ø NICE [Dinh et al., 2014.], RealNVP [Dinh et al., 2016.] を改良したモデル. Ø 画像合成をする Flow-based ⽣成モデルでは有名 (2020/01/14時点 Google scholar citation によると引⽤ 319 件). 論⽂情報 11 出典: [Kingma & Dhariwal., 2018.] Glow: Generative flow with invertible 1x1 convolutions.
  10. Multi-scale architecture n ⼤枠は, multi-scale architecture (RealNVP [Dinh et al.,

    2016.]) Ø 各 step で, squeezing で空間⽅向のスケールを変えて⾏く. p step によって, 同じサイズの kernel に対応する元画像のスケールが変化. Ø 各 step で⼀部の特徴量のみを次の step の⼊⼒へ. Ø 最終的に複数のスケールの特徴量を concatenate. 12 Glowの構造 1 2 5 6 3 4 7 8 4 8 3 7 2 6 1 5 Squeezing s×× → ( ) × ( ) ×4 出典: [Kingma & Dhariwal., 2018.] Glow: Generative flow with invertible 1x1 convolutions. 出典: [Dinh et al., 2017.] Density estimation using Real NVP.
  11. Glow の 1 ステップ n 各 step 内の構造 (step of

    flow の部分) を RealNVP から新しく変更. Ø actnorm, invertible 1×1 convolution, affine coupling layer. 13 Glowの構造 出典: [Kingma & Dhariwal., 2018.] Glow: Generative flow with invertible 1x1 convolutions.
  12. Glow の 1 ステップ n actnorm, invertible 1×1 convolution, affine

    coupling layer の構造の概要は以下. Ø 次ページ以降で詳細を⾒る. 14 Glowの構造 出典: [Kingma & Dhariwal., 2018.] Glow: Generative flow with invertible 1x1 convolutions.
  13. Actnorm n RealNVP では batch normalization を使っていた. Ø batch normalization

    では, minibatch size が⼩さい時に activation のノイズが増加する可能性がある. Ø ⼤きな画像などは, メモリの制約で minibatch size 1 で学習することがある. n batch normalization の代わりに activation normalization (actnorm) を使⽤ Ø batch ⽅向の統計量を使わずに, 値をスケール & シフト. (, ) は訓練可能なパラメータ. Fuction: ),2 = ⊙ ),2 + , Reverse Function: ),2 = ),2 − , Log − determinant: ℎ Y Y sum log . ここで, , : ℎ × × のテンソル, (, ): 空間⽅向 ((ℎ, ) ⽅向)の index. Ø 初期化はデータ依存; 最初の minibatch で actnorm の後の activation がチャネルごとに, 平均 0・分散 1 となるように初期化. 16 Glowの構造
  14. Invertible 1×1 convolution 17 Glowの構造 出典: [Kingma & Dhariwal., 2018.]

    Glow: Generative flow with invertible 1x1 convolutions.
  15. Invertible 1×1 convolution n ⼊⼒チャネル数と出⼒チャネル数が同じ 1×1 convolution を導⼊ Ø チャネルの置換の⼀般化を実現しようとする*.

    Ø 重みの初期値は, ランダムな × の回転⾏列 (rank が になるようにする). : サイズ ×, Function: ),2 = ),2 , Reverse Function: ),2 = +,),2 , Log − determinant: ℎ Y Y log det . n を予め LU 分解してパラメトライズすることで, det || の計算量を (1) から () へ減らせる; = 3 + diag , : 置換⾏列, : 1 0 0 ∗ ⋱ 0 ∗ ∗ 1 , 3: 0 ∗ ∗ 0 ⋱ ∗ 0 0 0 . Ø ℎ Y Y log det = ℎ Y Y log 18 Glowの構造 * Glow の元となるモデルである NICE, RealNVP では, チャネルの順番を逆にする操作 (置換の⼀種) が⼊っていた.
  16. 参考: 1×1 convolution の log-determinant の計算 n を 1×1-convolution の⼊⼒の

    ℎ×× のテンソル , を 1×1-convolution の重み⾏列とする. 1×1-convolution を conv2D(; ) と 書くと, log det conv2D(; ) = log det ⊗ 456 = log det 456 Y 17 = ℎ Y Y log det 19 Glowの構造 channel 1 channel 2 … channel c … filter 1 filter 2 filter c = + 1 層⽬ 層⽬ ℎ× ℎ× channel 1 channel 2 … channel c
  17. Affine coupling layers 20 Glowの構造 出典: [Kingma & Dhariwal., 2018.]

    Glow: Generative flow with invertible 1x1 convolutions.
  18. Affine coupling layers n affine 変換を使って, Jacobi ⾏列が三⾓⾏列になるように変換を設計. Ø 三⾓⾏列にすることで,

    ⾏列式の計算量を減らす. split(Y) は⽅向への分割を表す. NN(Y)はnonliear mapping を表す (出⼒を反映して log と表記). 21 Glowの構造
  19. Invertible 1×1 convolution の効果 n Invertible 1×1 convolution が効いていることを確認 Ø

    channel の permutation を reverse, shuffle, 1×1 convolution の 3 パターンで実験. 負の対数尤度の平均 (bits per dimension) が訓練過程でどう変わるかを調べた. 22 結果 出典: [Kingma & Dhariwal., 2018.] Glow: Generative flow with invertible 1x1 convolutions.
  20. 標準データセットでRealNVPと⽐較 n 標準データセットで RealNVP と⽐較 Ø どのデータセットでも, Glow の⽅が RealNVP

    より負の対数尤度の平均が低かった. 23 結果 出典: [Kingma & Dhariwal., 2018.] Glow: Generative flow with invertible 1x1 convolutions.
  21. 合成と補間 n CelebA-HQ datasetで実験. Ø 合成: 合成画像からのランダムにサンプリング (左図). Ø 補間:

    2つの実データに対応する潜在空間内の2点を線形補間し, 画像を合成 (右図). 24 結果 出典: [Kingma & Dhariwal., 2018.] Glow: Generative flow with invertible 1x1 convolutions.
  22. Semantic な操作 n CelebA datasetのラベルを使⽤. Ø 各画像に, 属性 (smiling, blond

    hair など) の有無で⼆値ラベルをつける. Ø ある属性を固定. 潜在空間で, その属性を持つ画像集合の平均ベクトルを 89: その属性を持たない画像集合の平均ベクトルを ;</ とする. Ø 89: − ;</ を属性を操作する⽅向とする. 25 結果 出典: [Kingma & Dhariwal., 2018.] Glow: Generative flow with invertible 1x1 convolutions.
  23. 温度と層の深さ n 温度: 温度 () を使って, サンプリングを ($ )=1 に⽐例するように⾏う.

    温度による変化を⾒た. 温度が1.0 の時はノイズが多い (上図). n 層の深さ: level を = 4 (shallow) と = 6 (deep) で⽐較. deep の⽅が良いサンプルが得られる (下図). 26 実験 T 0 0.25 0.6 0.7 0.8 0.9 1.0 出典: [Kingma & Dhariwal., 2018.] Glow: Generative flow with invertible 1x1 convolutions.
  24. 感想 n ⾼精度な画像合成を実現していて⾯⽩い. デモサイトはインパクトがある. n 計算上の⼯夫がいくつか施されていて, 勉強になる. Ø Flow based

    ⽣成モデルを調べていると, ⾏列式の計算の近似のために線形代数など計算の (細かい) ⼯夫が あって結構⾯⽩い. (例: Hutchinsonʼs trace estimater) n 本質的になぜ良いのかがよくわからない⼯夫もあった (例: actnorm). 発表者の理解不⾜?. n 理論的な背景や正当化 (普遍性定理 etc ) はあまり⾔及されていない. 他の論⽂やサーベイを当たったり⼿を動かしたりして理解を深めたい. 27 感想
  25. 参考⽂献 n 論⽂ (✔ はサーベイ) Ø [Dinh et al., 2014.]

    Dinh, L., Krueger, D., and Bengio, Y. (2014). NICE: Non-linear independent components estimation. International Conference on Learning Representations Workshop. Ø [Dinh et al., 2017.] Dinh, L., Sohl-Dickstein, J., and Bengio, S. (2017). Density estimation using Real NVP. International Conference on Learning Representations. Ø [Kingma & Dhariwal., 2018.] Kingma, D. P. and Dhariwal, P. (2018). Glow: Generative flow with invertible 1x1 convolutions. In Advances in Neural Information Processing Systems, pages 10236–10245. Ø [Rezende & Mohamed., 2015.] Rezende, D. and Mohamed, S. (2015). Variational inference with normalizing flows. In Proceedings of The 32nd International Conference on Machine Learning, pages 1530–1538. ü [Kobyzev et al., 2019.] Kobyzev, I., Prince, S., and Brubaker, M. (2019). Normalizing Flows: An Introduction and Review of Current Methods. arXiv: 1908.09257 [stat.ML] ü [Papamakarios et la., 2019.] Papamakarios, G., Nalisnick, E., Rezende, D., Mohamed, S., and Lakshminarayanan, B. (2019). Normalizing Flows for Probabilistic Modeling and Inference. arXiv: 1912.02762 [stat.ML] n ブログ Ø [Weng., 2018.] LilʼLog: Flow-based Deep Generative Models. https://lilianweng.github.io/lil-log/2018/10/13/flow-based-deep-generative-models.html n スライド Ø [Suzuki., 2019.] DL輪読会のスライド: Flow-based Deep Generative Models https://www.slideshare.net/DeepLearningJP2016/dlflowbased-deep-generative-models 28 参考⽂献