def calculate_same_padding(kernel_size, dilation, stride):
    """Calculates the amount of padding to use to get the "SAME" functionality in Tensorflow."""

    return ((stride - 1) + dilation * (kernel_size - 1)) // 2