dropout2d#

ivy.dropout2d(x, prob, /, *, training=True, data_format='NHWC', 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, dropout2d performs a channel-wise dropout but assumes a channel is a 2D feature map.

Parameters:
  • x (Union[Array, NativeArray]) – a 3D or 4D 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 dropout2d is performed during training or ignored during testing.

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

  • 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]])
>>> y = ivy.dropout2d(x, 0.5)
>>> print(y)
ivy.array([[0., 2., 2.]])
>>> x = ivy.array([[1, 1, 1]])
>>> y = ivy.dropout2d(x, 1, training=False, data_format="NCW")
>>> print(y)
ivy.array([[1, 1, 1]])
Array.dropout2d(self, prob, /, *, training=True, data_format='NHWC', out=None)[source]#

ivy.Array instance method variant of ivy.dropout2d. 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: 'NHWC') – “NHWC” or “NCHW”. Default is "NHWC".

  • 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], [2, 2, 2]])
>>> y = x.dropout2d(0.5)
>>> print(y)
ivy.array([[0., 0., 2.],
       [4., 4., 4.]])
Container.dropout2d(self, prob, /, *, training=True, data_format='NHWC', key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

ivy.Container instance method variant of ivy.dropout2d. This method simply wraps the function, and so the docstring for ivy.dropout2d 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: 'NHWC') – “NHWC” or “NCHW”. Default is "NHWC".

  • 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([[100, 200, 300]]),
...                   b=ivy.array([[400, 500, 600]]))
>>> y = x.dropout2d(0.5)
>>> print(y)
{
    a: ivy.array([[200., 0., 600.]]),
    b: ivy.array([[0., 0., 0.]])
}