3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

枝刈りによる学習モデルの小型化の効果

Posted at

概要

「Chainer pruning」で検索すると以下のサイトがヒットする。

ChainerでPruning - ニューラルネットの軽量化

pruningの利点はパラメータの削減だが、これによって学習モデルの容量削減も期待できる。今回はlossを低下
させない範囲でpruningを繰り返してどこまで学習モデルを削減できるかを検証する。

動作環境

  • Ubuntu 16.04.4 LTS
  • Python 3.5.2
  • chainer 4.0.0
  • numpy 1.14.2
  • cupy 4.0.0
  • opencv-python 3.4.0.12

使用するコード

今回は以下のコードを使って検証を行っている。以下のコードの詳細については、コードが少し古いがここを参照されたい。

高圧縮jpeg画像のノイズを除去する

pruningに該当するのはtrain.pyresumeを設定する部分である。今回はpruningなし、0.5、0.6、0.7と増やしていく。

train.py
# Resume from a snapshot
if args.resume:
    chainer.serializers.load_npz(args.resume, trainer)
    # Set pruning
    # http://tosaka2.hatenablog.com/entry/2017/11/17/194051
    masks = pruning.create_model_mask(model, args.pruning, args.gpu_id)
    trainer.extend(pruning.pruned(model, masks))

chainerのtrainerを使用している環境であれば、Tools/pruning.pyと上記該当箇所の修正で利用できる。

学習結果

epoch pruning 学習モデル容量 [MB] loss validation loss
0-100 - 64.5 0.002992 0.002654
100-125 0.5 39.5 0.002978 0.002623
125-140 0.6 33.3 0.002984 0.002621
140-150 0.7 26.9 0.003037 0.002646

lossが0.003を割りそうにないのでepochを150で止めた。しかし学習モデル容量は64.5 MBから26.9 MBまで40%以上の削減に成功した。

lossの全体像は以下の通り。

loss.png

生成される画像については目視でpruningによる劣化がないことを確認した。ちなみに容量が減ったからといって処理時間が拘束になるという効果は期待できないので注意。

以上。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?