Slide 1

Slide 1 text

Knowledge ~蒸留・モデル圧縮・そしてKT~ 2019/9/24 LT資料 Masa Twitter @asas_mimi 1

Slide 2

Slide 2 text

モデルのKnowledge有効活用 2 本日のテーマ

Slide 3

Slide 3 text

モデルの圧縮+α 3 本日のモチベーション

Slide 4

Slide 4 text

やりたいこと = モデルの圧縮 Model Compression 4

Slide 5

Slide 5 text

圧縮の動機 • 精度の良いDNNはデカい • できるだけ精度を保ちながら、計算量を減らしたいんです 5 https://www.learnopencv.com/pytorch-for-beginners-image- classification-using-pre-trained-models/

Slide 6

Slide 6 text

どんぐらいデカいの? 6 http://image-net.org/challenges/talks_2017/ILSVRC2017_overview.pdf 例えばこれを見てみよう

Slide 7

Slide 7 text

AlexNet (2012) 7 • 2012年のILSVRCにおいて,従来の画像認識のデファクトスタンダードであったSIFT + Fisher Vector + SVMというアプローチに大差をつけて優勝 • DNNブームの切っ掛け • 現在では比較的小規模なモデル

Slide 8

Slide 8 text

AlexNet の疑似計算量 8 層 入力サイズ ch数 カーネル サイズ Stride 出力サイズ wの個数 乗算回数 input 3 227*227 conv1 227*227 96 11*11 4 55*55 0.03 M 112 M pool1 55*55 96 3*3 2 27*27 conv2 27*27 256 5*5 1 27*27 0.6 M 448 M pool2 27*27 256 3*3 2 13*13 conv3 13*13 384 3*3 1 13*13 0.9 M 150 M conv4 13*13 384 3*3 1 13*13 1.3 M 224 M conv5 13*13 256 3*3 1 13*13 0.9 M 150 M pool5 13*13 256 3*3 2 6*6 fc6 9216 4096 38 M 38 M fc7 4096 4096 17 M 17 M fc8 4096 1000 4 M 4 M total 62 M 1,142 M ■ conv層 ① wの個数 : カーネルサイズ*入力ch数 *出力ch数 ② 乗算回数: wの個数*入力サイズ/(Stride)2 ■ pool層 wなし。乗算回数なし ■ fc層 ① wの個数 : 入力サイズ*出力サイズ ② 乗算回数: wの個数 メモリ問題 (fc層を減らせば何とかなる。) 計算量=1G回計算 • 現在では比較的小規模なモデル. それでも、畳み込み層が増えるほど、計算量ヤバい

Slide 9

Slide 9 text

9 http://josephpcohen.com/w/visualizing-cnn-architectures-side-by-side-with-mxnet/ AlexNet 224×224 (2012) 他のDNNアーキテクチャは?

Slide 10

Slide 10 text

10 http://josephpcohen.com/w/visualizing-cnn-architectures-side-by-side-with-mxnet/ AlexNet 224×224 (2012) VGG 224×224 (9/2014) GoogLeNet 224×224 (9/2014) Inception V3 299×299 (12/2015) Resnet (n=9, 56 Layers) 28×28(12/2015) ・・・

Slide 11

Slide 11 text

11 http://sqlml.azurewebsites.net/2017/09/12/convolutional-neural-network/

Slide 12

Slide 12 text

やりたいこと = モデルの圧縮 Model Compression 12 再掲 精度はできるだけ、 保ちつつ

Slide 13

Slide 13 text

モデル圧縮の全体像 13 Yu Cheng, Duo Wang, Pan Zhou, Tao Zhang. 2017 “A Survey of Model Compression and Acceleration for Deep Neural Networks” IEEE https://arxiv.org/abs/1710.09282 distillation??

Slide 14

Slide 14 text

distillation (蒸留) 14

Slide 15

Slide 15 text

蒸留 ? 15 Wikipedia (2019/9/12時点) https://ja.wikipedia.org/wiki/%E8%92%B8%E7%95%99

Slide 16

