folat 2021-08-08 22:43 采纳率: 0%
浏览 58

tensorflow中tf.Variable(tf.constant)变量吗?为什么可以这么写?

tf.Variable()是变量
tf.constant()是常量
但是书上用tf.Variable(tf.constant(0.1, shape=[OUTPUT_NODE]))来表示偏置项,为什么这么表示
为什么不直接用tf.Variable(0.1, shape=[OUTPUT_NODE])来表示

  • 写回答

2条回答 默认 最新

  • 八云黧 2021-08-08 22:58
    关注

    看源码:

      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对象,不能是值

    评论

报告相同问题?

问题事件

  • 创建了问题 8月8日