LoginSignup
1
1

More than 5 years have passed since last update.

kerasの活性化関数

Posted at

概要

kerasの活性化関数をグラフにしてみた。

写真

acti4.png

サンプルコード

import matplotlib.pyplot as plt
import numpy as np
from tensorflow.contrib.keras.python import keras
from tensorflow.contrib.keras.python.keras import backend as K

def tanh(x):
    a = np.asarray([x])
    a = K.variable(a)
    result = (K.get_value(K.tanh(a)))
    return result[0]
def relu(x):
    a = np.asarray([x])
    a = K.variable(a)
    result = (K.get_value(K.relu(a)))
    return result[0]
def sigmoid(x):
    a = np.asarray([x])
    a = K.variable(a)
    result = (K.get_value(K.sigmoid(a)))
    return result[0]
def linear(x):
    return keras.activations.linear(x)

x = np.linspace(-1.0, 1.0, 100)
plt.plot(x, tanh(x), label = "tanh")
plt.plot(x, relu(x), label = "relu")
plt.plot(x, sigmoid(x), label = "sigmoid")
plt.plot(x, linear(x), label = "linear")
plt.legend()
plt.savefig("acti4.png")
plt.show()

以上。

1
1
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
1
1