def _get_padding(K, mode):
  """ Helper method to compute padding size """
  if mode == 'valid':
    return 0
  elif mode == 'same':
    assert K % 2 == 1, 'Invalid kernel size %d for "same" padding' % K
    return (K - 1) // 2