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)
実行結果
以上。