Understand on the tf.variable_scope and tf.name_scope

来源:互联网 发布:mac上怎么切换输入法 编辑:程序博客网 时间:2024/05/22 04:43

Recent two weeks, I have spent much time on learning Tensorflow to implement my idea. Here, I would like to give some diferences between tf.variable_scope and tf.name_scope. Totally, these two method can summarize some basics operations into one node and show a clear graph visualized by TensorBoard. Next, I would like to highlight their differences.

First, we usually use the manner like w= tf.Variable(dtype=tf.float32, shape=[784, 10])) to define the variable w. Actually, the tensorflow would give a specific name for this variable in their graph, sometimes maybe like variable_1, variable_2, and so on like these. Occasionally, we would also like to define the w like this: w= tf.Variable(dtype=tf.float32, shape=[784, 10]), name=’w’). I think all these name methods are just for the compact visualization in the Tensorboard. In the same name_scope, variables with the same name would not allowed to be created andalso TF gives the errors.

Second, if the tf.variable_scope is used, the name of the variable would automatically be added a prefix with the variable scope name. In this regard, variables with the same names specified in the declaration would be fine, because a different variable scope name is added as their prefix.

Sometimes, we don’t not need to specify the variable name by the declaration, otherwise for reuse, which is another question and would be discussed when required in my future works.

阅读全文
0 0
原创粉丝点击