dropout1d#

ivy.dropout1d(x, prob, /, *, training=True, data_format='NWC', out=None)[source]#

Randomly zero out entire channels with probability prob using samples from a Bernoulli distribution and the remaining channels are scaled by (1/1-prob). In this case, dropout1d performs a channel-wise dropout but assumes a channel is a 1D feature map.

Parameters:
  • x (Union[Array, NativeArray]) – a 2D or 3D input array. Should have a floating-point data type.

  • prob (float) – probability of a channel to be zero-ed.

  • training (bool) – controls whether dropout1d is performed during training or ignored (default: True) during testing.

  • data_format (str) – “NWC” or “NCW”. Defaults to “NWC”. (default: 'NWC')

  • out (Optional[Array]) – optional output array, for writing the result to. (default: None) It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

  • ret

    an array with some channels zero-ed and the rest of channels are

    scaled by (1/1-prob).

  • Both the description and the type hints above assumes an array input for simplicity,

  • but this function is nestable, and therefore also accepts ivy.Container

  • instances in place of any of the arguments.

Examples

With ivy.Array input:

>>> x = ivy.array([1, 1, 1]).reshape([1, 1, 3])
>>> y = ivy.dropout1d(x, 0.5)
>>> print(y)
ivy.array([[[2., 0, 2.]]])
>>> x = ivy.array([1, 1, 1]).reshape([1, 1, 3])
>>> y = ivy.dropout1d(x, 1, training=False, data_format="NCW")
>>> print(y)
ivy.array([[[1, 1, 1]]])

With one ivy.Container input: >>> x = ivy.Container(a=ivy.array([100, 200, 300]).reshape([1, 1, 3]), … b=ivy.array([400, 500, 600]).reshape([1, 1, 3])) >>> y = ivy.dropout1d(x, 0.5) >>> print(y) { a: ivy.array([[[200., 400., 0.]]]), b: ivy.array([[[0., 0., 0.]]]) }

Array.dropout1d(self, prob, /, *, training=True, data_format='NWC', out=None)#

ivy.Array instance method variant of ivy.dropout1d. This method simply wraps the function, and so the docstring for ivy.droput1d also applies to this method with minimal changes.

Parameters:
  • self (Array) – The input array x to perform dropout on.

  • prob (float) – The probability of zeroing out each array element, float between 0 and 1.

  • training (bool) – Turn on dropout if training, turn off otherwise. Default is True. (default: True)

  • data_format (str) – “NWC” or “NCW”. Default is "NCW". (default: 'NWC')

  • out (Optional[Array]) – optional output array, for writing the result to. It must have (default: None) a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – Result array of the output after dropout is performed.

Examples

>>> x = ivy.array([1, 1, 1]).reshape([1, 1, 3])
>>> y = x.dropout1d(0.5)
>>> print(y)
ivy.array([[[2., 0, 2.]]])
Container.dropout1d(self, prob, /, *, training=True, data_format='NWC', key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)#

ivy.Container instance method variant of ivy.dropout1d. This method simply wraps the function, and so the docstring for ivy.dropout1d also applies to this method with minimal changes.

Parameters:
  • self (Container) – The input container to perform dropout on.

  • prob (float) – The probability of zeroing out each array element, float between 0 and 1.

  • training (bool) – Turn on dropout if training, turn off otherwise. Default is True. (default: True)

  • data_format (str) – “NWC” or “NCW”. Default is "NCW". (default: 'NWC')

  • key_chains (Optional[Union[List[str], Dict[str, str]]]) – The key-chains to apply or not apply the method to. Default is None. (default: None)

  • to_apply (bool) – If True, the method will be applied to key_chains, otherwise key_chains (default: True) will be skipped. Default is True.

  • prune_unapplied (bool) – Whether to prune key_chains for which the function was not applied. (default: False) Default is False.

  • map_sequences (bool) – Whether to also map method to sequences (lists, tuples). (default: False) Default is False.

  • out (Optional[Container]) – optional output array, for writing the result to. It must have a shape (default: None) that the inputs broadcast to.

Return type:

Container

Returns:

ret – Result container of the output after dropout is performed.

Examples

>>> x = ivy.Container(a=ivy.array([1, 2, 3]).reshape([1, 1, 3]),
...                   b=ivy.array([4, 5, 6]).reshape([1, 1, 3]))
>>> y = x.dropout1d(x, 0.5)
>>> print(y)
{
    a: ivy.array([[[0., 4., 0.]]]),
    b: ivy.array([[[0., 0., 12.]]])
}