code: def fft2(
      x: Union[tf.Tensor, tf.Variable],
      *,
      s: Optional[Sequence[int]] = None,
      dim: Sequence[int] = (-2, -1),
      norm: str = "backward",
      out: Optional[Union[tf.Tensor, tf.Variable]] = None,
  ) -> Union[tf.Tensor, tf.Variable]:
      if s is None:
          s = (x.shape[dim[0]], x.shape[dim[1]])
      if len(x.shape) > 2:
          result = _fft2_helper(x, s, dim)
      else:
          x_new = trans_x_to_s(x, s, dim)
          x_complex = tf.cast(x_new, tf.complex128)
          result = tf.signal.fft2d(x_complex)
  
      result = _fft2_norm(result, s, dim, norm)
      if x.dtype == tf.complex64:
          result = tf.cast(result, dtype=tf.complex128)
      return result
  
imports: import math
  from typing import Union, Optional, Tuple, List, Literal, Sequence, Callable
  import tensorflow
  from ivy.func_wrapper import inputs_to_ivy_arrays, output_to_native_arrays, with_unsupported_dtypes, with_supported_dtypes, with_supported_device_and_dtypes
  from ..None import backend_version
  import ivy
  from ivy.functional.ivy.layers import _handle_padding, _get_num_padded_values, _validate_max_pool_params, _depth_max_pooling_helper
  from ivy.functional.ivy.experimental.layers import _padding_ceil_mode, _get_size
label_desc: Use image node_id 26 for calling a global function with example usage: fft2(x) and returns: result