instance_norm#

ivy.instance_norm(x, mean, variance, /, *, offset=None, scale=None, training=False, eps=0.0, momentum=0.1, data_format='NSC', out=None)[source]#

Apply instance normalization to the input array and returns the normalized input, running mean and running variance arrays as output. If training == False, the mean and variance arrays passed as input are used for normalization and the same arrays are returned as running mean and running variance respectively. However, when training ==True, this function computes the mean and variance across the spatial dimensions which is then used for normalization.In this case, the function returns the running mean and running variance calculated using the following formula:

running_mean = (1 - momentum) * running_mean + momentum * batch_mean running_var = (1 - momentum) * running_var + momentum * frac{n}{n-1} * batch_var

Parameters:
  • x (Union[NativeArray, Array]) –

    Input array of default shape (N, *S, C), where N is the batch dimension, *S corresponds to any number of spatial dimensions and

    C corresponds to the channel dimension.

  • mean (Union[NativeArray, Array]) – Mean array of size C used for input’s normalization.

  • variance (Union[NativeArray, Array]) – Variance array of size C used for input’s normalization.

  • offset (Optional[Union[Array, NativeArray]], default: None) – An offset array of size C. If present, will be added to the normalized input.

  • scale (Optional[Union[Array, NativeArray]], default: None) – A scale array of size C. If present, the scale is applied to the normalized input.

  • training (Optional[bool], default: False) – If true, calculate and use the mean and variance of x. Otherwise, use the provided mean and variance.

  • eps (Optional[float], default: 0.0) – A small float number to avoid dividing by 0.

  • momentum (Optional[float], default: 0.1) –

    the value used for the running_mean and running_var computation.

    Default value is 0.1.

  • data_format (Optional[str], default: 'NSC') – The ordering of the dimensions in the input, one of “NSC” or “NCS”, where N is the batch dimension, S represents any number of spatial dimensions and C is the channel dimension. Default is “NSC”.

  • out (Optional[Tuple[Array, Array, Array]], default: None) – optional output arrays, for writing the result to.

Return type:

Tuple[Array, Array, Array]

Returns:

ret

Tuple of arrays containing

the normalized input, running_mean, and running_variance.

Array.instance_norm(self, mean, variance, /, *, offset=None, scale=None, training=False, eps=1e-05, momentum=0.1, data_format='NSC', out=None)[source]#

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

Parameters:
  • self (Union[NativeArray, Array]) –

    Input array of shape default (N, *S, C), where N is the batch dimension, *S corresponds to any number of spatial dimensions and

    C corresponds to the channel dimension.

  • mean (Union[NativeArray, Array]) – Mean array of size C used for input’s normalization.

  • variance (Union[NativeArray, Array]) – Variance array of size C used for input’s normalization.

  • offset (Optional[Union[Array, NativeArray]], default: None) – An offset array of size C. If present, will be added to the normalized input.

  • scale (Optional[Union[Array, NativeArray]], default: None) – A scale array of size C. If present, the scale is applied to the normalized input.

  • training (bool, default: False) – If true, calculate and use the mean and variance of x. Otherwise, use the provided mean and variance.

  • eps (float, default: 1e-05) – A small float number to avoid dividing by 0.

  • momentum (float, default: 0.1) –

    the value used for the running_mean and running_var computation.

    Default value is 0.1.

  • data_format (str, default: 'NSC') – The ordering of the dimensions in the input, one of “NSC” or “NCS”, where N is the batch dimension, S represents any number of spatial dimensions and C is the channel dimension. Default is “NSC”.

  • out (Optional[Tuple[Array, Array, Array]], default: None) – optional output array, for writing the result to.

Return type:

Tuple[Array, Array, Array]

Returns:

ret

Tuple of array containing

the normalized input, running mean, and running variance.

Container.instance_norm(self, mean, variance, /, *, offset=None, scale=None, training=False, eps=1e-05, momentum=0.1, data_format='NSC', out=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#

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

Parameters:
  • self (Union[Array, NativeArray, Container]) –

    Input array of shape default (N, *S, C), where N is the batch dimension, *S corresponds to any number of spatial dimensions and

    C corresponds to the channel dimension.

  • mean (Union[NativeArray, Array, Container]) – Mean array of size C used for input’s normalization.

  • variance (Union[NativeArray, Array, Container]) – Variance array of size C used for input’s normalization.

  • offset (Optional[Union[Array, NativeArray, Container]], default: None) – An offset array of size C. If present, will be added to the normalized input.

  • scale (Optional[Union[Array, NativeArray, Container]], default: None) – A scale array of size C. If present, the scale is applied to the normalized input.

  • training (Union[bool, Container], default: False) – If true, calculate and use the mean and variance of x. Otherwise, use the provided mean and variance.

  • eps (Union[float, Container], default: 1e-05) – A small float number to avoid dividing by 0.

  • momentum (Union[float, Container], default: 0.1) –

    the value used for the running_mean and running_var computation.

    Default value is 0.1.

  • data_format (Union[str, Container], default: 'NSC') – The ordering of the dimensions in the input, one of “NSC” or “NCS”, where N is the batch dimension, S represents any number of spatial dimensions and C is the channel dimension. Default is “NSC”.

  • out (Optional[Tuple[Union[Array, Container], Union[Array, Container], Union[Array, Container]]], default: None) – optional output arrays, for writing the result to.

  • 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.

Return type:

Tuple[Container, Container, Container]

Returns:

ret

Tuple of containers containing

the normalized input, running mean, and running variance.