Dropout#
- class serket.nn.Dropout(drop_rate=0.5, drop_axes=None)[source]#
Drop some elements of the input array.
Randomly zeroes some of the elements of the input array with probability
drop_rateusing samples from a Bernoulli distribution.- Parameters:
drop_rate (
float) â probability of an element to be zeroed. Default: 0.5drop_axes (
Optional[tuple[int,...]]) â axes to apply dropout. Default: None to apply to all axes.
Example
>>> import serket as sk >>> import jax.numpy as jnp >>> import jax.random as jr >>> layer = sk.nn.Dropout(0.5) >>> input = jnp.ones(10) >>> key = jr.key(0) >>> output = layer(input, key=key)
Note
Use
tree_eval()to turn off dropout during evaluation by converting dropout toIdentity.>>> import serket as sk >>> import jax.random as jr >>> class Model(sk.TreeClass): ... def __init__(self, rate): ... self.dropout = sk.nn.Dropout(rate) >>> model = Model(rate=0.5) >>> sk.tree_eval(model) Model(dropout=Identity())
-
drop_rate:
float# - Field Information:
Name:
drop_rateDefault:0.5- Callbacks:
On setting attribute:
IsInstance(klass=<class 'float'>)Range(min_val=0, max_val=1, min_inclusive=True, max_inclusive=True)
On getting attribute:
<bound method Primitive.bind of stop_gradient>
-
drop_axes:
tuple[int,...] |None# Field Information: Name:
drop_axesDefault:None
- class serket.nn.Dropout1D(drop_rate=0.5)[source]#
Drops full feature maps along the channel axis.
- Parameters:
drop_rate (
float) â fraction of an elements to be zeroed out.
Example
>>> import serket as sk >>> import jax.numpy as jnp >>> import jax.random as jr >>> layer = sk.nn.Dropout1D(0.5) >>> input = jnp.ones((1, 10)) >>> key = jr.key(0) >>> output = layer(input, key=key)
Note
Use
tree_eval()to turn off dropout during evaluation by converting dropout toIdentity.>>> import serket as sk >>> class Model(sk.TreeClass): ... def __init__(self, rate): ... self.dropout = sk.nn.Dropout1D(rate) >>> model = Model(rate=0.5) >>> sk.tree_eval(model) Model(dropout=Identity())
- Reference:
- __call__(input, *, key=None)#
Drop some elements of the input array.
- Parameters:
input (
Array) â input arraykey (
Optional[Array]) â random number generator key
- Return type:
Array
-
drop_rate:
float# - Field Information:
Name:
drop_rateDefault:0.5- Callbacks:
On setting attribute:
IsInstance(klass=<class 'float'>)Range(min_val=0, max_val=1, min_inclusive=True, max_inclusive=True)
On getting attribute:
<function stop_gradient at 0x7fbdd970f880>
- class serket.nn.Dropout2D(drop_rate=0.5)[source]#
Drops full feature maps along the channel axis.
- Parameters:
drop_rate (
float) â fraction of an elements to be zeroed out.
Example
>>> import serket as sk >>> import jax.numpy as jnp >>> import jax.random as jr >>> layer = sk.nn.Dropout2D(0.5) >>> input = jnp.ones((1, 5, 5)) >>> key = jr.key(0) >>> output = layer(input, key=key)
Note
Use
tree_eval()to turn off dropout during evaluation by converting dropout toIdentity.>>> import serket as sk >>> class Model(sk.TreeClass): ... def __init__(self, rate): ... self.dropout = sk.nn.Dropout2D(rate) >>> model = Model(rate=0.5) >>> sk.tree_eval(model) Model(dropout=Identity())
- Reference:
- __call__(input, *, key=None)#
Drop some elements of the input array.
- Parameters:
input (
Array) â input arraykey (
Optional[Array]) â random number generator key
- Return type:
Array
-
drop_rate:
float# - Field Information:
Name:
drop_rateDefault:0.5- Callbacks:
On setting attribute:
IsInstance(klass=<class 'float'>)Range(min_val=0, max_val=1, min_inclusive=True, max_inclusive=True)
On getting attribute:
<function stop_gradient at 0x7fbdd970f880>
- class serket.nn.Dropout3D(drop_rate=0.5)[source]#
Drops full feature maps along the channel axis.
- Parameters:
drop_rate (
float) â fraction of an elements to be zeroed out.
Example
>>> import serket as sk >>> import jax.numpy as jnp >>> import jax.random as jr >>> layer = sk.nn.Dropout3D(0.5) >>> input = jnp.ones((1, 2, 2, 2)) >>> key = jr.key(0) >>> output = layer(input, key=key)
Note
Use
tree_eval()to turn off dropout during evaluation by converting dropout toIdentity.>>> import serket as sk >>> class Model(sk.TreeClass): ... def __init__(self, rate): ... self.dropout = sk.nn.Dropout3D(rate) >>> model = Model(rate=0.5) >>> sk.tree_eval(model) Model(dropout=Identity())
- Reference:
- __call__(input, *, key=None)#
Drop some elements of the input array.
- Parameters:
input (
Array) â input arraykey (
Optional[Array]) â random number generator key
- Return type:
Array
-
drop_rate:
float# - Field Information:
Name:
drop_rateDefault:0.5- Callbacks:
On setting attribute:
IsInstance(klass=<class 'float'>)Range(min_val=0, max_val=1, min_inclusive=True, max_inclusive=True)
On getting attribute:
<function stop_gradient at 0x7fbdd970f880>
- class serket.nn.RandomCutout1D(shape, cutout_count=1, fill_value=0)[source]#
Random Cutouts for spatial 1D input.
- Parameters:
shape (
int|tuple[int]) â shape of the cutout. accepts an int or a tuple of int.cutout_count (
int) â number of holes. Defaults to 1.fill_value (
int|float) âfill_valueto fill the cutout region. Defaults to 0.
Note
Use
tree_eval()to turn off the cutout during evaluation.Examples
>>> import jax.numpy as jnp >>> import serket as sk >>> import jax.random as jr >>> layer = sk.nn.RandomCutout1D(5) >>> input = jnp.ones((1, 10)) * 100 >>> key = jr.key(0) >>> output = layer(input, key=key)
- Reference:
- __call__(input, *, key=None)#
Drop some elements of the input array.
- Parameters:
x â input array
key (
Optional[Array]) â random number generator keyinput (
Array)
- Return type:
Array
- class serket.nn.RandomCutout2D(shape, cutout_count=1, fill_value=0)[source]#
Random Cutouts for spatial 2D input
- Parameters:
shape (
int|tuple[int]) â shape of the cutout. accepts int or a two element tuple.cutout_count (
int) â number of holes. Defaults to 1.fill_value (
int|float) âfill_valueto fill the cutout region. Defaults to 0.
Note
Use
tree_eval()to turn off the cutout during evaluation.Examples
>>> import serket as sk >>> import jax.numpy as jnp >>> import jax.random as jr >>> layer = sk.nn.RandomCutout2D(shape=(3,2), cutout_count=2, fill_value=0) >>> input = jnp.arange(1,101).reshape(1, 10, 10) >>> key = jr.key(0) >>> output = layer(input, key=key)
- Reference:
- __call__(input, *, key=None)#
Drop some elements of the input array.
- Parameters:
x â input array
key (
Optional[Array]) â random number generator keyinput (
Array)
- Return type:
Array
- class serket.nn.RandomCutout3D(shape, cutout_count=1, fill_value=0)[source]#
Random Cutouts for spatial 2D input
- Parameters:
shape (
int|tuple[int]) â shape of the cutout. accepts int or a three element tuple.cutout_count (
int) â number of holes. Defaults to 1.fill_value (
int|float) âfill_valueto fill the cutout region. Defaults to 0.
Note
Use
tree_eval()to turn off the cutout during evaluation.Examples
>>> import serket as sk >>> import jax.numpy as jnp >>> import jax.random as jr >>> layer = sk.nn.RandomCutout3D(shape=(2, 2, 2), cutout_count=2, fill_value=0) >>> input = jnp.arange(1, 2 * 5 * 5 + 1).reshape(1, 2, 5, 5) >>> key = jr.key(0) >>> output = layer(input, key=key)
- Reference:
- __call__(input, *, key=None)#
Drop some elements of the input array.
- Parameters:
x â input array
key (
Optional[Array]) â random number generator keyinput (
Array)
- Return type:
Array
- serket.nn.dropout_nd(key, input, drop_rate, drop_axes=None)[source]#
Drop some elements of the input array.
- Parameters:
key (
Array) â random number generator keyinput (
Array) â input arraydrop_rate (
float) â probability of an element to be zeroed.drop_axes (
Optional[tuple[int,...]]) â axes to apply dropout. Default: None to apply to all axes.
- Return type:
Array
- serket.nn.random_cutout_nd(key, input, shape, cutout_count, fill_value)[source]#
Randomly cutout a region of the input array.
- Parameters:
key (
Array) â random number generator keyinput (
Array) â input arrayshape (
tuple[int,...]) â shape of the cutout region. acecepts a tuple of int.cutout_count (
int) â number of holes.fill_value (
int|float) â fill_value to fill.