tf.name_scope()

此函数作用是共享变量。在一个作用域scope内共享一些变量,简单来说,就是给变量名前面加个变量空间名,只限于tf.Variable()的变量

tf.variable_scope()

和tf.name_scope()作用一样,不过包括tf.get_variable()的变量和tf.Variable()的变量

在同一个程序中多次调用,在第一次调用之后需要将reuse参数设置为True

1 with tf.variable_scope("one"):
2     a = tf.get_variable("v", [1]) #a.name == "one/v:0"
3 with tf.variable_scope("one"):
4     b = tf.get_variable("v", [1]) #创建两个名字一样的变量会报错 ValueError: Variable one/v already exists 
5 with tf.variable_scope("one", reuse = True): #注意reuse的作用。
6     c = tf.get_variable("v", [1]) #c.name == "one/v:0" 成功共享,因为设置了reuse

 

相关文章:

  • 2021-09-27
  • 2021-10-10
  • 2022-01-25
  • 2021-12-20
  • 2022-12-23
  • 2021-10-21
  • 2021-05-26
  • 2021-08-22
猜你喜欢
  • 2022-02-08
  • 2022-12-23
  • 2022-03-09
  • 2021-09-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案