|
|
|
@ -847,7 +847,35 @@ def cos_sim(X, Y, **kwargs):
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def dropout(x, dropout_prob, is_test=False, seed=0, **kwargs):
|
|
|
|
|
def dropout(x, dropout_prob, is_test=False, seed=None, **kwargs):
|
|
|
|
|
"""
|
|
|
|
|
Computes dropout.
|
|
|
|
|
|
|
|
|
|
Drop or keep each element of `x` independently. Dropout is a regularization
|
|
|
|
|
technique for reducing overfitting by preventing neuron co-adaption during
|
|
|
|
|
training. The dropout operator randomly set (according to the given dropout
|
|
|
|
|
probability) the outputs of some units to zero, while others are remain
|
|
|
|
|
unchanged.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
x(variable): The input tensor.
|
|
|
|
|
dropout_prob(float): Probability of setting units to zero.
|
|
|
|
|
is_test(bool): A flag indicating whether it is in test phrase or not.
|
|
|
|
|
seed(int): A Python integer used to create random seeds. If this
|
|
|
|
|
parameter is set to None, a random seed is used.
|
|
|
|
|
NOTE: If an integer seed is given, always the same output
|
|
|
|
|
units will be dropped. DO NOT use a fixed seed in training.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
Variable: A tensor variable.
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
x = fluid.layers.data(name="data", shape=[32, 32], dtype="float32")
|
|
|
|
|
droped = fluid.layers.dropout(input=x, dropout_rate=0.5)
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
helper = LayerHelper('dropout', **kwargs)
|
|
|
|
|
out = helper.create_tmp_variable(dtype=x.dtype)
|
|
|
|
|
mask = helper.create_tmp_variable(dtype=x.dtype, stop_gradient=True)
|
|
|
|
@ -856,9 +884,12 @@ def dropout(x, dropout_prob, is_test=False, seed=0, **kwargs):
|
|
|
|
|
inputs={'X': [x]},
|
|
|
|
|
outputs={'Out': [out],
|
|
|
|
|
'Mask': [mask]},
|
|
|
|
|
attrs={'dropout_prob': dropout_prob,
|
|
|
|
|
'is_test': is_test,
|
|
|
|
|
'seed': seed})
|
|
|
|
|
attrs={
|
|
|
|
|
'dropout_prob': dropout_prob,
|
|
|
|
|
'is_test': is_test,
|
|
|
|
|
'fix_seed': seed is not None,
|
|
|
|
|
'seed': seed if seed is not None else 0
|
|
|
|
|
})
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|