tf.nn.dropout讲解

Dropout原理简述:

来自这位大佬

tf.nn.dropout是TensorFlow里面为了防止或减轻过拟合而使用的函数,它一般用在全连接层

Dropout就是在不同的训练过程中随机扔掉一部分神经元。也就是让某个神经元的激活值以一定的概率p,让其停止工作,这次训练过程中不更新权值,也不参加神经网络的计算。但是它的权重得保留下来(只是暂时不更新而已),因为下次样本输入时它可能又得工作了。 示意图如下:
在这里插入图片描述

tf.nn.dropout

tf.nn.dropout(
    x,
    keep_prob,
    noise_shape=None,
    seed=None,
    name=None
)
'''
Args:
	x: A floating point tensor.
	keep_prob: A scalar Tensor with the same type as x. The probability that each element is kept.
	noise_shape: A 1-D Tensor of type int32, representing the shape for randomly generated keep/drop flags.
	seed: A Python integer. Used to create random seeds. See tf.set_random_seed for behavior.
	name: A name for this operation (optional).
Returns:
    A Tensor of the same shape of x.
'''

说明

实现dropout,使用概率keep_prob,输出按1/keep_prob放大的输入元素,否则输出0。缩放使得预期的总和不变。

x:输入,一般是全连接网络的输出
keep_prob: 设置神经元被选中的概率,在初始化时keep_prob是一个占位符, keep_prob =tf.placeholder(tf.float32) 。tensorflow在run时设置keep_prob具体的值,例如keep_prob: 0.5
注意:train的时候才是dropout起作用的时候,设置0<keep_prob<1,
dev和test的时候不应该让dropout起作用,设置 keep_prob=1.0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值