code: def _aspect_preserving_resize(image, smallest_side):
      """Resize images preserving the original aspect ratio.
  
      Args:
        image: A 3-D image or a 4-D batch of images `Tensor`.
        smallest_side: A python integer or scalar `Tensor` indicating the size of
          the smallest side after resize.
  
      Returns:
        resized_image: A 3-D or 4-D tensor containing the resized image(s).
      """
      smallest_side = tf.convert_to_tensor(
          smallest_side, dtype=tf.int32
      )
  
      input_rank = len(image.shape)
      if input_rank == 3:
          image = tf.expand_dims(image, 0)
  
      shape = tf.shape(image)
      height = shape[1]
      width = shape[2]
      new_height, new_width = _smallest_size_at_least(
          height, width, smallest_side
      )
      resized_image = tf.image.resize_bilinear(
          image, [new_height, new_width], align_corners=False
      )
      if input_rank == 3:
          resized_image = tf.squeeze(resized_image)
          resized_image.set_shape([None, None, 3])
      else:
          resized_image.set_shape([None, None, None, 3])
      return resized_image
  
imports: import io
  import os
  import tempfile
  from magenta.models.image_stylization import imagenet_data
  import numpy
  import skimage.io
  import tensorflow.compat.v1
label_desc: Use image node_id 13 for calling a global function with example usage: _aspect_preserving_resize(image, smallest_side) and returns: resized_image