# Buggy code
def imread(uri, grayscale=False, expand_dims=True, rootpath=None, **kwargs):
    """

    Args:
        uri: {str, pathlib.Path, bytes, file}
        The resource to load the image from, e.g. a filename, pathlib.Path,
        http address or file object, see the docs for more info.
        grayscale:
        expand_dims:
        rootpath:

    Returns:

    """
    if rootpath is not None:
        uri = uri if uri.startswith(rootpath) else os.path.join(rootpath, uri)

    if JPEG4PY_ENABLED and uri.endswith(("jpg", "JPG", "jpeg", "JPEG")):
        img = jpeg.JPEG(uri).decode()
        if grayscale:
            img = rgb2gray(img)
    else:
        img = imageio.imread(uri, as_gray=grayscale, pilmode="RGB", **kwargs)

    if expand_dims and len(img.shape) < 3:  # grayscale
        img = np.expand_dims(img, -1)

    return img


# Traceback (TypeError)
TypeError                                 Traceback (most recent call last)
<ipython-input-92-cf55df030d98> in <module>
3
4 os.system("wget -O img.png https://www.sample-videos.com/img/Sample-png-image-200kb.png")
----> 5 imread("img.png")

/usr/local/lib/python3.6/dist-packages/catalyst/utils/image.py in imread(uri, grayscale, expand_dims, rootpath, **kwargs)
63             img = rgb2gray(img)
64     else:
---> 65         img = imageio.imread(uri, as_gray=grayscale, pilmode="RGB", **kwargs)
66
67     if expand_dims and len(img.shape) < 3:  # grayscale

/usr/local/lib/python3.6/dist-packages/imageio/core/functions.py in imread(uri, format, **kwargs)
183         )
184
--> 185     # Return its reader object
186     return format.get_reader(request)
187

/usr/local/lib/python3.6/dist-packages/imageio/core/functions.py in get_reader(uri, format, mode, **kwargs)
109
110     match = mem_re.match(arg)
--> 111     if match is None:
112         raise ValueError(
113             "Memory size could not be parsed "

/usr/local/lib/python3.6/dist-packages/imageio/core/format.py in get_reader(self, request)
156         from the given file. Users are encouraged to use
157         imageio.get_reader() instead.
--> 158         """
159         select_mode = request.mode[1] if request.mode[1] in "iIvV" else ""
160         if select_mode not in self.modes:

/usr/local/lib/python3.6/dist-packages/imageio/core/format.py in __init__(self, format, request)
205         and context management as Python's file objects.
206         """
--> 207
208         def __init__(self, format, request):
209             self.__closed = False

TypeError: _open() got an unexpected keyword argument 'as_gray'

# Fixed code
def imread(uri, grayscale=False, expand_dims=True, rootpath=None, **kwargs):
    """

    Args:
        uri: {str, pathlib.Path, bytes, file}
        The resource to load the image from, e.g. a filename, pathlib.Path,
        http address or file object, see the docs for more info.
        grayscale:
        expand_dims:
        rootpath:

    Returns:

    """
    if rootpath is not None:
        uri = uri if uri.startswith(rootpath) else os.path.join(rootpath, uri)

    if JPEG4PY_ENABLED and uri.endswith(("jpg", "JPG", "jpeg", "JPEG")):
        img = jpeg.JPEG(uri).decode()
    else:
        img = imageio.imread(uri, **kwargs)
    if grayscale:
        img = rgb2gray(img)

    if expand_dims and len(img.shape) < 3:  # grayscale
        img = np.expand_dims(img, -1)

    return img