yuxuanw8 commited on
Commit
885925d
·
verified ·
1 Parent(s): ccf3a89

Upload EuroSAT.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. EuroSAT.py +12 -16
EuroSAT.py CHANGED
@@ -38,9 +38,9 @@ class EuroSATConfig(datasets.BuilderConfig):
38
 
39
  def update(self, **kwargs):
40
  """Update Config"""
41
- for key, value in kwargs.items():
42
- if hasattr(self, key):
43
- setattr(self, key, value)
44
 
45
  class EuroSAT(datasets.GeneratorBasedBuilder):
46
  VERSION = datasets.Version("1.0.0")
@@ -57,19 +57,15 @@ class EuroSAT(datasets.GeneratorBasedBuilder):
57
  HEIGHT = WIDTH = 64
58
 
59
  def __init__(self, *args, **kwargs):
60
- config_keywords = ['bands']
61
- config_kwargs = {k: v for k, v in kwargs.items() if k in config_keywords}
62
- for k, _ in config_kwargs.items():
63
- print(k)
64
-
65
- if 'config' in kwargs and isinstance(kwargs['config'], EuroSATConfig):
66
- kwargs['config'].update(**config_kwargs)
67
- else:
68
- config = EuroSATConfig(**config_kwargs)
69
- kwargs['config'] = config
70
 
71
- for k in config_kwargs:
72
- kwargs.pop(k, None)
73
 
74
  self.height = self.HEIGHT
75
  self.width = self.WIDTH
@@ -85,7 +81,7 @@ class EuroSAT(datasets.GeneratorBasedBuilder):
85
  "River",
86
  "SeaLake",
87
  ]
88
- self.num_channels = len(kwargs['config'].band_indices)
89
  super().__init__(*args, **kwargs)
90
  # if 'config' in kwargs:
91
  # user_config = kwargs['config']
 
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")
 
57
  HEIGHT = WIDTH = 64
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
71
  self.width = self.WIDTH
 
81
  "River",
82
  "SeaLake",
83
  ]
84
+ self.num_channels = len(self.config.band_indices)
85
  super().__init__(*args, **kwargs)
86
  # if 'config' in kwargs:
87
  # user_config = kwargs['config']