class_docstr: Implement the local spatial smoothing defence approach in PyTorch.
  
  | Paper link: https://arxiv.org/abs/1704.01155
  
  | Please keep in mind the limitations of defences. For more information on the limitations of this defence,
      see https://arxiv.org/abs/1803.09868 . For details on how to evaluate classifier security in general, see
      https://arxiv.org/abs/1902.06705
docstr: Apply local spatial smoothing to sample `x`.
code: def forward(
      self, x: "torch.Tensor", y: Optional["torch.Tensor"] = None
  ) -> Tuple["torch.Tensor", Optional["torch.Tensor"]]:
      """
      Apply local spatial smoothing to sample `x`.
      """
      import torch
  
      x_ndim = x.ndim
  
      # NHWC/NCFHW/NFHWC --> NCHW.
      if x_ndim == 4:
          if self.channels_first:
              x_nchw = x
          else:
              # NHWC --> NCHW
              x_nchw = x.permute(0, 3, 1, 2)
      elif x_ndim == 5:
          if self.channels_first:
              # NCFHW --> NFCHW --> NCHW
              nb_clips, channels, clip_size, height, width = x.shape
              x_nchw = x.permute(0, 2, 1, 3, 4).reshape(
                  nb_clips * clip_size, channels, height, width
              )
          else:
              # NFHWC --> NHWC --> NCHW
              nb_clips, clip_size, height, width, channels = x.shape
              x_nchw = x.reshape(
                  nb_clips * clip_size, height, width, channels
              ).permute(0, 3, 1, 2)
      else:
          raise ValueError(
              "Unrecognized input dimension. Spatial smoothing can only be applied to image and video data."
          )
  
      x_nchw = self.median_blur(x_nchw)
  
      # NHWC/NCFHW/NFHWC <-- NCHW.
      if x_ndim == 4:
          if self.channels_first:
              x = x_nchw
          else:
              #   NHWC <-- NCHW
              x = x_nchw.permute(0, 2, 3, 1)
      elif x_ndim == 5:
          if self.channels_first:
              # NCFHW <-- NFCHW <-- NCHW
              x_nfchw = x_nchw.reshape(
                  nb_clips, clip_size, channels, height, width
              )
              x = x_nfchw.permute(0, 2, 1, 3, 4)
          else:
              # NFHWC <-- NHWC <-- NCHW
              x_nhwc = x_nchw.permute(0, 2, 3, 1)
              x = x_nhwc.reshape(
                  nb_clips, clip_size, height, width, channels
              )
  
      if self.clip_values is not None:
          x = x.clamp(
              min=torch.tensor(self.clip_values[0]),
              max=torch.tensor(self.clip_values[1]),
          )
  
      return x, y
  
file_path: adversarial-robustness-toolbox/art/defences/preprocessor/spatial_smoothing_pytorch.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import Optional, Tuple, TYPE_CHECKING
  import numpy
  from art.defences.preprocessor.preprocessor import PreprocessorPyTorch
label_desc: Use image node_id 2 for calling the SpatialSmoothingPyTorch obj's underlying member method code with example usage: obj.forward(x, y) and returns: x,  y