我在Python中有兩個tensorflow程序,它們的差別很小,但兩個程序的權重和偏差總數相同。我有兩個tensorflow程序,如何保持相同的權重和偏差的初始值?
爲了便於比較,我想用相同的初始狀態啓動兩個程序。
程序1個
import tensorflow as tf
def getVariable(shape):
initial = tf.truncated_normal(shape, stddev=0.1)
return tf.Variable(initial)
W = getVariable([10, 10])
b = getVariable([10,10])
sess = tf.InteractiveSession()
tf.global_variables_initializer().run()
r = W * b
print(sess.run(r))
計劃2
import tensorflow as tf
def getVariable(shape):
initial = tf.truncated_normal(shape, stddev=0.1)
return tf.Variable(initial)
W1 = getVariable([10, 10])
b1 = getVariable([10,10])
sess = tf.InteractiveSession()
tf.global_variables_initializer().run()
r1 = W1 * b1
print(sess.run(r1))