Skip to content

Instantly share code, notes, and snippets.

@hackintoshrao
Created June 21, 2018 04:35
Show Gist options
  • Select an option

  • Save hackintoshrao/4eea0cad4e3ae90f96a83254f1325f3e to your computer and use it in GitHub Desktop.

Select an option

Save hackintoshrao/4eea0cad4e3ae90f96a83254f1325f3e to your computer and use it in GitHub Desktop.
Using RELU activation with hidden layer for tensorflow
# Quiz Solution
# Note: You can't run code in this tab
import tensorflow as tf
output = None
hidden_layer_weights = [
[0.1, 0.2, 0.4],
[0.4, 0.6, 0.6],
[0.5, 0.9, 0.1],
[0.8, 0.2, 0.8]]
out_weights = [
[0.1, 0.6],
[0.2, 0.1],
[0.7, 0.9]]
# Weights and biases
weights = [
tf.Variable(hidden_layer_weights),
tf.Variable(out_weights)]
biases = [
tf.Variable(tf.zeros(3)),
tf.Variable(tf.zeros(2))]
# Input
features = tf.Variable([[1.0, 2.0, 3.0, 4.0], [-1.0, -2.0, -3.0, -4.0], [11.0, 12.0, 13.0, 14.0]])
# TODO: Create Model
hidden_layer = tf.add(tf.matmul(features, weights[0]), biases[0])
hidden_layer = tf.nn.relu(hidden_layer)
logits = tf.add(tf.matmul(hidden_layer, weights[1]), biases[1])
# TODO: Print session results
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print(sess.run(logits))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment