(image, bboxes, seed=None)
Random flip left-right of an image and its bounding boxes.
Random flip left-right of an image and its bounding boxes.
Random flip left - right of an image and its bounding boxes .
def random_flip_left_right(image, bboxes, seed=None):
    """Random flip left-right of an image and its bounding boxes.
    """
    def flip_bboxes(bboxes):
        """Flip bounding boxes coordinates.
        """
        bboxes = tf.stack([bboxes[:, 0], 1 - bboxes[:, 3],
                           bboxes[:, 2], 1 - bboxes[:, 1]], axis=-1)
        return bboxes

    # Random flip. Tensorflow implementation.
    with tf.name_scope('random_flip_left_right'):
        image = ops.convert_to_tensor(image, name='image')
        _Check3DImage(image, require_static=False)
        uniform_random = random_ops.random_uniform([], 0, 1.0, seed=seed)
        mirror_cond = math_ops.less(uniform_random, .5)
        # Flip image.
        result = control_flow_ops.cond(mirror_cond,
                                       lambda: array_ops.reverse_v2(image, [1]),
                                       lambda: image)
        # Flip bboxes.
        bboxes = control_flow_ops.cond(mirror_cond,
                                       lambda: flip_bboxes(bboxes),
                                       lambda: bboxes)
        return fix_image_flip_shape(image, result), bboxes
def random_flip_left_right ( image , bboxes , seed = None ) : def flip_bboxes ( bboxes ) : """Flip bounding boxes coordinates.
        """ bboxes = tf . stack ( [ bboxes [ : , 0 ] , 1 - bboxes [ : , 3 ] , bboxes [ : , 2 ] , 1 - bboxes [ : , 1 ] ] , axis = - 1 ) return bboxes # Random flip. Tensorflow implementation. with tf . name_scope ( 'random_flip_left_right' ) : image = ops . convert_to_tensor ( image , name = 'image' ) _Check3DImage ( image , require_static = False ) uniform_random = random_ops . random_uniform ( [ ] , 0 , 1.0 , seed = seed ) mirror_cond = math_ops . less ( uniform_random , .5 ) # Flip image. result = control_flow_ops . cond ( mirror_cond , lambda : array_ops . reverse_v2 ( image , [ 1 ] ) , lambda : image ) # Flip bboxes. bboxes = control_flow_ops . cond ( mirror_cond , lambda : flip_bboxes ( bboxes ) , lambda : bboxes ) return fix_image_flip_shape ( image , result ) , bboxes