code: def vqa_v2_preprocess_image(
      image,
      height,
      width,
      mode,
      resize_side=512,
      distort=True,
      image_model_fn="resnet_v1_152",
  ):
      """vqa v2 preprocess image."""
  
      image = tf.image.convert_image_dtype(image, dtype=tf.float32)
      assert resize_side > 0
      if resize_side:
          image = _aspect_preserving_resize(image, resize_side)
      if mode == tf_estimator.ModeKeys.TRAIN:
          image = tf.random_crop(image, [height, width, 3])
      else:
          # Central crop, assuming resize_height > height, resize_width > width.
          image = tf.image.resize_image_with_crop_or_pad(
              image, height, width
          )
  
      image = tf.clip_by_value(image, 0.0, 1.0)
  
      if mode == tf_estimator.ModeKeys.TRAIN and distort:
          image = _flip(image)
          num_distort_cases = 4
          # pylint: disable=unnecessary-lambda
          image = _apply_with_random_selector(
              image,
              lambda x, ordering: _distort_color(x, ordering),
              num_cases=num_distort_cases,
          )
  
      if image_model_fn.startswith("resnet_v1"):
          # resnet_v1 uses vgg preprocessing
          image = image * 255.0
          image = _mean_image_subtraction(
              image, [_R_MEAN, _G_MEAN, _B_MEAN]
          )
      elif image_model_fn.startswith("resnet_v2"):
          # resnet v2 uses inception preprocessing
          image = tf.subtract(image, 0.5)
          image = tf.multiply(image, 2.0)
  
      return image
  
file_path: tensor2tensor/tensor2tensor/data_generators/vqa_utils.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
  from tensorflow.python.ops import control_flow_ops
label_desc: Use image node_id 7 for calling a global function with example usage: vqa_v2_preprocess_image(image, height, width, mode, resize_side, distort, image_model_fn) and returns: image