class_docstr: This module implements EoT of changes in contrast with uniformly sampled factor.
docstr: Transformation of an image with randomly sampled contrast.
  
  :param x: Input samples.
  :param y: Label of the samples `x`.
  :return: Transformed samples and labels.
code: def _transform(
      self,
      x: "torch.Tensor",
      y: Optional[
          Union["torch.Tensor", List[Dict[str, "torch.Tensor"]]]
      ],
      **kwargs,
  ) -> Tuple[
      "torch.Tensor",
      Optional[Union["torch.Tensor", List[Dict[str, "torch.Tensor"]]]],
  ]:
      """
      Transformation of an image with randomly sampled contrast.
  
      :param x: Input samples.
      :param y: Label of the samples `x`.
      :return: Transformed samples and labels.
      """
      import torch
  
      contrast_factor_i = np.random.uniform(
          low=self.contrast_factor_range[0],
          high=self.contrast_factor_range[1],
      )
      if x.shape[3] == 3:
          red, green, blue = x[:, :, :, 0], x[:, :, :, 1], x[:, :, :, 2]
          x_gray = 0.2989 * red + 0.587 * green + 0.114 * blue
      elif x.shape[3] == 1:
          x_gray = x[:, :, :, 0]
      else:  # pragma: no cover
          raise ValueError(
              "Number of color channels is not 1 or 3 in input `x` of format HWC."
          )
      mean = torch.mean(x_gray, dim=(-2, -1), keepdim=True)
  
      return (
          torch.clamp(
              contrast_factor_i * x + (1.0 - contrast_factor_i) * mean,
              min=self.clip_values[0],
              max=self.clip_values[1],
          ),
          y,
      )
  
file_path: adversarial-robustness-toolbox/art/preprocessing/expectation_over_transformation/natural_corruptions/contrast/pytorch.py
imports: import logging
  from typing import Dict, List, Union, Tuple, TYPE_CHECKING, Optional
  import numpy
  from art.preprocessing.expectation_over_transformation.pytorch import EoTPyTorch
label_desc: Use image node_id 2 for calling the EoTContrastPyTorch obj's underlying member method code with example usage: obj._transform(x, y) and returns: torch,  y