class_docstr: Implement the local spatial smoothing defence approach in TensorFlow v2.
  
  | 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: "tf.Tensor", y: Optional["tf.Tensor"] = None
  ) -> Tuple["tf.Tensor", Optional["tf.Tensor"]]:
      """
      Apply local spatial smoothing to sample `x`.
      """
      import tensorflow as tf
      import tensorflow_addons as tfa
  
      x_ndim = x.ndim
  
      if x_ndim == 4:
          x_nhwc = x
      elif x_ndim == 5:
          # NFHWC --> NHWC
          nb_clips, clip_size, height, width, channels = x.shape
          x_nhwc = tf.reshape(
              x, (nb_clips * clip_size, height, width, channels)
          )
      else:
          raise ValueError(
              "Unrecognized input dimension. Spatial smoothing can only be applied to image (NHWC) and video (NFHWC) "
              "data."
          )
  
      x_nhwc = tfa.image.median_filter2d(
          x_nhwc,
          filter_shape=[self.window_size, self.window_size],
          padding="REFLECT",
          constant_values=0,
          name=None,
      )
  
      if x_ndim == 4:
          x = x_nhwc
      elif x_ndim == 5:
          # NFHWC <-- NHWC
          x = tf.reshape(
              x_nhwc, (nb_clips, clip_size, height, width, channels)
          )
  
      if self.clip_values is not None:
          x = x.clip_by_value(
              min=self.clip_values[0], max=self.clip_values[1]
          )
  
      return x, y
  
file_path: adversarial-robustness-toolbox/art/defences/preprocessor/spatial_smoothing_tensorflow.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 PreprocessorTensorFlowV2
label_desc: Use image node_id 2 for calling the SpatialSmoothingTensorFlowV2 obj's underlying member method code with example usage: obj.forward(x, y) and returns: x,  y