Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIL backend update #188

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion cascade/utils/vision/folder_image_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def __init__(self) -> None:
def read(self, path: str) -> "PIL.Image":
try:
img = self._image.open(path)
if img.mode != "RGB":
img = img.convert('RGB')
except Exception as e:
raise IOError(f"PIL failed to read {path}") from e
return img
Expand All @@ -67,7 +69,15 @@ class FolderImageDataset(FolderDataset):
Supports opencv or pillow backends
"""

def __init__(self, root: str, backend: Literal["cv2", "PIL"], *args: Any, **kwargs: Any) -> None:
def __init__(self, root: str, backend: Literal["cv2", "PIL"] = "PIL", *args: Any, **kwargs: Any) -> None:
"""
Parameters
----------
root : str
The folder with images. Should contain image files only
backend : Literal["cv2", "PIL"], optional
What library to use to load images, by default "PIL"
"""
super().__init__(root, *args, **kwargs)

if backend == "cv2":
Expand Down