美文网首页
tensorflow常用类

tensorflow常用类

作者: 律动的时间线 | 来源:发表于2017-11-11 14:25 被阅读0次

1 tf.Variable.__init__(initial_value,         trainable=True, collections=None,         validate_shape=True, name=None)

initial_value: A Tensor, or Python object convertible to aTensor.The initial value for the Variable。这里的初始值可以是数组,常量,以及随机出来的tensor.

trainable: If True, the default, also adds the variable to the the graph collection GraphKeys.TRAINABLE_VARIABLES. This collection is used as the default list of variables to use by the Optimizerclasses.

collections: List of graph collections keys. The new variable is added to these collections. Defaults to [GraphKeys.VARIABLES](默认值)

validate_shape(验证形状): If False, allows the variable to be initialized with a value of unknown shape. If True, the default, the shape of initial_value must be known.

name: Optional name for the variable. Defaults to' Variable' and gets uniquified automatically.

Returns:

 A Variable

2 tensorflow的主要数据类型

<1>tensor 

tf.constant(value, dtype=None, shape=None, name='Const');

        这个类型是tensorflow 中最常用的数据类型,他并不储存实际数值,但是保存了包括初始值,形状,名字等一系列信息,相当于与一个指针,先用这个指针构建出完整的Graph,在把指针指向具体的对象实现真实的计算,这只是一个形象的比喻。

<2>variable

tf.Variable(initial_value, trainable=True, collections=None,                                        validate_shape=True, name=None)

---initial_value: a tensor

tf.get_variable(name, shape=None, dtype=tf.float32, initializer=None, trainable=True, collections=None)

---配合tf.variable_scope(name,reuse = False),有两种用法

      这个类型用来定义需要进行学习的参数,ex.weights,bias等,会自动执行梯度下降。

<3>palceholder

tf.placeholder(dtype, shape=None, name=None)

 这个类型主要是用于数据的输入,相当于占位符,为Graph图中预先留下数据的入口。

函数:

在例如tf.matmul()的计算函数中,variable,tensor按照同一种数据,也就是说,可以理解为variable属于tensor,在tensorflow框架中任意计算,只要shape符合

相关文章

网友评论

      本文标题:tensorflow常用类

      本文链接:https://www.haomeiwen.com/subject/zxwwmxtx.html