简单神经网络

简单神经网络

tf.random_normal()函数用于从“服从指定正态分布的序列”中随机取出指定个数的值。

tf.random_normal(shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None)
x = tf.random.normal([2,784])

tf.Variable(initializer,name),参数initializer是初始化参数,name是可自定义的变量名称。

tf.random.truncated_normal()用法——截断正态分布
输出截断的正态分布的随机值。

tf.random.truncated_normal(
    shape,
    mean=0.0,
    stddev=1.0,
    dtype=tf.dtypes.float32,
    seed=None,
    name=None
)

shape: A 1-D integer Tensor or Python array. The shape of the output tensor.
mean: A 0-D Tensor or Python value of type dtype. The mean of the truncated normal distribution.均值默认为0
stddev: A 0-D Tensor or Python value of type dtype. The standard deviation of the normal distribution, before truncation.截断前正态分布的标准偏差,默认为1.0
dtype: The type of the output.
seed: A Python integer. Used to create a random seed for the distribution. Seetf.compat.v1.set_random_seed for behavior.
name: A name for the operation (optional).

tf.multiply()两个矩阵中对应元素各自相乘

tf.matmul()将矩阵a乘以矩阵b,生成a * b

dense :全连接层 相当于添加一个层

tf.layers.dense(

    inputs,

    units,

    activation=None,

    use_bias=True,

    kernel_initializer=None,  ##卷积核的初始化器

    bias_initializer=tf.zeros_initializer(),  ##偏置项的初始化器,默认初始化为0

    kernel_regularizer=None,    ##卷积核的正则化,可选

    bias_regularizer=None,    ##偏置项的正则化,可选

    activity_regularizer=None,   ##输出的正则化函数

    kernel_constraint=None,   

    bias_constraint=None,

    trainable=True,

    name=None,  ##层的名字

    reuse=None  ##是否重复使用参数

)

部分参数解释:

inputs:输入该网络层的数据

units:输出的维度大小,改变inputs的最后一维

activation:激活函数,即神经网络的非线性变化

use_bias:使用bias为True(默认使用),不用bias改成False即可,是否使用偏置项

trainable=True:表明该层的参数是否参与训练。如果为真则变量加入到图集合中

GraphKeys.TRAINABLE_VARIABLES (see tf.Variable)

在其他网站上看到的使用现象

dense1 = tf.layers.dense(inputs=pool3, units=1024, activation=tf.nn.relu,

                                       kernel_regularizer=tf.contrib.layers.l2_regularizer(0.003))

全连接层

dense1 = tf.layers.dense(inputs=pool3, units=1024, activation=tf.nn.relu)

dense2= tf.layers.dense(inputs=dense1, units=512, activation=tf.nn.relu)

logits= tf.layers.dense(inputs=dense2, units=10, activation=None)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值