我们在使用Tensorflow构建深度学习网络模型时,经常会使用name_scope和variable_scope。那么它们的区别体现在哪里呢?
① 为了说明以上问题,我们先解释tf.get_variable和tf.Variable的区别:
1. tf.get_variable: 有同名冲突问题(reuse=True可以解决,同一个);
2. tf.Variable: 没有同名冲突问题(自动在名字后面加上_1,不是同一个)。
② 接下来说明tf.name_scope和tf.variable_scope的区别:
1. tf.name_scope / tf.op_scope: 给tf.Variable加上prefix,不给tf.get_variable加prefix;
2. tf.variable_scope / tf.variable_op_scope: 给tf.Variable,tf.get_variable都加prefix。
PS: 如果tf.name_scope和tf.variable_scope相同,则相同的tf.get_variable没有影响,相同的tf.Variable会在tf.variable_scope prefix后加_1。