-
Notifications
You must be signed in to change notification settings - Fork 380
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
Million-AID dataset #455
Merged
Merged
Million-AID dataset #455
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
20406b7
millionaid
nilsleh 1c7951a
test
nilsleh 8903905
separator
nilsleh af42f59
remove type ignore
nilsleh 28c3cc3
type in test
nilsleh 9af29b4
requested changes
nilsleh 0993e60
typos and glob pattern
nilsleh ea6ad5b
task argument description
nilsleh 5715315
add test md5 hash
nilsleh 976ad3d
Remove download logic
adamjstewart 1fce2bc
Type ignore no longer needed
adamjstewart 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
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,52 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import hashlib | ||
import os | ||
import shutil | ||
|
||
import numpy as np | ||
from PIL import Image | ||
|
||
SIZE = 32 | ||
|
||
np.random.seed(0) | ||
|
||
PATHS = { | ||
"train": [ | ||
os.path.join( | ||
"train", "agriculture_land", "grassland", "meadow", "P0115918.jpg" | ||
), | ||
os.path.join("train", "water_area", "beach", "P0060208.jpg"), | ||
], | ||
"test": [ | ||
os.path.join("test", "agriculture_land", "grassland", "meadow", "P0115918.jpg"), | ||
os.path.join("test", "water_area", "beach", "P0060208.jpg"), | ||
], | ||
} | ||
|
||
|
||
def create_file(path: str) -> None: | ||
Z = np.random.rand(SIZE, SIZE, 3) * 255 | ||
img = Image.fromarray(Z.astype("uint8")).convert("RGB") | ||
img.save(path) | ||
|
||
|
||
if __name__ == "__main__": | ||
for split, paths in PATHS.items(): | ||
# remove old data | ||
if os.path.isdir(split): | ||
shutil.rmtree(split) | ||
for path in paths: | ||
os.makedirs(os.path.dirname(path), exist_ok=True) | ||
create_file(path) | ||
|
||
# compress data | ||
shutil.make_archive(split, "zip", ".", split) | ||
|
||
# Compute checksums | ||
with open(split + ".zip", "rb") as f: | ||
md5 = hashlib.md5(f.read()).hexdigest() | ||
print(f"{split}: {md5}") |
Binary file not shown.
Binary file added
BIN
+1.21 KB
tests/data/millionaid/test/agriculture_land/grassland/meadow/P0115918.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file added
BIN
+1.22 KB
tests/data/millionaid/train/agriculture_land/grassland/meadow/P0115918.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,64 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import os | ||
import shutil | ||
from pathlib import Path | ||
|
||
import matplotlib.pyplot as plt | ||
import pytest | ||
import torch | ||
import torch.nn as nn | ||
from _pytest.fixtures import SubRequest | ||
|
||
from torchgeo.datasets import MillionAID | ||
|
||
|
||
class TestMillionAID: | ||
@pytest.fixture( | ||
scope="class", params=zip(["train", "test"], ["multi-class", "multi-label"]) | ||
) | ||
def dataset(self, request: SubRequest) -> MillionAID: | ||
root = os.path.join("tests", "data", "millionaid") | ||
split, task = request.param | ||
transforms = nn.Identity() | ||
return MillionAID( | ||
root=root, split=split, task=task, transforms=transforms, checksum=True | ||
) | ||
|
||
def test_getitem(self, dataset: MillionAID) -> None: | ||
x = dataset[0] | ||
assert isinstance(x, dict) | ||
assert isinstance(x["image"], torch.Tensor) | ||
assert isinstance(x["label"], torch.Tensor) | ||
assert x["image"].shape[0] == 3 | ||
assert x["image"].ndim == 3 | ||
|
||
def test_len(self, dataset: MillionAID) -> None: | ||
assert len(dataset) == 2 | ||
|
||
def test_not_found(self, tmp_path: Path) -> None: | ||
with pytest.raises(RuntimeError, match="Dataset not found in"): | ||
MillionAID(str(tmp_path)) | ||
|
||
def test_not_extracted(self, tmp_path: Path) -> None: | ||
url = os.path.join("tests", "data", "millionaid", "train.zip") | ||
shutil.copy(url, tmp_path) | ||
MillionAID(str(tmp_path)) | ||
|
||
def test_corrupted(self, tmp_path: Path) -> None: | ||
with open(os.path.join(tmp_path, "train.zip"), "w") as f: | ||
f.write("bad") | ||
with pytest.raises(RuntimeError, match="Dataset found, but corrupted."): | ||
MillionAID(str(tmp_path), checksum=True) | ||
|
||
def test_plot(self, dataset: MillionAID) -> None: | ||
x = dataset[0].copy() | ||
dataset.plot(x, suptitle="Test") | ||
plt.close() | ||
|
||
def test_plot_prediction(self, dataset: MillionAID) -> None: | ||
x = dataset[0].copy() | ||
x["prediction"] = x["label"].clone() | ||
dataset.plot(x) | ||
plt.close() |
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.
Does anyone know the range of image sizes?