yuxuanw8 commited on
Commit
5b22784
·
verified ·
1 Parent(s): f9f2597

Upload EuroSAT.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. EuroSAT.py +35 -15
EuroSAT.py CHANGED
@@ -36,6 +36,12 @@ 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
  class EuroSAT(datasets.GeneratorBasedBuilder):
40
  VERSION = datasets.Version("1.0.0")
41
 
@@ -48,9 +54,23 @@ class EuroSAT(datasets.GeneratorBasedBuilder):
48
 
49
  DEFAULT_CONFIG_NAME = "default"
50
 
 
 
51
  def __init__(self, *args, **kwargs):
52
- self.height = 64
53
- self.width = 64
 
 
 
 
 
 
 
 
 
 
 
 
54
  self.labels = [
55
  "AnnualCrop",
56
  "Forest",
@@ -63,22 +83,22 @@ class EuroSAT(datasets.GeneratorBasedBuilder):
63
  "River",
64
  "SeaLake",
65
  ]
66
- # self.label_ids = {label: idx for idx, label in enumerate(self.labels)}
67
- if 'config' in kwargs:
68
- user_config = kwargs['config']
69
- if isinstance(user_config, dict):
70
- for key, value in user_config.items():
71
- if hasattr(self.config, key):
72
- setattr(self.config, key, value)
73
- else:
74
- raise ValueError("check user_config, it should be a dict")
75
- else:
76
- raise ValueError("config is not specified in arguments")
77
-
78
  super().__init__(*args, **kwargs)
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
  def _info(self):
81
- self.num_channels = self.config.band_indices.shape[0] # TODO: check out this
82
  return datasets.DatasetInfo(
83
  features=datasets.Features({
84
  "image": datasets.Array3D(shape=(self.num_channels, self.height, self.width), dtype="float32"),
 
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
+ 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")
47
 
 
54
 
55
  DEFAULT_CONFIG_NAME = "default"
56
 
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
+
63
+ if 'config' in kwargs and isinstance(kwargs['config'], EuroSATConfig):
64
+ kwargs['config'].update(**config_kwargs)
65
+ else:
66
+ config = EuroSATConfig(**config_kwargs)
67
+ kwargs['config'] = config
68
+
69
+ for k in config_kwargs:
70
+ kwargs.pop(k, None)
71
+
72
+ self.height = self.HEIGHT
73
+ self.width = self.WIDTH
74
  self.labels = [
75
  "AnnualCrop",
76
  "Forest",
 
83
  "River",
84
  "SeaLake",
85
  ]
86
+ self.num_channels = len(kwargs['config'].band_indices)
 
 
 
 
 
 
 
 
 
 
 
87
  super().__init__(*args, **kwargs)
88
+ # if 'config' in kwargs:
89
+ # user_config = kwargs['config']
90
+ # if isinstance(user_config, dict):
91
+ # for key, value in user_config.items():
92
+ # if hasattr(self.config, key):
93
+ # setattr(self.config, key, value)
94
+ # else:
95
+ # raise ValueError("check user_config, it should be a dict")
96
+ # else:
97
+ # raise ValueError("config is not specified in arguments")
98
+
99
+
100
 
101
  def _info(self):
 
102
  return datasets.DatasetInfo(
103
  features=datasets.Features({
104
  "image": datasets.Array3D(shape=(self.num_channels, self.height, self.width), dtype="float32"),