(images, offset_height, offset_width, target_height, target_width)
return padded
Zero-pads a batch of images with the given dimensions.

    @param images: 4-D tensor with shape [batch_size, height, width, channels]
    @param offset_height: Number of rows of zeros to add on top.
    @param offset_width: Number of columns of zeros to add on the left.
    @param target_height: Height of output images.
    @param target_width: Width of output images.

    @return: The batch of images, all zero-padded with the specified dimensions.
Zero-pads a batch of images with the given dimensions.
Zero - pads a batch of images with the given dimensions .
def batch_pad_to_bounding_box(images, offset_height, offset_width, target_height, target_width):
    """
    Zero-pads a batch of images with the given dimensions.

    @param images: 4-D tensor with shape [batch_size, height, width, channels]
    @param offset_height: Number of rows of zeros to add on top.
    @param offset_width: Number of columns of zeros to add on the left.
    @param target_height: Height of output images.
    @param target_width: Width of output images.

    @return: The batch of images, all zero-padded with the specified dimensions.
    """
    batch_size, height, width, channels = tf.Session().run(tf.shape(images))

    if not offset_height >= 0:
        raise ValueError('offset_height must be >= 0')
    if not offset_width >= 0:
        raise ValueError('offset_width must be >= 0')
    if not target_height >= height + offset_height:
        raise ValueError('target_height must be >= height + offset_height')
    if not target_width >= width + offset_width:
        raise ValueError('target_width must be >= width + offset_width')

    num_tpad = offset_height
    num_lpad = offset_width
    num_bpad = target_height - (height + offset_height)
    num_rpad = target_width - (width + offset_width)

    tpad = np.zeros([batch_size, num_tpad, width, channels])
    bpad = np.zeros([batch_size, num_bpad, width, channels])
    lpad = np.zeros([batch_size, target_height, num_lpad, channels])
    rpad = np.zeros([batch_size, target_height, num_rpad, channels])

    padded = images
    if num_tpad > 0 and num_bpad > 0: padded = tf.concat(1, [tpad, padded, bpad])
    elif num_tpad > 0: padded = tf.concat(1, [tpad, padded])
    elif num_bpad > 0: padded = tf.concat(1, [padded, bpad])
    if num_lpad > 0 and num_rpad > 0: padded = tf.concat(2, [lpad, padded, rpad])
    elif num_lpad > 0: padded = tf.concat(2, [lpad, padded])
    elif num_rpad > 0: padded = tf.concat(2, [padded, rpad])

    return padded
def batch_pad_to_bounding_box ( images , offset_height , offset_width , target_height , target_width ) : batch_size , height , width , channels = tf . Session ( ) . run ( tf . shape ( images ) ) if not offset_height >= 0 : raise ValueError ( 'offset_height must be >= 0' ) if not offset_width >= 0 : raise ValueError ( 'offset_width must be >= 0' ) if not target_height >= height + offset_height : raise ValueError ( 'target_height must be >= height + offset_height' ) if not target_width >= width + offset_width : raise ValueError ( 'target_width must be >= width + offset_width' ) num_tpad = offset_height num_lpad = offset_width num_bpad = target_height - ( height + offset_height ) num_rpad = target_width - ( width + offset_width ) tpad = np . zeros ( [ batch_size , num_tpad , width , channels ] ) bpad = np . zeros ( [ batch_size , num_bpad , width , channels ] ) lpad = np . zeros ( [ batch_size , target_height , num_lpad , channels ] ) rpad = np . zeros ( [ batch_size , target_height , num_rpad , channels ] ) padded = images if num_tpad > 0 and num_bpad > 0 : padded = tf . concat ( 1 , [ tpad , padded , bpad ] ) elif num_tpad > 0 : padded = tf . concat ( 1 , [ tpad , padded ] ) elif num_bpad > 0 : padded = tf . concat ( 1 , [ padded , bpad ] ) if num_lpad > 0 and num_rpad > 0 : padded = tf . concat ( 2 , [ lpad , padded , rpad ] ) elif num_lpad > 0 : padded = tf . concat ( 2 , [ lpad , padded ] ) elif num_rpad > 0 : padded = tf . concat ( 2 , [ padded , rpad ] ) return padded