-
Notifications
You must be signed in to change notification settings - Fork 388
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 Inria datamodule #498
Merged
Merged
Add Inria datamodule #498
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
591b609
Add Inria Datamodule
ashnair1 940e706
Fix up
ashnair1 0503f8b
Add predict.py
ashnair1 1d72772
Integrate kornia fns for extracting & combining
ashnair1 22c3428
transform creates problem when calculating metrics
ashnair1 022e434
Update
ashnair1 06e7766
Use dict.get
ashnair1 27209b1
Add tests & update test data
ashnair1 9364102
Add Inria datamodule to docs
ashnair1 b214a88
Reduce test data size
ashnair1 89d9e1c
Datamodules always have predict_dataloader
ashnair1 e51d07a
Remove comments
ashnair1 6379f47
Update predict.py
ashnair1 f3235ed
Add PredictDataset
ashnair1 1a9065c
Fix tests
ashnair1 618b3cc
Update inria.yaml
ashnair1 6268b35
Clarify predict_on doc
ashnair1 cfe9765
Refactor
ashnair1 9cd40de
Update min kornia
ashnair1 6ca5c49
Update inria.yaml
ashnair1 118e932
Remove predict utilities
ashnair1 2f6e896
Trainer fix
ashnair1 a60a956
Use kornia's compute_padding
ashnair1 5b9ef08
kornia docfix
ashnair1 90d6f5d
Use stable docs
ashnair1 db777ad
Fixes
ashnair1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. | ||
adamjstewart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 is pretty small... Note that
conf/inria.yaml
should contain the optimal hyperparameters whiletests/conf/inria.yaml
should contain the bare minimum to get the tests to run.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.
Added
tests/conf/inria.yaml
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.
Now that the small values required to make the tests run fast are in
tests/conf/inria.yaml
, should these values be increased? I guess it requires a hyperparam tuning to determine what the best hyperparams are.