TensorFlow: getting variable by name

后端 未结 4 439
后悔当初
后悔当初 2020-12-08 09:36

When using the TensorFlow Python API, I created a variable (without specifying its name in the constructor), and its name property had the value

4条回答
  •  醉梦人生
    2020-12-08 10:20

    The easiest way to get a variable by name is to search for it in the tf.global_variables() collection:

    var_23 = [v for v in tf.global_variables() if v.name == "Variable_23:0"][0]
    

    This works well for ad hoc reuse of existing variables. A more structured approach—for when you want to share variables between multiple parts of a model—is covered in the Sharing Variables tutorial.

提交回复
热议问题