code: def distorted_bounding_box_crop(
      image_bytes,
      bbox,
      min_object_covered=0.1,
      aspect_ratio_range=(0.75, 1.33),
      area_range=(0.05, 1.0),
      max_attempts=100,
      scope=None,
  ):
      """Generates cropped_image using one of the bboxes randomly distorted.
  
      See `tf.image.sample_distorted_bounding_box` for more documentation.
  
      Args:
        image_bytes: `Tensor` of binary image data.
        bbox: `Tensor` of bounding boxes arranged `[1, num_boxes, coords]`
            where each coordinate is [0, 1) and the coordinates are arranged
            as `[ymin, xmin, ymax, xmax]`. If num_boxes is 0 then use the whole
            image.
        min_object_covered: An optional `float`. Defaults to `0.1`. The cropped
            area of the image must contain at least this fraction of any bounding
            box supplied.
        aspect_ratio_range: An optional list of `float`s. The cropped area of the
            image must have an aspect ratio = width / height within this range.
        area_range: An optional list of `float`s. The cropped area of the image
            must contain a fraction of the supplied image within in this range.
        max_attempts: An optional `int`. Number of attempts at generating a cropped
            region of the image of the specified constraints. After `max_attempts`
            failures, return the entire image.
        scope: Optional `str` for name scope.
      Returns:
        cropped image `Tensor`
      """
      with tf.name_scope(
          scope, "distorted_bounding_box_crop", [image_bytes, bbox]
      ):
          shape = tf.image.extract_jpeg_shape(image_bytes)
          sample_distorted_bounding_box = (
              tf.image.sample_distorted_bounding_box(
                  shape,
                  bounding_boxes=bbox,
                  min_object_covered=min_object_covered,
                  aspect_ratio_range=aspect_ratio_range,
                  area_range=area_range,
                  max_attempts=max_attempts,
                  use_image_if_no_bounding_boxes=True,
              )
          )
          bbox_begin, bbox_size, _ = sample_distorted_bounding_box
  
          # Crop the image to the specified bounding box.
          offset_y, offset_x, _ = tf.unstack(bbox_begin)
          target_height, target_width, _ = tf.unstack(bbox_size)
          crop_window = tf.stack(
              [offset_y, offset_x, target_height, target_width]
          )
          image = tf.image.decode_and_crop_jpeg(
              image_bytes, crop_window, channels=3
          )
  
          return image
  
file_path: gen-efficientnet-pytorch/data/tf_preprocessing.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import tensorflow
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: distorted_bounding_box_crop(image_bytes, bbox, min_object_covered, aspect_ratio_range, area_range, max_attempts, scope) and returns: image