Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
isaaccorley committed Jul 29, 2021
1 parent 7ebf658 commit 3edfb0b
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,35 @@ x: dict(
"""
```

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

<img src="./assets/levircd_plus.png" width="750px"></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 dataset can be downloaded (3.6GB) using `scripts/download_levircd_plus.sh` and instantiated below:

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

transform = Compose([ToTensor()])

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

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

### Remote Sensing Visual Question Answering (RSVQA) Low Resolution (LR)

<img src="./assets/rsvqa_lr.png" width="850px"></img>
Expand Down
4 changes: 3 additions & 1 deletion torchrs/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
from .resisc45 import RESISC45
from .rsicd import RSICD
from .oscd import OSCD
from .levircd import LEVIRCD_Plus


__all__ = [
"PROBAV", "ETCI2021", "RSVQALR", "EuroSATRGB", "EuroSATMS",
"RESISC45", "RSICD", "OSCD"
"RESISC45", "RSICD", "OSCD", "LEVIRCD_Plus"
]
62 changes: 62 additions & 0 deletions torchrs/datasets/levircd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import os
from glob import glob
from typing import Dict

import torch
import numpy as np
from PIL import Image

from torchrs.transforms import Compose, ToTensor


class LEVIRCD_Plus(torch.utils.data.Dataset):
""" LEVIR-CD+ dataset from 'S2Looking: A Satellite Side-Looking
Dataset for Building Change Detection', Shen at al. (2021)
https://arxiv.org/abs/2107.09244
'LEVIR-CD+ contains more than 985 VHR (0.5m/pixel) bitemporal Google
Earth images with dimensions of 1024x1024 pixels. These bitemporal images
are from 20 different regions located in several cities in the state of
Texas in the USA. The capture times of the image data vary from 2002 to
2020. Images of different regions were taken at different times. The
bitemporal images have a time span of 5 years.'
"""
def __init__(
self,
root: str = ".data/levircd_plus",
split: str = "train",
transform: Compose = Compose([ToTensor()]),
):
assert split in ["train", "test"]
self.root = root
self.transform = transform
self.files = self.load_files(root, split)

@staticmethod
def load_files(root: str, split: str):
files = []
images = glob(os.path.join(root, split, "A", "*.png"))
images = sorted([os.path.basename(image) for image in images])
for image in images:
image1 = os.path.join(root, split, "A", image)
image2 = os.path.join(root, split, "B", image)
mask = os.path.join(root, split, "label", image)
files.append(dict(image1=image1, image2=image2, mask=mask))
return files

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

def __getitem__(self, idx: int) -> Dict:
""" Returns a dict containing x, mask, region, dates
x: (2, 13, h, w)
mask: (1, h, w)
"""
files = self.files[idx]
mask = np.array(Image.open(files["mask"]))
mask = np.clip(mask, 0, 1)
image1 = np.array(Image.open(files["image1"]))
image2 = np.array(Image.open(files["image2"]))
image1, image2, mask = self.transform([image1, image2, mask])
x = torch.stack([image1, image2], dim=0)
return dict(x=x, mask=mask)

0 comments on commit 3edfb0b

Please sign in to comment.