yuxuanw8 commited on
Commit
b1ab4a3
·
verified ·
1 Parent(s): 836b803

Upload EuroSAT.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. EuroSAT.py +12 -11
EuroSAT.py CHANGED
@@ -3,12 +3,10 @@ import datasets
3
  import numpy as np
4
  import tifffile
5
  import skimage.io as io
6
- import torch
7
 
8
  from typing import ClassVar
9
 
10
- class EuroSATConfig(datasets.BuilderConfig):
11
- all_band_names = (
12
  'B01',
13
  'B02',
14
  'B03',
@@ -24,8 +22,9 @@ class EuroSATConfig(datasets.BuilderConfig):
24
  'B12',
25
  )
26
 
27
- rgb_bands = ('B04', 'B03', 'B02')
28
 
 
29
  BAND_SETS: ClassVar[dict[str, tuple[str, ...]]] = {
30
  'all': all_band_names,
31
  'rgb': rgb_bands,
@@ -36,11 +35,11 @@ class EuroSATConfig(datasets.BuilderConfig):
36
  self.bands = bands
37
  self.band_indices = [int(self.all_band_names.index(b)) for b in bands if b in self.all_band_names]
38
 
39
- def update(self, **kwargs):
40
- """Update Config"""
41
- super().update(**kwargs)
42
- if 'bands' in kwargs:
43
- self.band_indices = [int(self.all_band_names.index(b)) for b in self.bands if b in self.all_band_names]
44
 
45
  class EuroSAT(datasets.GeneratorBasedBuilder):
46
  VERSION = datasets.Version("1.0.0")
@@ -58,13 +57,15 @@ class EuroSAT(datasets.GeneratorBasedBuilder):
58
 
59
  def __init__(self, *args, **kwargs):
60
  config = kwargs.pop('config', None)
 
61
 
62
- # Initialize config first
63
  if config:
64
  if isinstance(config, dict):
65
  for key, value in config.items():
66
- if key in ['bands']:
67
  kwargs[key] = value
 
 
68
 
69
 
70
  self.height = self.HEIGHT
 
3
  import numpy as np
4
  import tifffile
5
  import skimage.io as io
 
6
 
7
  from typing import ClassVar
8
 
9
+ all_band_names = (
 
10
  'B01',
11
  'B02',
12
  'B03',
 
22
  'B12',
23
  )
24
 
25
+ rgb_bands = ('B04', 'B03', 'B02')
26
 
27
+ class EuroSATConfig(datasets.BuilderConfig):
28
  BAND_SETS: ClassVar[dict[str, tuple[str, ...]]] = {
29
  'all': all_band_names,
30
  'rgb': rgb_bands,
 
35
  self.bands = bands
36
  self.band_indices = [int(self.all_band_names.index(b)) for b in bands if b in self.all_band_names]
37
 
38
+ # def update(self, **kwargs):
39
+ # """Update Config"""
40
+ # super().update(**kwargs)
41
+ # if 'bands' in kwargs:
42
+ # self.band_indices = [int(self.all_band_names.index(b)) for b in self.bands if b in all_band_names]
43
 
44
  class EuroSAT(datasets.GeneratorBasedBuilder):
45
  VERSION = datasets.Version("1.0.0")
 
57
 
58
  def __init__(self, *args, **kwargs):
59
  config = kwargs.pop('config', None)
60
+ config_keywords = ['bands']
61
 
 
62
  if config:
63
  if isinstance(config, dict):
64
  for key, value in config.items():
65
+ if key in config_keywords:
66
  kwargs[key] = value
67
+ if key in ['bands']:
68
+ kwargs['band_indices'] = [int(all_band_names.index(b)) for b in kwargs['bands'] if b in all_band_names]
69
 
70
 
71
  self.height = self.HEIGHT