在Tensorflow中,我可以用两种方式初始化变量:
global_variable_intializer在声明变量之前调用:
import tensorflow as tf
# Initialize the global variable and session
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
W = tf.Variable([.3], tf.float32)
b = tf.Variable([-.3], tf.float32)
b = tf.Variable([-.3], tf.float32)
linear_model = W * x + b
Run Code Online (Sandbox Code Playgroud)global_variable_intializer声明变量后调用:
import tensorflow as tf
W = tf.Variable([.3], tf.float32)
b = tf.Variable([-.3], tf.float32)
b = tf.Variable([-.3], tf.float32)
linear_model = W * x + b
# Initialize the global variable and session
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
Run Code Online (Sandbox Code Playgroud)两者有什么区别?哪个是初始化变量的最佳方法? …