def parse_image_size(image_size):
    """Parse the image size and return (height, width).

    Args:
    image_size: A integer, a tuple (H, W), or a string with HxW format.

    Returns:
    A tuple of integer (height, width).
    """
    if isinstance(image_size, int):
    # image_size is integer, with the same width and height.
        return (image_size, image_size)

    if isinstance(image_size, str):
    # image_size is a string with format WxH
        width, height = image_size.lower().split('x')
        return (int(height), int(width))

    if isinstance(image_size, tuple):
        return image_size

    raise ValueError('image_size must be an int, WxH string, or (height, width)'
                    'tuple. Was %r' % image_size)