Skip to content

Instantly share code, notes, and snippets.

@ahaider3
Created August 18, 2017 14:27
Show Gist options
  • Save ahaider3/82a8eae7a378a729d2420968acfe4bfd to your computer and use it in GitHub Desktop.
Save ahaider3/82a8eae7a378a729d2420968acfe4bfd to your computer and use it in GitHub Desktop.
Tensorflow random initialization
import tensorflow as tf
import numpy as np
X_DIM=2048
Y_DIM=128
tf.set_random_seed(123)
varz = tf.get_variable("v", [X_DIM, Y_DIM],
dtype=tf.float32,
initializer=tf.random_normal_initializer(seed=123))
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
v1 = sess.run(varz)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
v2 = sess.run(varz)
print(np.max(np.absolute(v2-v1)))
assert(np.allclose(v1, v2, rtol=1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment