How To Plot Keras Activation Functions In A Notebook
I wanted to plot all Keras activation functions but some of them are not working. i.e. linear throws an error: AttributeError: 'Series' object has no attribute 'eval' which is w
Solution 1:
That's because the linear
activation returns the input without any modifications:
deflinear(x):
"""Linear (i.e. identity) activation function.
"""return x
Since you are passing a Pandas Series as input, the same Pandas Series will be returned and therefore you don't need to use K.eval()
:
df["linear"] = activations.linear(df["activation"])
As for the selu
activation, you need to reshape the input to (n_samples, n_output)
:
df["selu"] = K.eval(activations.selu(df["activation"].values.reshape(-1,1)))
And as for the hard_sigmoid
activation, its input should be explicitly a Tensor which you can create using K.variable()
:
df["hard_sigmoid"] = K.eval(activations.hard_sigmoid(K.variable(df["activation"].values)))
Further, exponential
activation works as you have written and there is no need for modifications.
Post a Comment for "How To Plot Keras Activation Functions In A Notebook"