【问题标题】:Tensorflow: How to initlialize all variables in a given variable scopeTensorflow:如何初始化给定变量范围内的所有变量
【发布时间】:2017-10-19 05:47:50
【问题描述】:

我想初始化给定变量范围内的所有变量,除了列出所有变量的名称之外,还有其他方法吗? 作用域内的变量已经创建但没有初始化,只需要初始化

【问题讨论】:

    标签: python-2.7 machine-learning tensorflow deep-learning tensorflow-gpu


    【解决方案1】:

    您可以使用

    获取范围内的变量列表
    my_scope = 'my_scope_name'
    scope_variables=  tf.get_collection(tf.GraphKeys.VARIABLES, scope=my_scope )
    

    然后用

    初始化它们
    init_scope = tf.variables_initializer(scope_variables, name="init_"+my_scope )
    sess.run(init_scope)
    

    【讨论】:

      猜你喜欢
      • 2010-10-19
      • 2013-02-13
      • 2016-08-14
      • 1970-01-01
      • 1970-01-01
      • 2019-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多