Skip to content

Commit

Permalink
final update
Browse files Browse the repository at this point in the history
  • Loading branch information
isaaccorley committed Jul 29, 2021
1 parent 3be99cf commit a8f964d
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 33 deletions.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pip install git+https://github.com/isaaccorley/torchrs
* [PROBA-V Super Resolution](https://github.com/isaaccorley/torchrs#proba-v-super-resolution)
* [ETCI 2021 Flood Detection](https://github.com/isaaccorley/torchrs#etci-2021-flood-detection)
* [Onera Satellite Change Detection (OSCD)](https://github.com/isaaccorley/torchrs#onera-satellite-change-detection-oscd)
* [Satellite Side-Looking (S2Looking) Change Detection](https://github.com/isaaccorley/torchrs#satellite-side-looking-s2looking-change-detection)
* [LEVIR Change Detection+ (LEVIR-CD+)](https://github.com/isaaccorley/torchrs#levir-change-detection-levir-cd-)
* [Remote Sensing Visual Question Answering (RSVQA) Low Resolution (LR)](https://github.com/isaaccorley/torchrs#remote-sensing-visual-question-answering-rsvqa-low-resolution-lr)
* [Remote Sensing Image Captioning Dataset (RSICD)](https://github.com/isaaccorley/torchrs#remote-sensing-image-captioning-dataset-rsicd)
Expand Down Expand Up @@ -122,11 +123,42 @@ x: dict(
"""
```


### Satellite Side-Looking (S2Looking) Change Detection

<img src="./assets/s2looking.png" width="500px"></img>

The [S2Looking](https://github.com/AnonymousForACMMM/Dataset) dataset, proposed in ["S2Looking: A Satellite Side-Looking Dataset for Building Change Detection", Shen et al.](https://arxiv.org/abs/2107.09244) is a rural building Change Detection dataset of 5,000 very high resolution (VHR) 0.5-0.8m registered RGB image pairs of varying off-nadir angles taken by the (Gaogen (GF))[https://earth.esa.int/web/eoportal/satellite-missions/g/gaofen-1], (SuperView (SV))[https://eos.com/find-satellite/superview-1/], and (BeiJing-2 (BJ-2))[https://space.oscar.wmo.int/satelliteprogrammes/view/beijing_2] satellites. The dataset contains separate new and demolished building masks from regions all over the Earth a time span of 1-3 years. This dataset was proposed along with the LEVIR-CD+ dataset and is considered difficult due to the rural locations and off-nadir angles.

The dataset can be downloaded (11GB) using `scripts/download_s2looking.sh` and instantiated below:

```python
from torchrs.transforms import Compose, ToTensor
from torchrs.datasets import S2Looking

transform = Compose([ToTensor()])

dataset = S2Looking(
root="path/to/dataset/",
split="train", # or 'val', 'test'
transform=transform,
)

x = dataset[0]
"""
x: dict(
x: (2, 3, 1024, 1024)
build_mask: (1, 1024, 1024),
demolish_mask: (1, 1024, 1024)
)
"""
```

### LEVIR Change Detection+ (LEVIR-CD+)

<img src="./assets/levircd_plus.png" width="600px"></img>

The [LEVIR-CD+](https://github.com/AnonymousForACMMM/Dataset) dataset, proposed in ["S2Looking: A Satellite Side-Looking Dataset for Building Change Detection", Shen et al.](https://arxiv.org/abs/2107.09244) is an urban Change Detection dataset of 985 very high resolution (VHR) 0.5m RGB image pairs extracted from Google Earth. The dataset contains building/land use change masks from 20 different regions of Texas between 2002-2020 with a temporal difference of 5 years.
The [LEVIR-CD+](https://github.com/AnonymousForACMMM/Dataset) dataset, proposed in ["S2Looking: A Satellite Side-Looking Dataset for Building Change Detection", Shen et al.](https://arxiv.org/abs/2107.09244) is an urban building Change Detection dataset of 985 very high resolution (VHR) 0.5m RGB image pairs extracted from Google Earth. The dataset contains building/land use change masks from 20 different regions of Texas between 2002-2020 with a time span of 5 years. This dataset was proposed along with the S2Looking dataset and is considered the easier version due to the urban locations and near-nadir angles.

The dataset can be downloaded (3.6GB) using `scripts/download_levircd_plus.sh` and instantiated below:

Expand Down
Binary file added assets/s2looking.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion torchrs/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
from .resisc45 import RESISC45
from .rsicd import RSICD
from .oscd import OSCD
from .s2looking import S2Looking
from .levircd import LEVIRCD_Plus


__all__ = [
"PROBAV", "ETCI2021", "RSVQALR", "EuroSATRGB", "EuroSATMS",
"RESISC45", "RSICD", "OSCD", "LEVIRCD_Plus"
"RESISC45", "RSICD", "OSCD", "S2Looking", "LEVIRCD_Plus"
]
2 changes: 1 addition & 1 deletion torchrs/datasets/levircd.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __len__(self) -> int:
return len(self.files)

def __getitem__(self, idx: int) -> Dict:
""" Returns a dict containing x, mask, region, dates
""" Returns a dict containing x, mask
x: (2, 13, h, w)
mask: (1, h, w)
"""
Expand Down
2 changes: 1 addition & 1 deletion torchrs/datasets/oscd.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __len__(self) -> int:
return len(self.regions)

def __getitem__(self, idx: int) -> Dict:
""" Returns a dict containing x, mask, region, dates
""" Returns a dict containing x, mask
x: (2, 13, h, w)
mask: (1, h, w)
"""
Expand Down
53 changes: 24 additions & 29 deletions torchrs/datasets/s2looking.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Dict

import torch
import tifffile
import numpy as np
from PIL import Image

Expand All @@ -29,44 +28,40 @@ def __init__(
split: str = "train",
transform: Compose = Compose([ToTensor()]),
):
assert split in ["train", "test"]
assert split in ["train", "val", "test"]
self.root = root
self.transform = transform
self.files = self.load_files(root, split)

@staticmethod
def load_files(root: str, split: str):
images = []
labels_root = os.path.join(root, f"{split}_labels")
images_root = os.path.join(root, "images")
folders = glob(os.path.join(labels_root, "*/"))
for folder in folders:
region = folder.split(os.sep)[-2]
mask = os.path.join(labels_root, region, "cm", "cm.png")
images1 = glob(os.path.join(images_root, region, "imgs_1_rect", "*.tif"))
images2 = glob(os.path.join(images_root, region, "imgs_2_rect", "*.tif"))
images1 = sorted(images1, key=sort)
images2 = sorted(images2, key=sort)
with open(os.path.join(images_root, region, "dates.txt")) as f:
dates = tuple([line.split()[-1] for line in f.read().strip().splitlines()])

regions.append(dict(region=region, images1=images1, images2=images2, mask=mask, dates=dates))

return regions
files = []
images = glob(os.path.join(root, split, "Image1", "*.png"))
images = sorted([os.path.basename(image) for image in images])
for image in images:
image1 = os.path.join(root, split, "Image1", image)
image2 = os.path.join(root, split, "Image2", image)
build_mask = os.path.join(root, split, "label1", image)
demo_mask = os.path.join(root, split, "label2", image)
files.append(dict(image1=image1, image2=image2, build_mask=build_mask, demolish_mask=demo_mask))
return files

def __len__(self) -> int:
return len(self.regions)
return len(self.files)

def __getitem__(self, idx: int) -> Dict:
""" Returns a dict containing x, mask, region, dates
""" Returns a dict containing x, mask
x: (2, 13, h, w)
mask: (1, h, w)
build_mask: (1, h, w)
demolish_mask: (1, h, w)
"""
region = self.regions[idx]
mask = np.array(Image.open(region["mask"]))
mask[mask == 255] = 1
image1 = np.stack([tifffile.imread(path) for path in region["images1"]], axis=0)
image2 = np.stack([tifffile.imread(path) for path in region["images2"]], axis=0)
image1, image2, mask = self.transform([image1, image2, mask])
files = self.files[idx]
build_mask = np.array(Image.open(files["build_mask"]))
demo_mask = np.array(Image.open(files["demolish_mask"]))
build_mask = np.clip(build_mask.mean(axis=-1), 0, 1).astype("uint8")
demo_mask = np.clip(demo_mask.mean(axis=-1), 0, 1).astype("uint8")
image1 = np.array(Image.open(files["image1"]))
image2 = np.array(Image.open(files["image2"]))
image1, image2, build_mask, demo_mask = self.transform([image1, image2, build_mask, demo_mask])
x = torch.stack([image1, image2], dim=0)
return dict(x=x, mask=mask)
return dict(x=x, build_mask=build_mask, demolish_mask=demo_mask)

0 comments on commit a8f964d

Please sign in to comment.