def select_random_box(boxlist,
                      default_box=None,
                      seed=None,
                      scope=None):
  """Selects a random bounding box from a `BoxList`.

  Args:
    boxlist: A BoxList.
    default_box: A [1, 4] float32 tensor. If no boxes are present in `boxlist`,
      this default box will be returned. If None, will use a default box of
      [[-1., -1., -1., -1.]].
    seed: Random seed.
    scope: Name scope.

  Returns:
    bbox: A [1, 4] tensor with a random bounding box.
    valid: A bool tensor indicating whether a valid bounding box is returned
      (True) or whether the default box is returned (False).
  """
  with tf.name_scope(scope, 'SelectRandomBox'):
    bboxes = boxlist.get()
    combined_shape = shape_utils.combined_static_and_dynamic_shape(bboxes)
    number_of_boxes = combined_shape[0]
    default_box = default_box or tf.constant([[-1., -1., -1., -1.]])

    def select_box():
      random_index = tf.random_uniform([],
                                       maxval=number_of_boxes,
                                       dtype=tf.int32,
                                       seed=seed)
      return tf.expand_dims(bboxes[random_index], axis=0), tf.constant(True)

  return tf.cond(
      tf.greater_equal(number_of_boxes, 1),
      true_fn=select_box,
      false_fn=lambda: (default_box, tf.constant(False)))
Selects a random bounding box from a `BoxList`.

  Args:
    boxlist: A BoxList.
    default_box: A [1, 4] float32 tensor. If no boxes are present in `boxlist`,
      this default box will be returned. If None, will use a default box of
      [[-1., -1., -1., -1.]].
    seed: Random seed.
    scope: Name scope.

  Returns:
    bbox: A [1, 4] tensor with a random bounding box.
    valid: A bool tensor indicating whether a valid bounding box is returned
      (True) or whether the default box is returned (False).
  
inference_api/src/main/object_detection/core/box_list_ops.py