Datasets:

ArXiv:
yuxuanw8 commited on
Commit
bbc5eba
·
verified ·
1 Parent(s): 605b0c0

Upload SSL4EO-L-Benchmark.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. SSL4EO-L-Benchmark.py +16 -2
SSL4EO-L-Benchmark.py CHANGED
@@ -7,7 +7,13 @@ import tifffile
7
  import pandas as pd
8
  import numpy as np
9
 
10
- from GFMBench.datasets.base_dataset import GFMBenchDataset
 
 
 
 
 
 
11
 
12
  S2_MEAN = [752.40087073, 884.29673756, 1144.16202635, 1297.47289228, 1624.90992062, 2194.6423161, 2422.21248945, 2581.64687018, 2368.51236873, 1805.06846033]
13
 
@@ -71,6 +77,13 @@ class SSL4EOLBenchmarkDataset(datasets.GeneratorBasedBuilder):
71
  self.NUM_CHANNELS = num_channels[name] if name else num_channels['etm_sr_cdl']
72
  self.metadata = metadata[name] if name else metadata['etm_sr_cdl']
73
 
 
 
 
 
 
 
 
74
  super().__init__(*args, **kwargs)
75
 
76
  def _info(self):
@@ -86,7 +99,7 @@ class SSL4EOLBenchmarkDataset(datasets.GeneratorBasedBuilder):
86
  "spatial_resolution": datasets.Value("int32"),
87
  }),
88
  )
89
-
90
  def _split_generators(self, dl_manager):
91
  if isinstance(self.DATA_URL, list):
92
  downloaded_files = dl_manager.download(self.DATA_URL)
@@ -137,6 +150,7 @@ class SSL4EOLBenchmarkDataset(datasets.GeneratorBasedBuilder):
137
 
138
  label_path = os.path.join(data_dir, row.label_path)
139
  label = self._read_image(label_path).astype(np.int32)
 
140
 
141
  sample = {
142
  "optical": optical,
 
7
  import pandas as pd
8
  import numpy as np
9
 
10
+ from torchgeo.datasets.cdl import CDL
11
+ from torchgeo.datasets.nlcd import NLCD
12
+
13
+ CMAPS = {
14
+ 'nlcd': NLCD.cmap,
15
+ 'cdl': CDL.cmap,
16
+ }
17
 
18
  S2_MEAN = [752.40087073, 884.29673756, 1144.16202635, 1297.47289228, 1624.90992062, 2194.6423161, 2422.21248945, 2581.64687018, 2368.51236873, 1805.06846033]
19
 
 
77
  self.NUM_CHANNELS = num_channels[name] if name else num_channels['etm_sr_cdl']
78
  self.metadata = metadata[name] if name else metadata['etm_sr_cdl']
79
 
80
+ product = name.split('_')[-1]
81
+ cmap = CMAPS[product]
82
+ classes = list(cmap.keys())
83
+ ordinal_map = np.zeros(max(cmap.keys()) + 1, dtype=np.int64)
84
+ for v, k in enumerate(classes):
85
+ ordinal_map[k] = v
86
+
87
  super().__init__(*args, **kwargs)
88
 
89
  def _info(self):
 
99
  "spatial_resolution": datasets.Value("int32"),
100
  }),
101
  )
102
+
103
  def _split_generators(self, dl_manager):
104
  if isinstance(self.DATA_URL, list):
105
  downloaded_files = dl_manager.download(self.DATA_URL)
 
150
 
151
  label_path = os.path.join(data_dir, row.label_path)
152
  label = self._read_image(label_path).astype(np.int32)
153
+ label = self.ordinal_map[label]
154
 
155
  sample = {
156
  "optical": optical,