class_docstr: Compute the augmentation loss, as described in the
  `RangeAugment <https://arxiv.org/abs/2212.10553>`_ paper.
  
  Args:
      opts: command line arguments
class_docstr_tok: ["Compute","the","augmentation","loss",",","as","described","in","the","`","RangeAugment","<","https",":","\/\/arxiv.org\/abs\/2212.10553",">","`","_","paper",".","Args",":","opts",":","command","line","arguments"]
code: def __init__(self, opts: argparse.Namespace, *args, **kwargs) -> None:
      super().__init__(opts, *args, **kwargs)
  
      perceptual_metric = getattr(
          opts, "loss.neural_augmentation.perceptual_metric"
      )
      is_master_node = is_master(opts)
      if perceptual_metric is None and is_master_node:
          logger.error(
              "Perceptual metric can't be none. "
              "Please specify perceptual metric using --loss.auxiliary.neural-augmentation.perceptual-metric argument"
          )
      if not isinstance(perceptual_metric, str) and is_master_node:
          logger.error(
              "The type of perceptual metric is not string. Got: {}".format(
                  type(perceptual_metric)
              )
          )
      perceptual_metric = perceptual_metric.lower()
      target_value = getattr(
          opts, "loss.neural_augmentation.target_value"
      )
  
      self.curriculumn_learning = False
      self.iteration_based_training = getattr(
          opts, "scheduler.is_iteration_based", False
      )
      self.target_str = f"{target_value}"
      alpha = getattr(opts, "loss.neural_augmentation.alpha")
      if perceptual_metric == "psnr":
          if target_value is None and is_master_node:
              logger.error("Target PSNR value can not be None.")
  
          if isinstance(target_value, (int, float)):
              if target_value < 0:
                  if is_master_node:
                      logger.error(
                          "PSNR value should be >= 0 in {}. Got: {}".format(
                              self.__class__.__name__, target_value
                          )
                      )
              # compute target MSE using below equation
              # # PSNR = 20 log10(255) - 10 log10(MSE)
              target_mse = 10.0 ** (
                  (20.0 * math.log10(255.0) - target_value) / 10.0
              )
              self.target_value = torch.ones(
                  size=(1,), dtype=torch.float
              ).fill_(target_mse)
              self.target_str = f"{target_value}"
          elif (
              isinstance(target_value, (list, tuple))
              and len(target_value) == 2
          ):
              start_target_value = target_value[0]
              end_target_value = target_value[1]
  
              if start_target_value < 0 or end_target_value < 0:
                  if is_master_node:
                      logger.error(
                          "PSNR value should be >= 0 in {}. Got: {}".format(
                              self.__class__.__name__, target_value
                          )
                      )
  
              # compute target MSE using below equation
              # # PSNR = 20 log10(255) - 10 log10(MSE)
              start_target_mse = 10.0 ** (
                  (20.0 * math.log10(255.0) - start_target_value) / 10.0
              )
              end_target_mse = 10.0 ** (
                  (20.0 * math.log10(255.0) - end_target_value) / 10.0
              )
  
              max_steps = (
                  getattr(opts, "scheduler.max_iterations")
                  if self.iteration_based_training
                  else getattr(opts, "scheduler.max_epochs")
              )
  
              if max_steps is None and is_master_node:
                  logger.error(
                      "Please specify {}. Got None.".format(
                          "--scheduler.max-iterations"
                          if self.iteration_based_training
                          else "--scheduler.max-epochs"
                      )
                  )
  
              curriculum_method = getattr(
                  opts, "loss.neural_augmentation.curriculum_method"
              )
              if curriculum_method in CURRICULUM_METHOD.keys():
                  self.target_value = CURRICULUM_METHOD[
                      curriculum_method
                  ](
                      start=start_target_mse,
                      end=end_target_mse,
                      period=max_steps,
                  )
              else:
                  raise NotImplementedError
  
              self.curriculumn_learning = True
              self.target_str = (
                  f"[{start_target_value}, {end_target_value}]"
              )
          else:
              raise NotImplementedError
  
          # the maximum possible MSE error is computed as:
          # a = torch.ones((3, H, W)) * 255.0 # Max. input value is 255.0
          # b = torch.zeros((3, H, W)) # min. input value is 0.0
          # mse = torch.mean( (a -b) ** 2)
          # 65025 is the maximum mse
          self.alpha = alpha / 65025.0
      else:
          if is_master_node:
              logger.error(
                  "Supported perceptual metrics are: {}. Got: {}".format(
                      self.__supported_metrics, perceptual_metric
                  )
              )
      self.perceptual_metric = perceptual_metric
      self.device = getattr(opts, "dev.device", torch.device("cpu"))
  
file_path: ml-cvnets/loss_fn/neural_augmentation.py
imports: import argparse
  import math
  from typing import List, Mapping, Union
  import torch
  from torch import Tensor
  from torch.nn import functional
  from loss_fn import LOSS_REGISTRY, BaseCriteria
  from utils import logger
  from utils.ddp_utils import is_master
label_desc: Use image node_id 1 to create a new NeuralAugmentation object from inherited base classes: BaseCriteria with example: obj = NeuralAugmentation(opts)