-
Notifications
You must be signed in to change notification settings - Fork 373
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
DataModules: only instantiate when download requested #974
Changes from 1 commit
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 |
---|---|---|
|
@@ -12,5 +12,6 @@ experiment: | |
ignore_index: 0 | ||
datamodule: | ||
root: "tests/data/etci2021" | ||
download: true | ||
batch_size: 1 | ||
num_workers: 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,6 @@ experiment: | |
num_classes: 2 | ||
datamodule: | ||
root: "tests/data/eurosat" | ||
download: true | ||
batch_size: 1 | ||
num_workers: 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,6 @@ experiment: | |
num_classes: 3 | ||
datamodule: | ||
root: "tests/data/resisc45" | ||
download: true | ||
batch_size: 1 | ||
num_workers: 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,6 @@ experiment: | |
num_classes: 2 | ||
datamodule: | ||
root: "tests/data/ucmerced" | ||
download: true | ||
batch_size: 1 | ||
num_workers: 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,8 +31,6 @@ class NAIPChesapeakeDataModule(pl.LightningDataModule): | |
|
||
def __init__( | ||
self, | ||
naip_root: str, | ||
chesapeake_root: str, | ||
batch_size: int = 64, | ||
num_workers: int = 0, | ||
patch_size: int = 256, | ||
|
@@ -41,22 +39,25 @@ def __init__( | |
"""Initialize a LightningDataModule for NAIP and Chesapeake based DataLoaders. | ||
|
||
Args: | ||
naip_root: directory containing NAIP data | ||
chesapeake_root: directory containing Chesapeake data | ||
batch_size: The batch size to use in all created DataLoaders | ||
num_workers: The number of workers to use in all created DataLoaders | ||
patch_size: size of patches to sample | ||
**kwargs: Additional keyword arguments passed to | ||
:class:`~torchgeo.datasets.NAIP` and | ||
:class:`~torchgeo.datasets.Chesapeake13` | ||
:class:`~torchgeo.datasets.NAIP` (prefix keys with naip_) and | ||
:class:`~torchgeo.datasets.Chesapeake13` (prefix keys with chesapeake_) | ||
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. When I first added this I was lazy and didn't provide a way to separate these. This seems like a good solution to me. |
||
""" | ||
super().__init__() | ||
self.naip_root = naip_root | ||
self.chesapeake_root = chesapeake_root | ||
self.batch_size = batch_size | ||
self.num_workers = num_workers | ||
self.patch_size = patch_size | ||
self.kwargs = kwargs | ||
|
||
self.naip_kwargs = {} | ||
self.chesapeake_kwargs = {} | ||
for key, val in kwargs.items(): | ||
if key.startswith("naip_"): | ||
self.naip_kwargs[key[5:]] = val | ||
elif key.startswith("chesapeake_"): | ||
self.chesapeake_kwargs[key[11:]] = val | ||
|
||
def preprocess(self, sample: Dict[str, Any]) -> Dict[str, Any]: | ||
"""Transform a single sample from the NAIP Dataset. | ||
|
@@ -102,7 +103,8 @@ def prepare_data(self) -> None: | |
|
||
This method is only called once per run. | ||
""" | ||
Chesapeake13(self.chesapeake_root, **self.kwargs) | ||
if self.chesapeake_kwargs.get("download", False): | ||
Chesapeake13(**self.chesapeake_kwargs) | ||
|
||
def setup(self, stage: Optional[str] = None) -> None: | ||
"""Initialize the main ``Dataset`` objects. | ||
|
@@ -119,14 +121,13 @@ def setup(self, stage: Optional[str] = None) -> None: | |
chesapeak_transforms = Compose([self.chesapeake_transform, self.remove_bbox]) | ||
|
||
self.chesapeake = Chesapeake13( | ||
self.chesapeake_root, transforms=chesapeak_transforms, **self.kwargs | ||
transforms=chesapeak_transforms, **self.chesapeake_kwargs | ||
) | ||
self.naip = NAIP( | ||
self.naip_root, | ||
self.chesapeake.crs, | ||
self.chesapeake.res, | ||
crs=self.chesapeake.crs, | ||
res=self.chesapeake.res, | ||
transforms=naip_transforms, | ||
**self.kwargs, | ||
**self.naip_kwargs, | ||
) | ||
self.dataset = self.chesapeake & self.naip | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,13 +103,6 @@ def preprocess(self, sample: Dict[str, Any]) -> Dict[str, Any]: | |
|
||
return sample | ||
|
||
def prepare_data(self) -> None: | ||
"""Make sure that the dataset is downloaded. | ||
|
||
This method is only called once per run. | ||
""" | ||
So2Sat(**self.kwargs) | ||
Comment on lines
-106
to
-111
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. This dataset cannot be automatically downloaded, no reason to prepare_data |
||
|
||
def setup(self, stage: Optional[str] = None) -> None: | ||
"""Initialize the main ``Dataset`` objects. | ||
|
||
|
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.
This file will be deleted in #966, this is only temporary