def conv_output_length(input_length, filter_size, stride, autopad=True,
    dilation=1):
    """Determines output length of a convolution given input length.

  Arguments:
      input_length: integer.
      filter_size: integer.
      padding: one of "same", "valid", "full", "causal"
      stride: integer.
      dilation: dilation rate, integer.

  Returns:
      The output length (integer).
  """
    if input_length is None:
        return None
    dilated_filter_size = (filter_size - 1) * dilation + 1
    if autopad:
        output_length = input_length
    else:
        output_length = input_length - dilated_filter_size + 1
    return (output_length + stride - 1) // stride
