def compute_conv_output_dim(ifm_dim, k, stride, total_pad=0, dilation=1):
    """Returns spatial output dimension size for convolution with given params.
    total_pad gives the total amount of padding along the entire axis
    (both sides included).
    """
    if ifm_dim == 1:
        # indicates dummy dimension, keep as-is
        out_dim = 1
    else:
        out_dim = int(((ifm_dim + total_pad - dilation * (k - 1) - 1) / stride) + 1)
    return out_dim