forked from isaaccorley/torchrs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added hkh dataset datamodule and download script
- Loading branch information
1 parent
4c5b9fb
commit e4b14f7
Showing
9 changed files
with
173 additions
and
42 deletions.
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
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,5 @@ | ||
pip install gdown | ||
mkdir -p .data | ||
gdown --id 1cvjfe_MZJI9HXwkRgoQbSCH55qQd6Esm | ||
unzip hkh_glacier_mapping.zip -d .data/ | ||
rm hkh_glacier_mapping.zip |
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,61 @@ | ||
import os | ||
from glob import glob | ||
from typing import List, Dict | ||
|
||
import torch | ||
import numpy as np | ||
|
||
from torchrs.transforms import Compose, ToTensor | ||
|
||
|
||
class HKHGlacierMapping(torch.utils.data.Dataset): | ||
""" Hindu Kush Himalayas (HKH) Glacier Mapping dataset | ||
https://lila.science/datasets/hkh-glacier-mapping | ||
'We also provide 14190 numpy patches. The numpy patches are all of size 512x512x15 and | ||
corresponding 512x512x2 pixel-wise mask labels; the two channels in the pixel-wise masks | ||
correspond to clean-iced and debris-covered glaciers. Patches' geolocation information, | ||
time stamps, source Landsat IDs, and glacier density are available in a geojson metadata file.' | ||
""" | ||
bands = [ | ||
"LE7 B1 (blue)", | ||
"LE7 B2 (green)", | ||
"LE7 B3 (red)", | ||
"LE7 B4 (near infrared)", | ||
"LE7 B5 (shortwave infrared 1)", | ||
"LE7 B6_VCID_1 (low-gain thermal infrared)", | ||
"LE7 B6_VCID_2 (high-gain thermal infrared)", | ||
"LE7 B7 (shortwave infrared 2)", | ||
"LE7 B8 (panchromatic)", | ||
"LE7 BQA (quality bitmask)", | ||
"NDVI (vegetation index)", | ||
"NDSI (snow index)", | ||
"NDWI (water index)", | ||
"SRTM 90 elevation", | ||
"SRTM 90 slope" | ||
] | ||
|
||
def __init__( | ||
self, | ||
root: str = ".data/hkh_glacier_mapping", | ||
transform: Compose = Compose([ToTensor()]), | ||
): | ||
self.transform = transform | ||
self.images = self.load_images(root) | ||
|
||
@staticmethod | ||
def load_images(path: str) -> List[Dict]: | ||
images = sorted(glob(os.path.join(path, "images", "*.npy"))) | ||
masks = sorted(glob(os.path.join(path, "masks", "*.npy"))) | ||
return [dict(image=image, mask=mask) for image, mask in zip(images, masks)] | ||
|
||
def __len__(self) -> int: | ||
return len(self.images) | ||
|
||
def __getitem__(self, idx: int) -> Dict[str, torch.Tensor]: | ||
image_path, target_path = self.images[idx]["image"], self.images[idx]["mask"] | ||
x, y = np.load(image_path), np.load(target_path) | ||
y0, y1 = y[..., 0], y[..., 1] | ||
x, y0, y1 = self.transform([x, y0, y1]) | ||
return dict(x=x, clean_ice_mask=y0, debris_covered_mask=y1) |
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,25 @@ | ||
from typing import Optional | ||
|
||
from torchrs.transforms import Compose, ToTensor | ||
from torchrs.datasets.utils import dataset_split | ||
from torchrs.train.datamodules import BaseDataModule | ||
from torchrs.datasets import HKHGlacierMapping | ||
|
||
|
||
class HKHGlacierMappingDataModule(BaseDataModule): | ||
|
||
def __init__( | ||
self, | ||
root: str = ".data/hkh_glacier_mapping", | ||
transform: Compose = Compose([ToTensor()]), | ||
*args, **kwargs | ||
): | ||
super().__init__(*args, **kwargs) | ||
self.root = root | ||
self.transform = transform | ||
|
||
def setup(self, stage: Optional[str] = None): | ||
dataset = HKHGlacierMapping(root=self.root, transform=self.transform) | ||
self.train_dataset, self.val_dataset, self.test_dataset = dataset_split( | ||
dataset, val_pct=self.val_split, test_pct=self.test_split | ||
) |