(bbox_ref, bboxes, name=None)
Resize bounding boxes based on a reference bounding box,
    assuming that the latter is [0, 0, 1, 1] after transform. Useful for
    updating a collection of boxes after cropping an image.
Resize bounding boxes based on a reference bounding box,
    assuming that the latter is [0, 0, 1, 1] after transform. Useful for
    updating a collection of boxes after cropping an image.
Resize bounding boxes based on a reference bounding box assuming that the latter is [ 0 0 1 1 ] after transform . Useful for updating a collection of boxes after cropping an image .
def bboxes_resize(bbox_ref, bboxes, name=None):
    """Resize bounding boxes based on a reference bounding box,
    assuming that the latter is [0, 0, 1, 1] after transform. Useful for
    updating a collection of boxes after cropping an image.
    """
    # Bboxes is dictionary.
    if isinstance(bboxes, dict):
        with tf.name_scope(name, 'bboxes_resize_dict'):
            d_bboxes = {}
            for c in bboxes.keys():
                d_bboxes[c] = bboxes_resize(bbox_ref, bboxes[c])
            return d_bboxes

    # Tensors inputs.
    with tf.name_scope(name, 'bboxes_resize'):
        # Translate.
        v = tf.stack([bbox_ref[0], bbox_ref[1], bbox_ref[0], bbox_ref[1]])
        bboxes = bboxes - v
        # Scale.
        s = tf.stack([bbox_ref[2] - bbox_ref[0],
                      bbox_ref[3] - bbox_ref[1],
                      bbox_ref[2] - bbox_ref[0],
                      bbox_ref[3] - bbox_ref[1]])
        bboxes = bboxes / s
        return bboxes
def bboxes_resize ( bbox_ref , bboxes , name = None ) : # Bboxes is dictionary. if isinstance ( bboxes , dict ) : with tf . name_scope ( name , 'bboxes_resize_dict' ) : d_bboxes = { } for c in bboxes . keys ( ) : d_bboxes [ c ] = bboxes_resize ( bbox_ref , bboxes [ c ] ) return d_bboxes # Tensors inputs. with tf . name_scope ( name , 'bboxes_resize' ) : # Translate. v = tf . stack ( [ bbox_ref [ 0 ] , bbox_ref [ 1 ] , bbox_ref [ 0 ] , bbox_ref [ 1 ] ] ) bboxes = bboxes - v # Scale. s = tf . stack ( [ bbox_ref [ 2 ] - bbox_ref [ 0 ] , bbox_ref [ 3 ] - bbox_ref [ 1 ] , bbox_ref [ 2 ] - bbox_ref [ 0 ] , bbox_ref [ 3 ] - bbox_ref [ 1 ] ] ) bboxes = bboxes / s return bboxes