class_docstr: Apply global mean and variance normalization
  
  TODO(kamo): Make this class portable somehow
  
  Args:
      stats_file: npy file
      norm_means: Apply mean normalization
      norm_vars: Apply var normalization
      eps:
class_docstr_tok: ["Apply","global","mean","and","variance","normalization","TODO","(","kamo",")",":","Make","this","class","portable","somehow","Args",":","stats_file",":","npy","file","norm_means",":","Apply","mean","normalization","norm_vars",":","Apply","var","normalization","eps",":"]
code: def __init__(
      self,
      stats_file: Union[Path, str],
      norm_means: bool = True,
      norm_vars: bool = True,
      eps: float = 1.0e-20,
  ):
      assert check_argument_types()
      super().__init__()
      self.norm_means = norm_means
      self.norm_vars = norm_vars
      self.eps = eps
      stats_file = Path(stats_file)
  
      self.stats_file = stats_file
      stats = np.load(stats_file)
      if isinstance(stats, np.ndarray):
          # Kaldi like stats
          count = stats[0].flatten()[-1]
          mean = stats[0, :-1] / count
          var = stats[1, :-1] / count - mean * mean
      else:
          # New style: Npz file
          count = stats["count"]
          sum_v = stats["sum"]
          sum_square_v = stats["sum_square"]
          mean = sum_v / count
          var = sum_square_v / count - mean * mean
      std = np.sqrt(np.maximum(var, eps))
  
      if isinstance(mean, np.ndarray):
          mean = torch.from_numpy(mean)
      else:
          mean = torch.tensor(mean).float()
      if isinstance(std, np.ndarray):
          std = torch.from_numpy(std)
      else:
          std = torch.tensor(std).float()
  
      self.register_buffer("mean", mean)
      self.register_buffer("std", std)
  
file_path: espnet/espnet2/layers/global_mvn.py
imports: from pathlib import Path
  from typing import Tuple, Union
  import numpy
  import torch
  from typeguard import check_argument_types
  from espnet2.layers.abs_normalize import AbsNormalize
  from espnet2.layers.inversible_interface import InversibleInterface
  from espnet.nets.pytorch_backend.nets_utils import make_pad_mask
label_desc: Use image node_id 1 to create a new GlobalMVN object from inherited base classes: AbsNormalize, InversibleInterface with example: obj = GlobalMVN(stats_file, norm_means, norm_vars, eps)