chainer.functions.dropout¶
-
chainer.functions.
dropout
(x, ratio=.5)[source]¶ Drops elements of input variable randomly.
This function drops input elements randomly with probability
ratio
and scales the remaining elements by factor1 / (1 - ratio)
. In testing mode, it does nothing and just returnsx
.Warning
train
argument is not supported anymore since v2. Instead, usechainer.using_config('train', boolean)
. Seechainer.using_config()
.Parameters: - x (
Variable
ornumpy.ndarray
orcupy.ndarray
) – Input variable. A \((s_1, s_2, ..., s_N)\) -shaped float array. - ratio (float) – Dropout ratio. The
ratio
must be0.0 <= ratio < 1.0
.
Returns: Output variable.
Return type: See the paper by G. Hinton: Improving neural networks by preventing co-adaptation of feature detectors.
Example
>>> x = np.array([[-1, 0], [2, -3], [-2, 1]], 'f') >>> with chainer.using_config('train', True): ... y = F.dropout(x) >>> y.data array([[-2., 0.], [ 4., -6.], [-0., 2.]], dtype=float32) >>> with chainer.using_config('train', True): ... y = F.dropout(x, ratio=0.0) # dropout returns original input if ratio=0.0 >>> (x == y.data).all() True >>> with chainer.using_config('train', False): ... y = F.dropout(x) # dropout in test mode returns original input >>> (x == y.data).all() True
- x (