def sample_boxes_by_jittering(boxlist,
                              num_boxes_to_sample,
                              stddev=0.1,
                              scope=None):
  """Samples num_boxes_to_sample boxes by jittering around boxlist boxes.

  It is possible that this function might generate boxes with size 0. The larger
  the stddev, this is more probable. For a small stddev of 0.1 this probability
  is very small.

  Args:
    boxlist: A boxlist containing N boxes in normalized coordinates.
    num_boxes_to_sample: A positive integer containing the number of boxes to
      sample.
    stddev: Standard deviation. This is used to draw random offsets for the
      box corners from a normal distribution. The offset is multiplied by the
      box size so will be larger in terms of pixels for larger boxes.
    scope: Name scope.

  Returns:
    sampled_boxlist: A boxlist containing num_boxes_to_sample boxes in
      normalized coordinates.
  """
  with tf.name_scope(scope, 'SampleBoxesByJittering'):
    num_boxes = boxlist.num_boxes()
    box_indices = tf.random_uniform(
        [num_boxes_to_sample],
        minval=0,
        maxval=num_boxes,
        dtype=tf.int32)
    sampled_boxes = tf.gather(boxlist.get(), box_indices)
    sampled_boxes_height = sampled_boxes[:, 2] - sampled_boxes[:, 0]
    sampled_boxes_width = sampled_boxes[:, 3] - sampled_boxes[:, 1]
    rand_miny_gaussian = tf.random_normal([num_boxes_to_sample], stddev=stddev)
    rand_minx_gaussian = tf.random_normal([num_boxes_to_sample], stddev=stddev)
    rand_maxy_gaussian = tf.random_normal([num_boxes_to_sample], stddev=stddev)
    rand_maxx_gaussian = tf.random_normal([num_boxes_to_sample], stddev=stddev)
    miny = rand_miny_gaussian * sampled_boxes_height + sampled_boxes[:, 0]
    minx = rand_minx_gaussian * sampled_boxes_width + sampled_boxes[:, 1]
    maxy = rand_maxy_gaussian * sampled_boxes_height + sampled_boxes[:, 2]
    maxx = rand_maxx_gaussian * sampled_boxes_width + sampled_boxes[:, 3]
    maxy = tf.maximum(miny, maxy)
    maxx = tf.maximum(minx, maxx)
    sampled_boxes = tf.stack([miny, minx, maxy, maxx], axis=1)
    sampled_boxes = tf.maximum(tf.minimum(sampled_boxes, 1.0), 0.0)
    return box_list.BoxList(sampled_boxes)
Samples num_boxes_to_sample boxes by jittering around boxlist boxes.

  It is possible that this function might generate boxes with size 0. The larger
  the stddev, this is more probable. For a small stddev of 0.1 this probability
  is very small.

  Args:
    boxlist: A boxlist containing N boxes in normalized coordinates.
    num_boxes_to_sample: A positive integer containing the number of boxes to
      sample.
    stddev: Standard deviation. This is used to draw random offsets for the
      box corners from a normal distribution. The offset is multiplied by the
      box size so will be larger in terms of pixels for larger boxes.
    scope: Name scope.

  Returns:
    sampled_boxlist: A boxlist containing num_boxes_to_sample boxes in
      normalized coordinates.
  
inference_api/src/main/object_detection/core/box_list_ops.py