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

Add LoveDADataModule to the trainer tests #966

Merged
merged 8 commits into from
Dec 30, 2022
Merged
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions tests/conf/loveda.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
experiment:
task: "loveda"
module:
loss: "ce"
model: "unet"
backbone: "resnet18"
weights: null
learning_rate: 1e-3
learning_rate_schedule_patience: 6
verbose: false
in_channels: 3
num_classes: 8
num_filters: 1
ignore_index: null
datamodule:
root: "tests/data/loveda"
download: true
batch_size: 1
num_workers: 0
46 changes: 0 additions & 46 deletions tests/datamodules/test_loveda.py

This file was deleted.

6 changes: 5 additions & 1 deletion tests/trainers/test_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
ETCI2021DataModule,
InriaAerialImageLabelingDataModule,
LandCoverAIDataModule,
LoveDADataModule,
NAIPChesapeakeDataModule,
OSCDDataModule,
SEN12MSDataModule,
Expand Down Expand Up @@ -44,6 +45,7 @@ class TestSemanticSegmentationTask:
("inria_val", InriaAerialImageLabelingDataModule),
("inria_test", InriaAerialImageLabelingDataModule),
("landcoverai", LandCoverAIDataModule),
("loveda", LoveDADataModule),
("naipchesapeake", NAIPChesapeakeDataModule),
("oscd_all", OSCDDataModule),
("oscd_rgb", OSCDDataModule),
Expand Down Expand Up @@ -81,7 +83,9 @@ def test_trainer(
# Instantiate trainer
trainer = Trainer(fast_dev_run=True, log_every_n_steps=1, max_epochs=1)
trainer.fit(model=model, datamodule=datamodule)
trainer.test(model=model, datamodule=datamodule)

if hasattr(datamodule, "test_dataset") or hasattr(datamodule, "test_sampler"):
trainer.test(model=model, datamodule=datamodule)

if hasattr(datamodule, "predict_dataset"):
trainer.predict(model=model, datamodule=datamodule)
Expand Down
17 changes: 9 additions & 8 deletions torchgeo/datamodules/loveda.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,19 @@ def setup(self, stage: Optional[str] = None) -> None:
stage: stage to set up
"""
train_transforms = self.preprocess
val_test_transforms = self.preprocess
val_predict_transforms = self.preprocess

self.train_dataset = LoveDA(
split="train", transforms=train_transforms, **self.kwargs
)

self.val_dataset = LoveDA(
split="val", transforms=val_test_transforms, **self.kwargs
split="val", transforms=val_predict_transforms, **self.kwargs
)

self.test_dataset = LoveDA(
split="test", transforms=val_test_transforms, **self.kwargs
# Test set masks are not public, use for prediction instead
self.predict_dataset = LoveDA(
split="test", transforms=val_predict_transforms, **self.kwargs
)

def train_dataloader(self) -> DataLoader[Any]:
Expand Down Expand Up @@ -107,14 +108,14 @@ def val_dataloader(self) -> DataLoader[Any]:
shuffle=False,
)

def test_dataloader(self) -> DataLoader[Any]:
"""Return a DataLoader for testing.
def predict_dataloader(self) -> DataLoader[Any]:
"""Return a DataLoader for prediction.

Returns:
testing data loader
predict data loader
"""
return DataLoader(
self.test_dataset,
self.predict_dataset,
batch_size=self.batch_size,
num_workers=self.num_workers,
shuffle=False,
Expand Down
2 changes: 2 additions & 0 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
EuroSATDataModule,
InriaAerialImageLabelingDataModule,
LandCoverAIDataModule,
LoveDADataModule,
NAIPChesapeakeDataModule,
NASAMarineDebrisDataModule,
OSCDDataModule,
Expand Down Expand Up @@ -52,6 +53,7 @@
"etci2021": (SemanticSegmentationTask, ETCI2021DataModule),
"inria": (SemanticSegmentationTask, InriaAerialImageLabelingDataModule),
"landcoverai": (SemanticSegmentationTask, LandCoverAIDataModule),
"loveda": (SemanticSegmentationTask, LoveDADataModule),
"naipchesapeake": (SemanticSegmentationTask, NAIPChesapeakeDataModule),
"nasa_marine_debris": (ObjectDetectionTask, NASAMarineDebrisDataModule),
"oscd": (SemanticSegmentationTask, OSCDDataModule),
Expand Down