forked from microsoft/torchgeo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Inria datamodule (microsoft#498)
* Add Inria Datamodule * Fix up * Add predict.py * Integrate kornia fns for extracting & combining Requires kornia/kornia#1558 to be merged * transform creates problem when calculating metrics * Update * Use dict.get * Add tests & update test data * Add Inria datamodule to docs * Reduce test data size * Datamodules always have predict_dataloader * Remove comments * Update predict.py * Add PredictDataset * Fix tests * Update inria.yaml * Clarify predict_on doc * Refactor * Update min kornia * Update inria.yaml * Remove predict utilities * Trainer fix * Use kornia's compute_padding * kornia docfix * Use stable docs * Fixes
- Loading branch information
Showing
29 changed files
with
389 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
program: | ||
overwrite: True | ||
|
||
|
||
trainer: | ||
gpus: 1 | ||
min_epochs: 5 | ||
max_epochs: 100 | ||
benchmark: True | ||
log_every_n_steps: 2 | ||
|
||
experiment: | ||
task: "inria" | ||
name: "inria_test" | ||
module: | ||
loss: "ce" | ||
segmentation_model: "unet" | ||
encoder_name: "resnet18" | ||
encoder_weights: "imagenet" | ||
learning_rate: 1e-3 | ||
learning_rate_schedule_patience: 6 | ||
in_channels: 3 | ||
num_classes: 2 | ||
ignore_zeros: True # class 0 not used for scoring | ||
datamodule: | ||
root_dir: "data/inria" | ||
batch_size: 2 | ||
num_workers: 32 | ||
patch_size: 512 | ||
num_patches_per_tile: 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
experiment: | ||
task: "inria" | ||
module: | ||
loss: "ce" | ||
segmentation_model: "unet" | ||
encoder_name: "resnet18" | ||
encoder_weights: "imagenet" | ||
learning_rate: 1e-3 | ||
learning_rate_schedule_patience: 6 | ||
in_channels: 3 | ||
num_classes: 2 | ||
ignore_zeros: True # class 0 not used for scoring | ||
datamodule: | ||
root_dir: "tests/data/inria" | ||
batch_size: 1 | ||
num_workers: 0 | ||
val_split_pct: 0.2 | ||
test_split_pct: 0.2 | ||
patch_size: 2 | ||
num_patches_per_tile: 2 |
Binary file modified
BIN
-11.8 KB
(4.4%)
tests/data/inria/AerialImageDataset/test/images/austin10.tif
Binary file not shown.
Binary file modified
BIN
-11.8 KB
(4.4%)
tests/data/inria/AerialImageDataset/test/images/austin11.tif
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
-11.8 KB
(4.4%)
tests/data/inria/AerialImageDataset/train/images/austin1.tif
Binary file not shown.
Binary file modified
BIN
-11.8 KB
(4.4%)
tests/data/inria/AerialImageDataset/train/images/austin2.tif
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import os | ||
|
||
import pytest | ||
from _pytest.fixtures import SubRequest | ||
|
||
from torchgeo.datamodules import InriaAerialImageLabelingDataModule | ||
|
||
TEST_DATA_DIR = os.path.join("tests", "data", "inria") | ||
|
||
|
||
class TestInriaAerialImageLabelingDataModule: | ||
@pytest.fixture( | ||
params=zip([0.2, 0.2, 0.0], [0.2, 0.0, 0.0], ["test", "test", "test"]) | ||
) | ||
def datamodule(self, request: SubRequest) -> InriaAerialImageLabelingDataModule: | ||
val_split_pct, test_split_pct, predict_on = request.param | ||
patch_size = 2 # (2,2) | ||
num_patches_per_tile = 2 | ||
root = TEST_DATA_DIR | ||
batch_size = 1 | ||
num_workers = 0 | ||
dm = InriaAerialImageLabelingDataModule( | ||
root, | ||
batch_size, | ||
num_workers, | ||
val_split_pct, | ||
test_split_pct, | ||
patch_size, | ||
num_patches_per_tile, | ||
predict_on=predict_on, | ||
) | ||
dm.prepare_data() | ||
dm.setup() | ||
return dm | ||
|
||
def test_train_dataloader( | ||
self, datamodule: InriaAerialImageLabelingDataModule | ||
) -> None: | ||
sample = next(iter(datamodule.train_dataloader())) | ||
assert sample["image"].shape[-2:] == sample["mask"].shape[-2:] == (2, 2) | ||
assert sample["image"].shape[0] == sample["mask"].shape[0] == 2 | ||
assert sample["image"].shape[1] == 3 | ||
assert sample["mask"].shape[1] == 1 | ||
|
||
def test_val_dataloader( | ||
self, datamodule: InriaAerialImageLabelingDataModule | ||
) -> None: | ||
sample = next(iter(datamodule.val_dataloader())) | ||
if datamodule.val_split_pct > 0.0: | ||
assert sample["image"].shape[-2:] == sample["mask"].shape[-2:] == (2, 2) | ||
assert sample["image"].shape[0] == sample["mask"].shape[0] == 2 | ||
|
||
def test_test_dataloader( | ||
self, datamodule: InriaAerialImageLabelingDataModule | ||
) -> None: | ||
sample = next(iter(datamodule.test_dataloader())) | ||
if datamodule.test_split_pct > 0.0: | ||
assert sample["image"].shape[-2:] == sample["mask"].shape[-2:] == (2, 2) | ||
assert sample["image"].shape[0] == sample["mask"].shape[0] == 2 | ||
|
||
def test_predict_dataloader( | ||
self, datamodule: InriaAerialImageLabelingDataModule | ||
) -> None: | ||
sample = next(iter(datamodule.predict_dataloader())) | ||
assert len(sample["image"].shape) == 5 | ||
assert sample["image"].shape[-2:] == (2, 2) | ||
assert sample["image"].shape[2] == 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.