Slide 16 text

蒸留 (Knowledge distillation) ? 16 Training a compact neural network with distilled knowledge of a large model

Slide 17

Slide 17 text

蒸留 (Knowledge distillation) ? 17 Training a compact neural network with distilled knowledge of a large model 生徒モデル 教師モデル

Slide 18

Slide 18 text

蒸留 (Knowledge distillation) 18 SimplifiedKnowledge Distillation https://towardsdatascience.com/knowledge-distillation-simplified-dd4973dbc764 ① 精度が良い大きなモデル(教師モデル)を用意 (含むアンサンブル) ② いい感じでknowledgeを抽出 ③ いい感じでknowledgeを活かして、 コンパクトなモデル(生徒モデル)を学習

Slide 19

Slide 19 text

soft target lossアプローチ 19 Deep Learningにおける知識の蒸留 http://codecrafthouse.jp/p/2018/01/knowledge-distillation/ 教師モデルの 出力分布がヒントになるのでは? これは普通の損失関数 生徒モデルの出力分布が 教師モデルと近くなるように する損失

Slide 20

Slide 20 text

soft target lossアプローチ 20 Deep Learningにおける知識の蒸留 http://codecrafthouse.jp/p/2018/01/knowledge-distillation/ 温度パラメータTで割って、 Softmaxに突っ込む KL Divergence (クロスエントロピー)損失関数 教師モデルの出力分布と生徒ラベルの 出力分布を近づけるための 損失関数 =soft target loss 一例

Slide 21

Slide 21 text

-6 -5 -4 -3 -2 -1 0 1 2 3 4 5 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 犬 猫 鳥 豚 牛 人 logit prob prob with T = 1 prob with T = 2 prob with T = 3 prob with T = 4 logit 温度パラメータT (イメージ) 21 ご参考 元のlogit出力 温度パラメータTを上げると、 正解クラス以外の類似クラスのprobが 大きくなっていく(蒸留成功?) • なんで温度パラメータなんて使ってるの?

Slide 22

Slide 22 text

蒸留 ? 22 Wikipedia (2019/9/12時点) https://ja.wikipedia.org/wiki/%E8%92%B8%E7%95%99

Slide 23

Slide 23 text

soft target lossアプローチ まとめ 23 一例 1/T 1/T Soft max 関 数 Soft max 関 数 soft target 損失関数 hard target 損失関数 正解データ Soft max 関 数 (1-λ) λ 教師モデル 生徒モデル 損失情報 backprop 損失情報 backprop forward インプットデータ

Slide 24

Slide 24 text

他にもいろいろあるよ 蒸留はKT(Knowledge Transfer)の一つ 24

Slide 25

Slide 25 text

中間層も有効活用したい? 25 Hint Learningですね。 Chen et al., 2017 “Learning Efficient Object Detection Models with Knowledge Distillation”. https://papers.nips.cc/paper/6676-learning-efficient-object-detection-models-with-knowledge-distillation.pdf 教師モデルの Hint 層 生徒モデルの Guided 層 チャネル数や空間サイズ が異なる場合は調整

Slide 26

Slide 26 text

Attention please! 26 教師モデルのAttentionを学ぶ: ATTENTION TRANSFER Sergey et al., 2017 “PAYING MORE ATTENTION TO ATTENTION: IMPROVING THE PERFORMANCE OF CONVOLUTIONAL NEURAL NETWORKS VIA ATTENTION TRANSFER ”. https://arxiv.org/pdf/1612.03928.pdf

Slide 27

Slide 27 text

Attention? 27 Minh-Thang Luong et al., 2015”Effective Approaches to Attention-based Neural Machine Translation” https://arxiv.org/abs/1508.04025 自然言語処理とかで流行ってるアレ? 余談

Slide 28

Slide 28 text

CNNでAttention? 28 いっぱい論文・事例ありました 余談

Slide 29

Slide 29 text

