code: def data_anchor_sampling(
      bbox_labels, image_width, image_height, scale_array, resize_width
  ):
      num_gt = len(bbox_labels)
      # np.random.randint range: [low, high)
      rand_idx = np.random.randint(0, num_gt) if num_gt != 0 else 0
  
      if num_gt != 0:
          norm_xmin = bbox_labels[rand_idx][0]
          norm_ymin = bbox_labels[rand_idx][1]
          norm_xmax = bbox_labels[rand_idx][2]
          norm_ymax = bbox_labels[rand_idx][3]
  
          xmin = norm_xmin * image_width
          ymin = norm_ymin * image_height
          wid = image_width * (norm_xmax - norm_xmin)
          hei = image_height * (norm_ymax - norm_ymin)
          range_size = 0
  
          area = wid * hei
          for scale_ind in range(0, len(scale_array) - 1):
              if (
                  area > scale_array[scale_ind] ** 2
                  and area < scale_array[scale_ind + 1] ** 2
              ):
                  range_size = scale_ind + 1
                  break
  
          if area > scale_array[len(scale_array) - 2] ** 2:
              range_size = len(scale_array) - 2
  
          scale_choose = 0.0
          if range_size == 0:
              rand_idx_size = 0
          else:
              # np.random.randint range: [low, high)
              rng_rand_size = np.random.randint(0, range_size + 1)
              rand_idx_size = rng_rand_size % (range_size + 1)
  
          if rand_idx_size == range_size:
              min_resize_val = scale_array[rand_idx_size] / 2.0
              max_resize_val = min(
                  2.0 * scale_array[rand_idx_size],
                  2 * math.sqrt(wid * hei),
              )
              scale_choose = random.uniform(
                  min_resize_val, max_resize_val
              )
          else:
              min_resize_val = scale_array[rand_idx_size] / 2.0
              max_resize_val = 2.0 * scale_array[rand_idx_size]
              scale_choose = random.uniform(
                  min_resize_val, max_resize_val
              )
  
          sample_bbox_size = wid * resize_width / scale_choose
  
          w_off_orig = 0.0
          h_off_orig = 0.0
          if sample_bbox_size < max(image_height, image_width):
              if wid <= sample_bbox_size:
                  w_off_orig = np.random.uniform(
                      xmin + wid - sample_bbox_size, xmin
                  )
              else:
                  w_off_orig = np.random.uniform(
                      xmin, xmin + wid - sample_bbox_size
                  )
  
              if hei <= sample_bbox_size:
                  h_off_orig = np.random.uniform(
                      ymin + hei - sample_bbox_size, ymin
                  )
              else:
                  h_off_orig = np.random.uniform(
                      ymin, ymin + hei - sample_bbox_size
                  )
  
          else:
              w_off_orig = np.random.uniform(
                  image_width - sample_bbox_size, 0.0
              )
              h_off_orig = np.random.uniform(
                  image_height - sample_bbox_size, 0.0
              )
  
          w_off_orig = math.floor(w_off_orig)
          h_off_orig = math.floor(h_off_orig)
  
          # Figure out top left coordinates.
          w_off = float(w_off_orig / image_width)
          h_off = float(h_off_orig / image_height)
  
          sampled_bbox = [
              w_off,
              h_off,
              w_off + float(sample_bbox_size / image_width),
              h_off + float(sample_bbox_size / image_height),
          ]
          return sampled_bbox
      else:
          return 0
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  import random
  import math
  import cv2
label_desc: Use image node_id 9 for calling a global function with example usage: data_anchor_sampling(bbox_labels, image_width, image_height, scale_array, resize_width) and returns: sampled_bbox, int