Why do we name variables in Tensorflow?

前端 未结 4 817
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-24 01:53

In some of the places, I saw the syntax, where variables are initialized with names, sometimes without names. For example:

# With name
var = tf.Variable(0, n         


        
4条回答
  •  我在风中等你
    2020-12-24 02:08

    In fact, from the aspect to distinguish different variables, we totally can use the python name (the left part of the assignment sign, and we call the name as python name to avoid confusion. such as v in the following example) to name the variables. However, in the programming process, we usually rebind the python name to other objects (i.e., the op in Tensorflow), for example,

    v = tf.get_variable("v1", [3], initializer = tf.zeros_initializer)
    v = tf.get_variable("v2", [5], initializer = tf.zeros_initializer)
    

    Firstly, the python name v bind the tensor form first line (tf.get_variable("v1", [3], initializer = tf.zeros_initializer)). Then,the v rebind the tensor from the second line (tf.get_variable("v2", [5], initializer = tf.zeros_initializer)) and didn't bind the first tensor anymore. If we didn't give the tensorflow attribute name v1 and v2, how can we identify the tensor from the first line?

提交回复
热议问题