Squeeze-and-Excitation Net 29 Jie Hu et al.,2018” Squeeze-and-Excitation Networks” https://arxiv.org/pdf/1709.01507.pdf 余談 ILSVRC 2017 画像分類 Top の手法 Squeeze-and-Excitation Networks 畳み込み層の各チャンネルに対して重みをつけている。 → これは、チャネルに対するAttentionの事例 1*1*C

Slide 30

Slide 30 text

ATTENTION TRANSFER 30 今回の論文は、空間に対するAttentionの事例ですね。 Sergey et al., 2017 “PAYING MORE ATTENTION TO ATTENTION: IMPROVING THE PERFORMANCE OF CONVOLUTIONAL NEURAL NETWORKS VIA ATTENTION TRANSFER ”. https://arxiv.org/pdf/1612.03928.pdf

Slide 31

Slide 31 text

ATTENTION TRANSFER 31 論文では、損失ベースのほかに、勾配ベースのアプローチも載ってます Sergey et al., 2017 “PAYING MORE ATTENTION TO ATTENTION: IMPROVING THE PERFORMANCE OF CONVOLUTIONAL NEURAL NETWORKS VIA ATTENTION TRANSFER ”. https://arxiv.org/pdf/1612.03928.pdf

Slide 32

Slide 32 text

モデルの圧縮+α 32 モチベーション おまけ せっかくなので、 転移学習の面白い論文もご紹介

Slide 33

Slide 33 text

転移学習 ? 33 Transfer Learning - Machine Learning's Next Frontier より http://ruder.io/transfer-learning/index.html

Slide 34

Slide 34 text

CS231n: Convolutional Neural Networks for Visual Recognition http://cs231n.stanford.edu/slides/winter1516_lecture11.pdf Fine-tuningは有名ですね 34 Sourse モデル Target モデル Knowledge (重み、構造)

Slide 35

Slide 35 text

DELTA: 35 DEEP LEARNING TRANSFER USING FEATURE MAP WITH ATTENTION FOR CONVOLUTIONAL NETWORKS Li et al., 2019 “DELTA: DEEP LEARNING TRANSFER USING FEATURE MAP WITH ATTENTION FOR CONVOLUTIONAL NETWORKS”. https://arxiv.org/pdf/1901.09229.pdf ■転移学習は、以下のようなものに悩みがち ✓ over-fitting with limited number of training samples ✓ Inefficient and even negative transfer ■ 本論文の工夫は、 ✓ regularizing the Behavior rather than model parameters ✓ “unactivated channel re-usage” using an attention mechanism with feature map regularizeon

Slide 36

Slide 36 text

ATTENTION TRANSFER 36 今回の論文は、空間に対するAttentionの事例ですね。 https://postersession.ai/poster/delta-deep-learning-transfer-using-featu/

Slide 37

Slide 37 text

ATTENTION TRANSFER 37 今回の論文は、空間に対するAttentionの事例ですね。 https://postersession.ai/poster/delta-deep-learning-transfer-using-featu/ FM間のL2 loss モデルパラメータそのもの、よりその振る舞い(Behavior)が近く なるように設計する Similar weights are not necessary for producing similar outputs

Slide 38

Slide 38 text

ATTENTION TRANSFER 38 今回の論文は、空間に対するAttentionの事例ですね。 https://postersession.ai/poster/delta-deep-learning-transfer-using-featu/ j-chを抜いた時のsorceモデルの損失と 同モデルの損失の差分からj-chの重みを推定 FM間のL2 loss 各chの重み 出力に貢献するchは動かさず、貢献しないchは、再学習させる Not all channels are necessary for knowledge transfer → unactivated channel re-usage

Slide 39

Slide 39 text

ATTENTION TRANSFER 39 今回の論文は、空間に対するAttentionの事例ですね。 https://postersession.ai/poster/delta-deep-learning-transfer-using-featu/ j-chを抜いた時のsorceモデルの損失と 同モデルの損失の差分からj-chの重みを推定 FM間のL2 loss 各chの重み +Ω’’(w|w*) :sorceとtargetのwの距離に関する正則化

Slide 40

Slide 40 text

簡単なDemo 40