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

Refactor datamodule/model testing #329

Merged
merged 21 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update OSCD training data
  • Loading branch information
adamjstewart committed Dec 28, 2021
commit d3dbaa79635dbb17f730abaa85982fe26d378a23
23 changes: 18 additions & 5 deletions tests/data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,28 @@ VisionDataset data can be created like so.
### RGB images

```python
import numpy as np
from PIL import Image

img = Image.new("RGB", (64, 64))
DTYPE = np.uint8
SIZE = 64

arr = np.random.randint(np.iinfo(DTYPE).max, size=(SIZE, SIZE, 3), dtype=DTYPE)
img = Image.fromarray(arr)
img.save("01.png")
```

### Grayscale images

```python
import numpy as np
from PIL import Image

img = Image.new("L", (64, 64))
DTYPE = np.uint8
SIZE = 64

arr = np.random.randint(np.iinfo(DTYPE).max, size=(SIZE, SIZE), dtype=DTYPE)
img = Image.fromarray(arr)
img.save("02.jpg")
```

Expand All @@ -84,9 +94,12 @@ wavfile.write("01.wav", rate=22050, data=audio)
import h5py
import numpy as np

num_classes = 10
images = np.random.randint(256, size=(64, 64, 3), dtype=np.uint8)
masks = np.random.randint(num_classes, size=(64, 64), dtype=np.uint8)
DTYPE = np.uint8
SIZE = 64
NUM_CLASSES = 10

images = np.random.randint(np.iinfo(DTYPE).max, size=(SIZE, SIZE, 3), dtype=DTYPE)
masks = np.random.randint(NUM_CLASSES, size=(SIZE, SIZE), dtype=DTYPE)
with h5py.File("data.hdf5", "w") as f:
f.create_dataset("images", data=images)
f.create_dataset("masks", data=masks)
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
date_1: 20151211
date_2: 20180330
date_1: 20161130
date_2: 20170829
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 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 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 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 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 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 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 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 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.
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.
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.
84 changes: 84 additions & 0 deletions tests/data/oscd/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/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 = 64 # image width/height

np.random.seed(0)

directories = [
"Onera Satellite Change Detection dataset - Images",
"Onera Satellite Change Detection dataset - Train Labels",
"Onera Satellite Change Detection dataset - Test Labels",
]
bands = [
"B01",
"B02",
"B03",
"B04",
"B05",
"B06",
"B07",
"B08",
"B09",
"B10",
"B11",
"B12",
"B8A",
]

# Remove old data
for directory in directories:
filename = f"{directory}.zip"

if os.path.exists(filename):
os.remove(filename)
if os.path.exists(directory):
shutil.rmtree(directory)

# Create images
for subdir in ["train1", "train2", "test"]:
for rect in ["imgs_1_rect", "imgs_2_rect"]:
directory = os.path.join(directories[0], subdir, rect)
os.makedirs(directory)

for band in bands:
filename = os.path.join(directory, f"{band}.tif")
arr = np.random.randint(
np.iinfo(np.uint16).max, size=(SIZE, SIZE), dtype=np.uint16
)
img = Image.fromarray(arr)
img.save(filename)

filename = os.path.join(directories[0], subdir, "dates.txt")
with open(filename, "w") as f:
for key, value in [("date_1", "20161130"), ("date_2", "20170829")]:
f.write(f"{key}: {value}\n")

# Create labels
for i, subdir in [(1, "train1"), (1, "train2"), (2, "test")]:
directory = os.path.join(directories[i], subdir, "cm")
os.makedirs(directory)
filename = os.path.join(directory, "cm.png")
arr = np.random.randint(np.iinfo(np.uint8).max, size=(SIZE, SIZE), dtype=np.uint8)
img = Image.fromarray(arr)
img.save(filename)

for directory in directories:
# Compress data
shutil.make_archive(directory, "zip", ".", directory)

# Compute checksums
filename = f"{directory}.zip"
with open(filename, "rb") as f:
md5 = hashlib.md5(f.read()).hexdigest()
print(repr(filename) + ": " + repr(md5) + ",")