activation-function

How to plot keras activation functions in a notebook

偶尔善良 提交于 2019-12-11 17:08:47
问题 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 weird. How can I plot the rest of my activation functions? points = 100 zeros = np.zeros((points,1)) df = pd.DataFrame({"activation": np.linspace(-1.2,1.2,points)}) df["softmax"] = K.eval(activations.elu(df["activation"])) #df["linear"] = K.eval(activations.linear(df["activation"])) df["tanh"] = K.eval(activations.tanh

Tensorflow apply different activation functions in output layer

ε祈祈猫儿з 提交于 2019-12-11 10:21:22
问题 I want to build a network like this The hidden layer is not important, I want to know how can I write the code in my output layer, and the following is my code, am I right? Parameters: state_dim = 13 layer1_size, layer2_size = 400, 300 action_dim = 2 W1 = self.variable([state_dim,layer1_size],state_dim) b1 = self.variable([layer1_size],state_dim) W2 = self.variable([layer1_size,layer2_size],layer1_size) b2 = self.variable([layer2_size],layer1_size) W3 = tf.Variable(tf.random_uniform([layer2

Artificial Neural Network RELU Activation Function and Gradients

▼魔方 西西 提交于 2019-12-11 07:05:58
问题 I have a question. I watched a really detailed tutorial on implementing an artificial neural network in C++. And now I have more than a basic understanding of how a neural network works and how to actually program and train one. So in the tutorial a hyperbolic tangent was used for calculating outputs, and obviously its derivative for calculating gradients. However I wanted to move on to a different function. Specifically Leaky RELU (to avoid dying neurons). My question is, it specifies that

How do I use categorical_hinge in Keras?

吃可爱长大的小学妹 提交于 2019-12-10 14:54:52
问题 Maybe a very dumb question but I can't find an example how to use categorical_hinge in Keras. I do classification and my target is shape(,1) with values [-1,0,1] so I have 3 categories. Using the functional API I have set up my output layer like this: output = Dense(1, name='output', activation='tanh', kernel_initializer='lecun_normal')(output1) Then I apply: model.compile(optimizer=adam, loss={'output': 'categorical_hinge'}, metrics=['accuracy']) The result is that the model is converging

ReLU derivative with NumPy

无人久伴 提交于 2019-12-10 10:25:09
问题 import numpy as np def relu(z): return np.maximum(0,z) def d_relu(z): z[z>0]=1 z[z<=0]=0 return z x=np.array([5,1,-4,0]) y=relu(x) z=d_relu(y) print("y = {}".format(y)) print("z = {}".format(z)) The code above prints out: y = [1 1 0 0] z = [1 1 0 0] instead of y = [5 1 0 0] z = [1 1 0 0] From what I understand the function calls I've used should only be doing passing by value,passing a copy of the variable. Why is my d_relu function affecting the y variable? 回答1: Your first mistake is in

Tensorflow custom activation function

元气小坏坏 提交于 2019-12-08 11:05:32
问题 I implemented a network with TensorFlow and created the model doing the following in my code: def multilayer_perceptron(x, weights, biases): layer_1 = tf.add(tf.matmul(x, weights["h1"]), biases["b1"]) layer_1 = tf.nn.relu(layer_1) out_layer = tf.add(tf.matmul(layer_1, weights["out"]), biases["out"]) return out_layer I initialize the weights and the biases doing: weights = { "h": tf.Variable(tf.random_normal([n_input, n_hidden_1])), "out": tf.Variable(tf.random_normal([n_hidden_1, n_classes]))

ReLU derivative with NumPy

懵懂的女人 提交于 2019-12-06 00:18:29
import numpy as np def relu(z): return np.maximum(0,z) def d_relu(z): z[z>0]=1 z[z<=0]=0 return z x=np.array([5,1,-4,0]) y=relu(x) z=d_relu(y) print("y = {}".format(y)) print("z = {}".format(z)) The code above prints out: y = [1 1 0 0] z = [1 1 0 0] instead of y = [5 1 0 0] z = [1 1 0 0] From what I understand the function calls I've used should only be doing passing by value,passing a copy of the variable. Why is my d_relu function affecting the y variable? Your first mistake is in assuming python passes objects by value... it doesn't - it's pass by assignment (similar to passing by reference

Keras How to use max_value in Relu activation function

不打扰是莪最后的温柔 提交于 2019-12-05 04:16:03
Relu function as defined in keras/activation.py is: def relu(x, alpha=0., max_value=None): return K.relu(x, alpha=alpha, max_value=max_value) It has a max_value which can be used to clip the value. Now how can this be used/called in the code? I have tried the following: (a) model.add(Dense(512,input_dim=1)) model.add(Activation('relu',max_value=250)) assert kwarg in allowed_kwargs, 'Keyword argument not understood: ' + kwarg AssertionError: Keyword argument not understood: max_value (b) Rel = Activation('relu',max_value=250) same error (c) from keras.layers import activations uu = activations

In simple multi-layer FFNN only ReLU activation function doesn't converge

三世轮回 提交于 2019-12-02 11:47:01
I'm learning tensorflow, deep learning and experimenting various kinds of activation functions. I created a multi-layer FFNN for the MNIST problem. Mostly based on the tutorial from the official tensorflow website, except that 3 hidden layers were added. The activation functions I have experimented are: tf.sigmoid , tf.nn.tanh , tf.nn.softsign , tf.nn.softmax , tf.nn.relu . Only tf.nn.relu doesn't converge, the network output random noise (testing accuracy is about 10%). The following are my source code: import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data mnist =

Activation function for output layer for regression models in Neural Networks

寵の児 提交于 2019-12-01 03:04:17
I have been experimenting with neural networks these days. I have come across a general question regarding the activation function to use. This might be a well known fact to but I couldn't understand properly. A lot of the examples and papers I have seen are working on classification problems and they either use sigmoid (in binary case) or softmax (in multi-class case) as the activation function in the out put layer and it makes sense. But I haven't seen any activation function used in the output layer of a regression model. So my question is that is it by choice we don't use any activation