def load_img(path, grayscale=False, target_size=None, interpolation='nearest'):
    'Loads an image into PIL format.\n\n    # Arguments\n        path: Path to image file.\n        grayscale: Boolean, whether to load the image as grayscale.\n        target_size: Either `None` (default to original size)\n            or tuple of ints `(img_height, img_width)`.\n        interpolation: Interpolation method used to resample the image if the\n            target size is different from that of the loaded image.\n            Supported methods are "nearest", "bilinear", and "bicubic".\n            If PIL version 1.1.3 or newer is installed, "lanczos" is also\n            supported. If PIL version 3.4.0 or newer is installed, "box" and\n            "hamming" are also supported. By default, "nearest" is used.\n\n    # Returns\n        A PIL Image instance.\n\n    # Raises\n        ImportError: if PIL is not available.\n        ValueError: if interpolation method is not supported.\n    '
    if (pil_image is None):
        raise ImportError('Could not import PIL.Image. The use of `array_to_img` requires PIL.')
    img = pil_image.open(path)
    if grayscale:
        if (img.mode != 'L'):
            img = img.convert('L')
    elif (img.mode != 'RGB'):
        img = img.convert('RGB')
    if (target_size is not None):
        width_height_tuple = (target_size[1], target_size[0])
        if (img.size != width_height_tuple):
            if (interpolation not in _PIL_INTERPOLATION_METHODS):
                raise ValueError('Invalid interpolation method {} specified. Supported methods are {}'.format(interpolation, ', '.join(_PIL_INTERPOLATION_METHODS.keys())))
            resample = _PIL_INTERPOLATION_METHODS[interpolation]
            img = img.resize(width_height_tuple, resample)
    return img
Loads an image into PIL format.

# Arguments
    path: Path to image file.
    grayscale: Boolean, whether to load the image as grayscale.
    target_size: Either `None` (default to original size)
        or tuple of ints `(img_height, img_width)`.
    interpolation: Interpolation method used to resample the image if the
        target size is different from that of the loaded image.
        Supported methods are "nearest", "bilinear", and "bicubic".
        If PIL version 1.1.3 or newer is installed, "lanczos" is also
        supported. If PIL version 3.4.0 or newer is installed, "box" and
        "hamming" are also supported. By default, "nearest" is used.

# Returns
    A PIL Image instance.

# Raises
    ImportError: if PIL is not available.
    ValueError: if interpolation method is not supported.
def load_img(path, grayscale=False, target_size=None, interpolation='nearest'):
    'Loads an image into PIL format.\n\n    # Arguments\n        path: Path to image file.\n        grayscale: Boolean, whether to load the image as grayscale.\n        target_size: Either `None` (default to original size)\n            or tuple of ints `(img_height, img_width)`.\n        interpolation: Interpolation method used to resample the image if the\n            target size is different from that of the loaded image.\n            Supported methods are "nearest", "bilinear", and "bicubic".\n            If PIL version 1.1.3 or newer is installed, "lanczos" is also\n            supported. If PIL version 3.4.0 or newer is installed, "box" and\n            "hamming" are also supported. By default, "nearest" is used.\n\n    # Returns\n        A PIL Image instance.\n\n    # Raises\n        ImportError: if PIL is not available.\n        ValueError: if interpolation method is not supported.\n    '
    if (pil_image is None):
        raise ImportError('Could not import PIL.Image. The use of `array_to_img` requires PIL.')
    img = pil_image.open(path)
    if grayscale:
        if (img.mode != 'L'):
            img = img.convert('L')
    elif (img.mode != 'RGB'):
        img = img.convert('RGB')
    if (target_size is not None):
        width_height_tuple = (target_size[1], target_size[0])
        if (img.size != width_height_tuple):
            if (interpolation not in _PIL_INTERPOLATION_METHODS):
                raise ValueError('Invalid interpolation method {} specified. Supported methods are {}'.format(interpolation, ', '.join(_PIL_INTERPOLATION_METHODS.keys())))
            resample = _PIL_INTERPOLATION_METHODS[interpolation]
            img = img.resize(width_height_tuple, resample)
    return img