tensorflow的学习笔记一(初级)

函数类: tf.reshape(tensor, shape, name=None) 
函数的作用是将tensor变换为参数shape的形式。 

其中shape为一个列表形式,特殊的一点是列表中可以存在-1。-1代表的含义是不用我们自己指定这一维的大小,函数会自动计算,但列表中只能存在一个-1。(当然如果存在多个-1,就是一个存在多解的方程了)

代码:

with tf.Session() as sess:  
    a = np.array([[1,2,3],[4,5,6]])
    b = tf.reshape(a,[3,2])
  #  sess.run(b)
    print(sess.run(b))
[[1 2]
 [3 4]
 [5 6]]

注意,这里面的之后的类型,也可以用tuple,(3,2)

tf.decode_csv()

tf.decode_csv(
    records
,
    record_defaults
,
    field_delim
=',',
    use_quote_delim
=True,
    name
=None,
    na_value
=''
)

Convert CSV records to tensors. Each column maps to one tensor.每一列都是一个张量。

  • records: A Tensor of type string. Each string is a record/row in the csv and all records should have the same format.
  • record_defaults: A list of Tensor objects with specific types. Acceptable types are float32float64int32,int64string. One tensor per column of the input record, with either a scalar default value for that column or empty if the column is required.

返回:A list of Tensor objects

iter() 函数用来生成迭代器

 tf.losses.mean_squared_error(labels=tf_y, predictions=outs) 这是均方差,是L2的形式。

predictions, target

tf.layers.dense用法

dense:全连接层

相当于添加一个层,即初学的add_layer()函数


tf.layers.dense(
    inputs,
    units,
    activation=None,
    use_bias=True,
    kernel_initializer=None,
    bias_initializer=tf.zeros_initializer(),
    kernel_regularizer=None,
    bias_regularizer=None,
    activity_regularizer=None,
    kernel_constraint=None,
    bias_constraint=None,
    trainable=True,
    name=None,
    reuse=None
)

其中:

        inputs: 该层的输入

        units: 输出的大小(维数),整数或long

        activation: 使用什么激活函数(神经网络的非线性层),默认为None,不使用激活函数

        use_bias: 使用bias为True(默认使用),不用bias改成False即可

全连接层的定义: 全连接层的每一个结点都与上一层的所有结点相连,用来把前边提取到的特征综合起来。由于其全相连的特性,一般全连接层的参数也是最多的。也就是中间的隐藏层吧。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值