Upload senbench_so2sat_wrapper.py
Browse files
so2sat_s1s2/senbench_so2sat_wrapper.py
CHANGED
|
@@ -14,7 +14,7 @@ Path: TypeAlias = str | os.PathLike[str]
|
|
| 14 |
|
| 15 |
class SenBenchSo2Sat(So2Sat):
|
| 16 |
|
| 17 |
-
versions = ('
|
| 18 |
filenames_by_version: ClassVar[dict[str, dict[str, str]]] = {
|
| 19 |
# '2': {
|
| 20 |
# 'train': 'training.h5',
|
|
@@ -23,11 +23,16 @@ class SenBenchSo2Sat(So2Sat):
|
|
| 23 |
# },
|
| 24 |
# '3_random': {'train': 'random/training.h5', 'test': 'random/testing.h5'},
|
| 25 |
# '3_block': {'train': 'block/training.h5', 'test': 'block/testing.h5'},
|
| 26 |
-
'3_culture_10': {
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
}
|
| 32 |
|
| 33 |
classes = (
|
|
@@ -86,7 +91,7 @@ class SenBenchSo2Sat(So2Sat):
|
|
| 86 |
def __init__(
|
| 87 |
self,
|
| 88 |
root: Path = 'data',
|
| 89 |
-
version: str = '
|
| 90 |
split: str = 'train',
|
| 91 |
bands: Sequence[str] = BAND_SETS['s2'], # only supported bands now
|
| 92 |
transforms: Callable[[dict[str, Tensor]], dict[str, Tensor]] | None = None,
|
|
@@ -174,52 +179,17 @@ class SenBenchSo2Sat(So2Sat):
|
|
| 174 |
|
| 175 |
|
| 176 |
class ClsDataAugmentation(torch.nn.Module):
|
| 177 |
-
BAND_STATS = {
|
| 178 |
-
'mean': {
|
| 179 |
-
'B01': 1353.72696296,
|
| 180 |
-
'B02': 1117.20222222,
|
| 181 |
-
'B03': 1041.8842963,
|
| 182 |
-
'B04': 946.554,
|
| 183 |
-
'B05': 1199.18896296,
|
| 184 |
-
'B06': 2003.00696296,
|
| 185 |
-
'B07': 2374.00874074,
|
| 186 |
-
'B08': 2301.22014815,
|
| 187 |
-
'B8A': 2599.78311111,
|
| 188 |
-
'B09': 732.18207407,
|
| 189 |
-
'B10': 12.09952894,
|
| 190 |
-
'B11': 1820.69659259,
|
| 191 |
-
'B12': 1118.20259259,
|
| 192 |
-
#'VV': -12.54847273,
|
| 193 |
-
#'VH': -20.19237134
|
| 194 |
-
},
|
| 195 |
-
'std': {
|
| 196 |
-
'B01': 897.27143653,
|
| 197 |
-
'B02': 736.01759721,
|
| 198 |
-
'B03': 684.77615743,
|
| 199 |
-
'B04': 620.02902871,
|
| 200 |
-
'B05': 791.86263829,
|
| 201 |
-
'B06': 1341.28018273,
|
| 202 |
-
'B07': 1595.39989386,
|
| 203 |
-
'B08': 1545.52915718,
|
| 204 |
-
'B8A': 1750.12066835,
|
| 205 |
-
'B09': 475.11595216,
|
| 206 |
-
'B10': 98.26600935,
|
| 207 |
-
'B11': 1216.48651476,
|
| 208 |
-
'B12': 736.6981037,
|
| 209 |
-
#'VV': 5.25697717,
|
| 210 |
-
#'VH': 5.91150917
|
| 211 |
-
}
|
| 212 |
-
}
|
| 213 |
|
| 214 |
-
def __init__(self, split, size,
|
| 215 |
super().__init__()
|
| 216 |
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
mean.
|
| 222 |
-
std.
|
|
|
|
| 223 |
mean = torch.Tensor(mean)
|
| 224 |
std = torch.Tensor(std)
|
| 225 |
|
|
@@ -227,6 +197,7 @@ class ClsDataAugmentation(torch.nn.Module):
|
|
| 227 |
self.transform = torch.nn.Sequential(
|
| 228 |
K.Normalize(mean=mean, std=std),
|
| 229 |
K.Resize(size=size, align_corners=True),
|
|
|
|
| 230 |
K.RandomHorizontalFlip(p=0.5),
|
| 231 |
K.RandomVerticalFlip(p=0.5),
|
| 232 |
)
|
|
@@ -250,10 +221,11 @@ class SenBenchSo2SatDataset:
|
|
| 250 |
self.root_dir = config.data_path
|
| 251 |
self.bands = config.band_names
|
| 252 |
self.version = config.version
|
|
|
|
| 253 |
|
| 254 |
def create_dataset(self):
|
| 255 |
-
train_transform = ClsDataAugmentation(split="train", size=self.img_size,
|
| 256 |
-
eval_transform = ClsDataAugmentation(split="test", size=self.img_size,
|
| 257 |
|
| 258 |
dataset_train = SenBenchSo2Sat(
|
| 259 |
root=self.root_dir, version=self.version, split="train", bands=self.bands, transforms=train_transform
|
|
|
|
| 14 |
|
| 15 |
class SenBenchSo2Sat(So2Sat):
|
| 16 |
|
| 17 |
+
versions = ('4_senbench')
|
| 18 |
filenames_by_version: ClassVar[dict[str, dict[str, str]]] = {
|
| 19 |
# '2': {
|
| 20 |
# 'train': 'training.h5',
|
|
|
|
| 23 |
# },
|
| 24 |
# '3_random': {'train': 'random/training.h5', 'test': 'random/testing.h5'},
|
| 25 |
# '3_block': {'train': 'block/training.h5', 'test': 'block/testing.h5'},
|
| 26 |
+
# '3_culture_10': {
|
| 27 |
+
# 'train': 'culture_10/train-new.h5',
|
| 28 |
+
# 'val': 'culture_10/val-new.h5',
|
| 29 |
+
# 'test': 'culture_10/test-new.h5',
|
| 30 |
+
# },
|
| 31 |
+
'4_senbench': {
|
| 32 |
+
'train': 'train-new.h5',
|
| 33 |
+
'val': 'val-new.h5',
|
| 34 |
+
'test': 'test-new.h5'
|
| 35 |
+
}
|
| 36 |
}
|
| 37 |
|
| 38 |
classes = (
|
|
|
|
| 91 |
def __init__(
|
| 92 |
self,
|
| 93 |
root: Path = 'data',
|
| 94 |
+
version: str = '4_senbench', # only supported version now
|
| 95 |
split: str = 'train',
|
| 96 |
bands: Sequence[str] = BAND_SETS['s2'], # only supported bands now
|
| 97 |
transforms: Callable[[dict[str, Tensor]], dict[str, Tensor]] | None = None,
|
|
|
|
| 179 |
|
| 180 |
|
| 181 |
class ClsDataAugmentation(torch.nn.Module):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
+
def __init__(self, split, size, band_stats):
|
| 184 |
super().__init__()
|
| 185 |
|
| 186 |
+
if band_stats is not None:
|
| 187 |
+
mean = band_stats['mean']
|
| 188 |
+
std = band_stats['std']
|
| 189 |
+
else:
|
| 190 |
+
mean = [0.0]
|
| 191 |
+
std = [1.0]
|
| 192 |
+
|
| 193 |
mean = torch.Tensor(mean)
|
| 194 |
std = torch.Tensor(std)
|
| 195 |
|
|
|
|
| 197 |
self.transform = torch.nn.Sequential(
|
| 198 |
K.Normalize(mean=mean, std=std),
|
| 199 |
K.Resize(size=size, align_corners=True),
|
| 200 |
+
#K.RandomResizedCrop(size=size, scale=(0.8,1.0)),
|
| 201 |
K.RandomHorizontalFlip(p=0.5),
|
| 202 |
K.RandomVerticalFlip(p=0.5),
|
| 203 |
)
|
|
|
|
| 221 |
self.root_dir = config.data_path
|
| 222 |
self.bands = config.band_names
|
| 223 |
self.version = config.version
|
| 224 |
+
self.band_stats = config.band_stats
|
| 225 |
|
| 226 |
def create_dataset(self):
|
| 227 |
+
train_transform = ClsDataAugmentation(split="train", size=self.img_size, band_stats=self.band_stats)
|
| 228 |
+
eval_transform = ClsDataAugmentation(split="test", size=self.img_size, band_stats=self.band_stats)
|
| 229 |
|
| 230 |
dataset_train = SenBenchSo2Sat(
|
| 231 |
root=self.root_dir, version=self.version, split="train", bands=self.bands, transforms=train_transform
|