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, default: True) – controls whether dropout1d is performed during training or ignored during testing.

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

  • out (Optional[Array], default: None) – optional output array, for writing the result to. 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)[source]#

ivy.Array 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 (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, default: True) – Turn on dropout if training, turn off otherwise. Default is True.

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

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have 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)[source]#

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 (Union[float, Container]) – The probability of zeroing out each array element, float between 0 and 1.

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

  • data_format (Union[str, Container], default: 'NWC') – “NWC” or “NCW”. Default is "NCW".

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

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

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

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

  • out (Optional[Container], default: None) – optional output array, for writing the result to. It must have a shape 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.]]])
}