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

猜你喜欢

转载自blog.csdn.net/qq_32806793/article/details/85175005
今日推荐