-
Notifications
You must be signed in to change notification settings - Fork 7.1k
feat: expose loader argument in Country211 and EuroSAT. #8922
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
Changes from all commits
551863e
8ed5947
b4877bc
2c23686
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from pathlib import Path | ||
from typing import Callable, Optional, Union | ||
from typing import Any, Callable, Optional, Union | ||
|
||
from .folder import ImageFolder | ||
from .folder import default_loader, ImageFolder | ||
from .utils import download_and_extract_archive, verify_str_arg | ||
|
||
|
||
|
@@ -21,6 +21,9 @@ class Country211(ImageFolder): | |
target_transform (callable, optional): A function/transform that takes in the target and transforms it. | ||
download (bool, optional): If True, downloads the dataset from the internet and puts it into | ||
``root/country211/``. If dataset is already downloaded, it is not downloaded again. | ||
loader (callable, optional): A function to load an image given its path. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the PR @GdoongMathew , Here and below, we should specify that the default is to use PIL, but that we encourage users to try to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added. I also updated the one in |
||
By default, it uses PIL as its image loader, but users could also pass in | ||
``torchvision.io.decode_image`` for decoding image data into tensors directly. | ||
""" | ||
|
||
_URL = "https://openaipublic.azureedge.net/clip/data/country211.tgz" | ||
|
@@ -33,6 +36,7 @@ def __init__( | |
transform: Optional[Callable] = None, | ||
target_transform: Optional[Callable] = None, | ||
download: bool = False, | ||
loader: Callable[[str], Any] = default_loader, | ||
) -> None: | ||
self._split = verify_str_arg(split, "split", ("train", "valid", "test")) | ||
|
||
|
@@ -46,7 +50,12 @@ def __init__( | |
if not self._check_exists(): | ||
raise RuntimeError("Dataset not found. You can use download=True to download it") | ||
|
||
super().__init__(str(self._base_folder / self._split), transform=transform, target_transform=target_transform) | ||
super().__init__( | ||
str(self._base_folder / self._split), | ||
transform=transform, | ||
target_transform=target_transform, | ||
loader=loader, | ||
) | ||
self.root = str(root) | ||
|
||
def _check_exists(self) -> bool: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import os | ||
from pathlib import Path | ||
from typing import Callable, Optional, Union | ||
from typing import Any, Callable, Optional, Union | ||
|
||
from .folder import ImageFolder | ||
from .folder import default_loader, ImageFolder | ||
from .utils import download_and_extract_archive | ||
|
||
|
||
|
@@ -21,6 +21,9 @@ class EuroSAT(ImageFolder): | |
download (bool, optional): If True, downloads the dataset from the internet and | ||
puts it in root directory. If dataset is already downloaded, it is not | ||
downloaded again. Default is False. | ||
loader (callable, optional): A function to load an image given its path. | ||
By default, it uses PIL as its image loader, but users could also pass in | ||
``torchvision.io.decode_image`` for decoding image data into tensors directly. | ||
""" | ||
|
||
def __init__( | ||
|
@@ -29,6 +32,7 @@ def __init__( | |
transform: Optional[Callable] = None, | ||
target_transform: Optional[Callable] = None, | ||
download: bool = False, | ||
loader: Callable[[str], Any] = default_loader, | ||
) -> None: | ||
self.root = os.path.expanduser(root) | ||
self._base_folder = os.path.join(self.root, "eurosat") | ||
|
@@ -40,7 +44,12 @@ def __init__( | |
if not self._check_exists(): | ||
raise RuntimeError("Dataset not found. You can use download=True to download it") | ||
|
||
super().__init__(self._data_folder, transform=transform, target_transform=target_transform) | ||
super().__init__( | ||
self._data_folder, | ||
transform=transform, | ||
target_transform=target_transform, | ||
loader=loader, | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do you feel about writing a basic test for this? Hopefully this can fit in <10 lines of code and we can re-use the same test across most datasets? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. Hopefully, for the rest of the test classes, one could update their |
||
self.root = os.path.expanduser(root) | ||
|
||
def __len__(self) -> int: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn, I hope we never have to change / fix this ever lol.
Thank you so much for pushing through the test @GdoongMathew