小编Pan*_*ami的帖子

在TensorFlow中初始化变量的最佳方法是什么?

在Tensorflow中,我可以用两种方式初始化变量:

  1. 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)
  2. 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)

两者有什么区别?哪个是初始化变量的最佳方法? …

python tensorflow tensor

5
推荐指数
1
解决办法
5637
查看次数

标签 统计

python ×1

tensor ×1

tensorflow ×1