tf.Variable()是变量
tf.constant()是常量
但是书上用tf.Variable(tf.constant(0.1, shape=[OUTPUT_NODE]))来表示偏置项,为什么这么表示
为什么不直接用tf.Variable(0.1, shape=[OUTPUT_NODE])来表示
看源码:
def __init__(self,
initial_value=None,
trainable=None,
validate_shape=True,
caching_device=None,
name=None,
variable_def=None,
dtype=None,
import_scope=None,
constraint=None,
synchronization=VariableSynchronization.AUTO,
aggregation=VariableAggregation.NONE,
shape=None):
"""Creates a new variable with value `initial_value`.
Args:
initial_value: A `Tensor`, or Python object convertible to a `Tensor`,
which is the initial value for the Variable. The initial value must have
a shape specified unless `validate_shape` is set to False. Can also be a
callable with no argument that returns the initial value when called. In
that case, `dtype` must be specified. (Note that initializer functions
from init_ops.py must first be bound to a shape before being used here.)
"""
Variable的构造函数第一个参数说了是一个Tensor对象,不能是值
但是在设置global_step的时候是这么写的
global_step = tf.Variable(0, trainable=False),第一个参数直接用的0
代码在这个链接 https://www.jianshu.com/p/9f35d452e81c https://www.jianshu.com/p/9f35d452e81c