# 【python】不同的dropout们

dropout是一种激活函数（activation function），python中有若干种dropout函数，不尽相同。
dropout是为了防止或减轻过拟合而使用的函数，它一般用在全连接层。也有研究证明可以用在卷积层（小卷积核不适用）。

> PyTorch中的dropout：概率参数p表示置零的概率
> Tensorflow中的dropout：概率参数keep_prob表示保留的概率

## torch.nn.Dropout

class torch.nn.Dropout(p: float = 0.5, inplace: bool = False)
# Input: (*). Input can be of any shape
# Output: (*). Output is of the same shape as input


## torch.nn.functional.dropout

torch.nn.functional.dropout(input, p=0.5, training=True, inplace=False)
# During training, randomly zeroes some of the elements of the input tensor with probability p using samples from a Bernoulli distribution.


## torch.nn.modules.dropout

class Dropout(_DropoutNd):
r&quot;&quot;&quot;During training, randomly zeroes some of the elements of the input tensor with probability :attr:p using samples from a Bernoulli distribution. Each channel will be zeroed out independently on every forward call.
This has proven to be an effective technique for regularization and preventing the co-adaptation of neurons as described in the paper Improving neural networks by preventing co-adaptation of feature detectors_ .
Furthermore, the outputs are scaled by a factor of :math:\frac{1}{1-p} during training. This means that during evaluation the module simply computes an identity function.
Args:
p: probability of an element to be zeroed. Default: 0.5
inplace: If set to True, will do this operation in-place. Default: False
Shape:
- Input: :math:(*). Input can be of any shape
- Output: :math:(*). Output is of the same shape as input
Examples::
&gt;&gt;&gt; m = nn.Dropout(p=0.2)
&gt;&gt;&gt; input = torch.randn(20, 16)
&gt;&gt;&gt; output = m(input)
.. _Improving neural networks by preventing co-adaptation of feature detectors: https://arxiv.org/abs/1207.0580 &quot;&quot;&quot;
def forward(self, input: Tensor) -&gt; Tensor:
return F.dropout(input, self.p, self.training, self.inplace)


## tf.nn.dropout

dropout函数会以一个概率为keep_prob来决定神经元是否被抑制。如果被抑制，该神经元输出为0，如果不被抑制则该神经元的输出为输入的1/keep_prob倍？

def dropout(x, keep_prob, noise_shape=None, seed=None, name=None)