In [1]:
import numpy as np
np.random.seed(42)
import tensorflow as tf
tf.set_random_seed(42)
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
n_input = 784
n_dense = 128
In [3]:
x = tf.placeholder(tf.float32, [None, n_input])
In [4]:
b = tf.Variable(tf.zeros([n_dense]))
W = tf.Variable(tf.random_uniform([n_input, n_dense])) # 1.
# W = tf.Variable(tf.random_normal([n_input, n_dense])) # 2.
# W = tf.get_variable('W', [n_input, n_dense],
# initializer=tf.contrib.layers.xavier_initializer())
In [5]:
z = tf.add(tf.matmul(x, W), b)
a = tf.sigmoid(z) # first with tf.sigmoid(), then stick with tf.tanh() or tf.nn.relu()
In [6]:
initializer_op = tf.global_variables_initializer()
In [7]:
with tf.Session() as session:
session.run(initializer_op)
layer_output = session.run(a, {x: np.random.random([1, n_input])})
In [8]:
layer_output
Out[8]:
In [9]:
_ = plt.hist(np.transpose(layer_output))
In [ ]: