(bbox_ref, bboxes, scope=None)
Clip bounding boxes to a reference box.
    Batch-compatible if the first dimension of `bbox_ref` and `bboxes`
    can be broadcasted.

    Args:
      bbox_ref: Reference bounding box. Nx4 or 4 shaped-Tensor;
      bboxes: Bounding boxes to clip. Nx4 or 4 shaped-Tensor or dictionary.
    Return:
      Clipped bboxes.
Clip bounding boxes to a reference box.
    Batch-compatible if the first dimension of `bbox_ref` and `bboxes`
    can be broadcasted.
Clip bounding boxes to a reference box . Batch - compatible if the first dimension of bbox_ref and bboxes can be broadcasted .
def bboxes_clip(bbox_ref, bboxes, scope=None):
    """Clip bounding boxes to a reference box.
    Batch-compatible if the first dimension of `bbox_ref` and `bboxes`
    can be broadcasted.

    Args:
      bbox_ref: Reference bounding box. Nx4 or 4 shaped-Tensor;
      bboxes: Bounding boxes to clip. Nx4 or 4 shaped-Tensor or dictionary.
    Return:
      Clipped bboxes.
    """
    # Bboxes is dictionary.
    if isinstance(bboxes, dict):
        with tf.name_scope(scope, 'bboxes_clip_dict'):
            d_bboxes = {}
            for c in bboxes.keys():
                d_bboxes[c] = bboxes_clip(bbox_ref, bboxes[c])
            return d_bboxes

    # Tensors inputs.
    with tf.name_scope(scope, 'bboxes_clip'):
        # Easier with transposed bboxes. Especially for broadcasting.
        bbox_ref = tf.transpose(bbox_ref)
        bboxes = tf.transpose(bboxes)
        # Intersection bboxes and reference bbox.
        ymin = tf.maximum(bboxes[0], bbox_ref[0])
        xmin = tf.maximum(bboxes[1], bbox_ref[1])
        ymax = tf.minimum(bboxes[2], bbox_ref[2])
        xmax = tf.minimum(bboxes[3], bbox_ref[3])
        # Double check! Empty boxes when no-intersection.
        #      _____
        #     |     |
        #     |_____|
        #                ______
        #               |      |
        #               |______|
        ymin = tf.minimum(ymin, ymax)
        xmin = tf.minimum(xmin, xmax)
        bboxes = tf.transpose(tf.stack([ymin, xmin, ymax, xmax], axis=0))
        return bboxes
def bboxes_clip ( bbox_ref , bboxes , scope = None ) : # Bboxes is dictionary. if isinstance ( bboxes , dict ) : with tf . name_scope ( scope , 'bboxes_clip_dict' ) : d_bboxes = { } for c in bboxes . keys ( ) : d_bboxes [ c ] = bboxes_clip ( bbox_ref , bboxes [ c ] ) return d_bboxes # Tensors inputs. with tf . name_scope ( scope , 'bboxes_clip' ) : # Easier with transposed bboxes. Especially for broadcasting. bbox_ref = tf . transpose ( bbox_ref ) bboxes = tf . transpose ( bboxes ) # Intersection bboxes and reference bbox. ymin = tf . maximum ( bboxes [ 0 ] , bbox_ref [ 0 ] ) xmin = tf . maximum ( bboxes [ 1 ] , bbox_ref [ 1 ] ) ymax = tf . minimum ( bboxes [ 2 ] , bbox_ref [ 2 ] ) xmax = tf . minimum ( bboxes [ 3 ] , bbox_ref [ 3 ] ) # Double check! Empty boxes when no-intersection. #      _____ #     |     | #     |_____| #                ______ #               |      | #               |______| ymin = tf . minimum ( ymin , ymax ) xmin = tf . minimum ( xmin , xmax ) bboxes = tf . transpose ( tf . stack ( [ ymin , xmin , ymax , xmax ] , axis = 0 ) ) return bboxes