class_docstr: ## Instance Normalization Layer
  
  Instance normalization layer $\text{IN}$ normalizes the input $X$ as follows:
  
  When input $X \in \mathbb{R}^{B \times C \times H \times W}$ is a batch of image representations,
  where $B$ is the batch size, $C$ is the number of channels, $H$ is the height and $W$ is the width.
  $\gamma \in \mathbb{R}^{C}$ and $\beta \in \mathbb{R}^{C}$. The affine transformation with $gamma$ and
  $beta$ are optional.
  
  $$\text{IN}(X) = \gamma
  \frac{X - \underset{H, W}{\mathbb{E}}[X]}{\sqrt{\underset{H, W}{Var}[X] + \epsilon}}
  + \beta$$
docstr: * `channels` is the number of features in the input
  * `eps` is $\epsilon$, used in $\sqrt{Var[X] + \epsilon}$ for numerical stability
  * `affine` is whether to scale and shift the normalized value
docstr_tok: ["*","`","channels","`","is","the","number","of","features","in","the","input","*","`","eps","`","is","$","\\epsilon","$",",","used","in","$","\\sqrt","{","Var","[","X","]","+","\\epsilon","}","$","for","numerical","stability","*","`","affine","`","is","whether","to","scale","and","shift","the","normalized","value"]
code: def __init__(
      self, channels: int, *, eps: float = 1e-5, affine: bool = True
  ):
      """
      * `channels` is the number of features in the input
      * `eps` is $\epsilon$, used in $\sqrt{Var[X] + \epsilon}$ for numerical stability
      * `affine` is whether to scale and shift the normalized value
      """
      super().__init__()
  
      self.channels = channels
  
      self.eps = eps
      self.affine = affine
      # Create parameters for $\gamma$ and $\beta$ for scale and shift
      if self.affine:
          self.scale = nn.Parameter(torch.ones(channels))
          self.shift = nn.Parameter(torch.zeros(channels))
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/normalization/instance_norm/__init__.py
imports: import torch
  from torch import nn
  from labml_helpers.module import Module
label_desc: Use image node_id 1 to create a new InstanceNorm object from inherited base classes: Module with example: obj = InstanceNorm(channels)