8
3

More than 5 years have passed since last update.

Chainerの活性化関数を可視化

Posted at

Chainerの活性化関数を可視化する。

動作環境

  • Ubuntu 16.04
  • Python 3.5.2
  • Chainer 3.2
  • numpy 1.13.3
  • opencv-python 3.2

ソースコード

全体はここ(Github)。main部は以下で、actfunに普段使うor使いそうな活性化関数を設定し、それを順次画像化していく。args.out_pathは出力先のフォルダ名。

import matplotlib.pyplot as plt
import chainer.functions as F

def main(args):
    actfun = [
        F.relu, F.elu, F.clipped_relu, F.leaky_relu, F.selu,
        F.sigmoid, F.hard_sigmoid, F.tanh, F.softplus,
    ]
    x = np.arange(-10, 10, 0.2)

    for af in actfun:
        file_name = getFilePath(args.out_path, af.__name__, '.png')
        print(file_name)
        y = [i.data for i in af(x)]
        f = plt.figure()
        a = f.add_subplot(111)
        a.plot(x, np.array(y))
        plt.savefig(file_name, dpi=200)

実行結果

キャプチャ.PNG

以上。

8
3
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
8
3