code: def distorted_bounding_box_crop(
      image_buffer,
      num_channels,
      min_object_covered=0.1,
      aspect_ratio_range=(0.75, 1.33),
      area_range=(0.05, 1.0),
      max_attempts=100,
  ):
      """Generates cropped_image using a one of the bboxes randomly distorted.
  
      See `tf.image.sample_distorted_bounding_box` for more documentation.
  
      Args:
      image_buffer: 3-D Tensor of image.
      num_channels: num of channels
      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 `floats`. The cropped area of the
        image must have an aspect ratio = width / height within this range.
      area_range: An optional list of `floats`. 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 scope for name_scope.
      Returns:
      A tuple, a 3-D Tensor cropped_image
      """
      # bbox: 3-D float 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 it would use the whole
      #       image.
      bbox = tf.constant(
          [0.0, 0.0, 1.0, 1.0], dtype=tf.float32, shape=[1, 1, 4]
      )  # From the entire image
  
      sample_distorted_bounding_box = (
          tf.image.sample_distorted_bounding_box(
              tf.image.extract_jpeg_shape(image_buffer),
              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,
          distort_bbox,
      ) = sample_distorted_bounding_box
  
      # Reassemble the bounding box in the format the crop op requires.
      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]
      )
  
      # Use the fused decode and crop op here, which is faster than each in series.
      cropped_image = tf.image.decode_and_crop_jpeg(
          image_buffer, crop_window, channels=num_channels
      )
  
      return cropped_image
  
file_path: analytics-zoo/pyzoo/zoo/examples/orca/learn/tf/inception/inception_preprocessing.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import tensorflow.compat.v1
  from tensorflow.python.ops import control_flow_ops
label_desc: Use image node_id 1 for calling a global function with example usage: distorted_bounding_box_crop(image_buffer, num_channels, min_object_covered, aspect_ratio_range, area_range, max_attempts) and returns: cropped_image