From df4662a9941173ede9232b4249b84bb503b94df1 Mon Sep 17 00:00:00 2001 From: Yu-Fan Tung Date: Mon, 18 Feb 2019 14:43:43 +0800 Subject: [PATCH] Add activation function --- examples/3_NeuralNetworks/neural_network.py | 4 ++-- examples/3_NeuralNetworks/neural_network_raw.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/3_NeuralNetworks/neural_network.py b/examples/3_NeuralNetworks/neural_network.py index 1fff2d54..fc588677 100644 --- a/examples/3_NeuralNetworks/neural_network.py +++ b/examples/3_NeuralNetworks/neural_network.py @@ -40,9 +40,9 @@ def neural_net(x_dict): # TF Estimator input is a dict, in case of multiple inputs x = x_dict['images'] # Hidden fully connected layer with 256 neurons - layer_1 = tf.layers.dense(x, n_hidden_1) + layer_1 = tf.nn.relu(tf.layers.dense(x, n_hidden_1)) # Hidden fully connected layer with 256 neurons - layer_2 = tf.layers.dense(layer_1, n_hidden_2) + layer_2 = tf.nn.relu(tf.layers.dense(layer_1, n_hidden_2)) # Output fully connected layer with a neuron for each class out_layer = tf.layers.dense(layer_2, num_classes) return out_layer diff --git a/examples/3_NeuralNetworks/neural_network_raw.py b/examples/3_NeuralNetworks/neural_network_raw.py index 9c9962ba..b1cb9229 100644 --- a/examples/3_NeuralNetworks/neural_network_raw.py +++ b/examples/3_NeuralNetworks/neural_network_raw.py @@ -20,7 +20,7 @@ import tensorflow as tf # Parameters -learning_rate = 0.1 +learning_rate = 0.01 num_steps = 500 batch_size = 128 display_step = 100 @@ -51,9 +51,9 @@ # Create model def neural_net(x): # Hidden fully connected layer with 256 neurons - layer_1 = tf.add(tf.matmul(x, weights['h1']), biases['b1']) + layer_1 = tf.nn.relu(tf.add(tf.matmul(x, weights['h1']), biases['b1'])) # Hidden fully connected layer with 256 neurons - layer_2 = tf.add(tf.matmul(layer_1, weights['h2']), biases['b2']) + layer_2 = tf.nn.relu(tf.add(tf.matmul(layer_1, weights['h2']), biases['b2'])) # Output fully connected layer with a neuron for each class out_layer = tf.matmul(layer_2, weights['out']) + biases['out'] return out_layer