像我这样的菜鸡根本看不出以下的区别:
- tf.name_scope() 和 tf.variable_scope()
- tf.Variable() 和 tf.get_variable()
tf.Variable() 和 tf.get_variable()
- 都是变量使用方式, 所需参数都差不多,语法略有差异
tf.Variable是新建变量时使用,且只能新建变量!
-
需要注意的事:若新建的变量名已经存在,tf会为新建的同名变量加上前缀,来区别它们
-
这里的第二个
scope1
自动变成了scope1_1

tf.get_variable可以新建变量,但是若存在同名的变量,则不需要新建,直接将已经建立的变量拿来用就行
- 新建变量很简单。。
- 重用已有变量有两种写法
- 方式1:需要将
reuse=True
,这样可以在不同variable_scope
之间进行重用

- 方式2: 若
仅仅在
variable_scope
内进行重用,利用tf.get_variable_scope().reuse_variables()
即可

网友评论