import tensorflow as tf

    assert (bsize[2] - ksize[1]) % strides[2] == 0, ERR_MSG_DIV.format(
        strides[2], bsize[2], ksize[1])
    assert strides[0] == strides[3] == 1, ERR_MSG_DIM.format(strides)

    bstrides = _calc_block_strides(bsize, ksize, strides)

    # Pad mask.
    mask_ = tf.expand_dims(mask, 3)
    mask_ = _pad_input(mask_, ksize, strides, padding, bsize=bsize, bstrides=bstrides)
    mask_ = tf.nn.max_pool(mask_, bsize, bstrides, 'VALID')    # Blocks are always valid conv.
    mask_ = tf.squeeze(mask_, [3])
    indices = tf.where(tf.greater(mask_, tol))
    indices = tf.cast(indices, tf.int32)
    return indices


def convert_mask_to_block_indices(mask, bsize, ksize, strides, padding, tol):
    """
