class_docstr: ## Channel Normalization
  
  This is similar to [Group Normalization](../group_norm/index.html) but affine transform is done group wise.
class_docstr_tok: ["#","#","Channel","Normalization","This","is","similar","to","[","Group","Normalization","]","(","..","\/group_norm\/index.html",")","but","affine","transform","is","done","group","wise","."]
docstr: * `groups` is the number of groups the features are divided into
  * `channels` is the number of features in the input
  * `eps` is $\epsilon$, used in $\sqrt{Var[x^{(k)}] + \epsilon}$ for numerical stability
  * `affine` is whether to scale and shift the normalized value
docstr_tok: ["*","`","groups","`","is","the","number","of","groups","the","features","are","divided","into","*","`","channels","`","is","the","number","of","features","in","the","input","*","`","eps","`","is","$","\\epsilon","$",",","used","in","$","\\sqrt","{","Var","[","x^","{","(","k",")","}","]","+","\\epsilon","}","$","for","numerical","stability","*","`","affine","`","is","whether","to","scale","and","shift","the","normalized","value"]
code: def __init__(
      self, channels, groups, eps: float = 1e-5, affine: bool = True
  ):
      """
      * `groups` is the number of groups the features are divided into
      * `channels` is the number of features in the input
      * `eps` is $\epsilon$, used in $\sqrt{Var[x^{(k)}] + \epsilon}$ for numerical stability
      * `affine` is whether to scale and shift the normalized value
      """
      super().__init__()
      self.channels = channels
      self.groups = groups
      self.eps = eps
      self.affine = affine
      # Parameters for affine transformation.
      #
      # *Note that these transforms are per group, unlike in group norm where
      # they are transformed channel-wise.*
      if self.affine:
          self.scale = nn.Parameter(torch.ones(groups))
          self.shift = nn.Parameter(torch.zeros(groups))
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/normalization/batch_channel_norm/__init__.py
imports: import torch
  from torch import nn
  from labml_helpers.module import Module
  from labml_nn.normalization.batch_norm import BatchNorm
label_desc: Use image node_id 1 to create a new ChannelNorm object from inherited base classes: Module with example: obj = ChannelNorm(channels, groups, eps, affine)