import tensorflow as tf

            w = x_shape[2]
            pad_h1 = tf.mod(-h + bsize[1], bstrides[1])
            pad_w1 = tf.mod(-w + bsize[2], bstrides[2])
            return tf.cond(
                tf.logical_or(tf.greater(pad_h1, 0), tf.greater(pad_w1, 0)),
                lambda: tf.pad(x, [[0, 0], [0, pad_h1], [0, pad_w1], [0, 0]]), lambda: x)
        else:
            return x
