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

Fix the default folds and assertion for checking valid folds in PASTIS #1810

Merged
merged 3 commits into from
Jan 16, 2024
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
Binary file modified tests/data/pastis/PASTIS-R.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/data/pastis/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def create_directory(directory: str, hierarchy: FILENAME_HIERARCHY) -> None:
"coordinates": [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]],
},
"id": str(i),
"properties": {"Fold": i % 5, "ID_PATCH": i},
"properties": {"Fold": (i % 5) + 1, "ID_PATCH": i},
}
)

Expand Down
10 changes: 5 additions & 5 deletions tests/datasets/test_pastis.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ def download_url(url: str, root: str, *args: str, **kwargs: str) -> None:
class TestPASTIS:
@pytest.fixture(
params=[
{"folds": (0, 1), "bands": "s2", "mode": "semantic"},
{"folds": (0, 1), "bands": "s1a", "mode": "semantic"},
{"folds": (0, 1), "bands": "s1d", "mode": "instance"},
{"folds": (1, 2), "bands": "s2", "mode": "semantic"},
{"folds": (1, 2), "bands": "s1a", "mode": "semantic"},
{"folds": (1, 2), "bands": "s1d", "mode": "instance"},
]
)
def dataset(
self, monkeypatch: MonkeyPatch, tmp_path: Path, request: SubRequest
) -> PASTIS:
monkeypatch.setattr(torchgeo.datasets.pastis, "download_url", download_url)

md5 = "9b11ae132623a0d13f7f0775d2003703"
md5 = "135a29fb8221241dde14f31579c07f45"
monkeypatch.setattr(PASTIS, "md5", md5)
url = os.path.join("tests", "data", "pastis", "PASTIS-R.zip")
monkeypatch.setattr(PASTIS, "url", url)
Expand Down Expand Up @@ -91,7 +91,7 @@ def test_corrupted(self, tmp_path: Path) -> None:

def test_invalid_fold(self) -> None:
with pytest.raises(AssertionError):
PASTIS(folds=(6,))
PASTIS(folds=(0,))

def test_invalid_mode(self) -> None:
with pytest.raises(AssertionError):
Expand Down
5 changes: 3 additions & 2 deletions torchgeo/datasets/pastis.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class PASTIS(NonGeoDataset):
def __init__(
self,
root: str = "data",
folds: Sequence[int] = (0, 1, 2, 3, 4),
folds: Sequence[int] = (1, 2, 3, 4, 5),
bands: str = "s2",
mode: str = "semantic",
transforms: Optional[Callable[[dict[str, Tensor]], dict[str, Tensor]]] = None,
Expand All @@ -153,7 +153,8 @@ def __init__(
Raises:
DatasetNotFoundError: If dataset is not found and *download* is False.
"""
assert set(folds) <= set(range(6))
for fold in folds:
assert 1 <= fold <= 5
assert bands in ["s1a", "s1d", "s2"]
assert mode in ["semantic", "instance"]
self.root = root
Expand Down