gdamms commited on
Commit
0f840bd
·
1 Parent(s): 6fc135c

feat: DS4 and better infos

Browse files
Files changed (1) hide show
  1. ornithoscope.py +43 -13
ornithoscope.py CHANGED
@@ -90,7 +90,6 @@ class OrnithoscopeConfig(datasets.BuilderConfig):
90
 
91
  def __init__(
92
  self,
93
- classes: list[str],
94
  train_json: str,
95
  validation_json: str,
96
  test_json: str,
@@ -106,11 +105,27 @@ class OrnithoscopeConfig(datasets.BuilderConfig):
106
  **kwargs: keyword arguments forwarded to super.
107
  """
108
  super().__init__(version=datasets.Version("1.0.0"), **kwargs)
109
- self.classes = classes
 
 
 
 
110
  self.train_json = train_json
111
  self.validation_json = validation_json
112
  self.test_json = test_json
113
 
 
 
 
 
 
 
 
 
 
 
 
 
114
 
115
  class Ornithoscope(datasets.GeneratorBasedBuilder):
116
 
@@ -119,28 +134,43 @@ class Ornithoscope(datasets.GeneratorBasedBuilder):
119
  OrnithoscopeConfig(
120
  name="DS3",
121
  description="The main dataset.",
122
- classes=[], # TODO
123
  train_json="sets/DS3_train.json",
124
  validation_json="sets/DS3_val.json",
125
  test_json="sets/DS3_test.json",
126
  ),
 
 
 
 
 
 
 
127
  ]
128
 
129
  def _info(self) -> datasets.DatasetInfo:
130
  return datasets.DatasetInfo(
131
  description=_DESCRIPTION,
132
- # features=datasets.Features(
133
- # {
134
- # "image": datasets.Image(),
135
- # "label": datasets.ClassLabel(names=self.config.classes),
136
- # }
137
- # ),
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  homepage=_HOMEPAGE,
139
  citation=_CITATION,
140
- # task_templates=[ImageClassification(
141
- # image_column="image",
142
- # label_column="label",
143
- # )],
144
  )
145
 
146
  def _split_generators(self, dl_manager: datasets.DownloadManager) -> list[datasets.SplitGenerator]:
 
90
 
91
  def __init__(
92
  self,
 
93
  train_json: str,
94
  validation_json: str,
95
  test_json: str,
 
105
  **kwargs: keyword arguments forwarded to super.
106
  """
107
  super().__init__(version=datasets.Version("1.0.0"), **kwargs)
108
+ self.classes = self._get_classes([
109
+ train_json,
110
+ validation_json,
111
+ test_json,
112
+ ])
113
  self.train_json = train_json
114
  self.validation_json = validation_json
115
  self.test_json = test_json
116
 
117
+ def _get_classes(self, paths: list[str]) -> list[str]:
118
+ """Get the classes from the paths."""
119
+ classes = []
120
+ for path in paths:
121
+ with open(path, 'r') as f:
122
+ file = json.load(f)
123
+ for value in file.values():
124
+ for box in value['boxes']:
125
+ if box['label'] not in classes:
126
+ classes.append(box['label'])
127
+ return classes
128
+
129
 
130
  class Ornithoscope(datasets.GeneratorBasedBuilder):
131
 
 
134
  OrnithoscopeConfig(
135
  name="DS3",
136
  description="The main dataset.",
 
137
  train_json="sets/DS3_train.json",
138
  validation_json="sets/DS3_val.json",
139
  test_json="sets/DS3_test.json",
140
  ),
141
+ OrnithoscopeConfig(
142
+ name="DS4",
143
+ description="The new dataset.",
144
+ train_json="sets/DS4_train.json",
145
+ validation_json="sets/DS4_val.json",
146
+ test_json="sets/DS4_test.json",
147
+ ),
148
  ]
149
 
150
  def _info(self) -> datasets.DatasetInfo:
151
  return datasets.DatasetInfo(
152
  description=_DESCRIPTION,
153
+ features=datasets.Features(
154
+ {
155
+ "id_path": datasets.Value("string"),
156
+ "path": datasets.Value("string"),
157
+ "boxes": datasets.Sequence(
158
+ {
159
+ "label": datasets.Value("string"),
160
+ "xmin": datasets.Value("float32"),
161
+ "xmax": datasets.Value("float32"),
162
+ "ymin": datasets.Value("float32"),
163
+ "ymax": datasets.Value("float32"),
164
+ }
165
+ ),
166
+ "size": {
167
+ "width": datasets.Value("int32"),
168
+ "height": datasets.Value("int32"),
169
+ },
170
+ },
171
+ ),
172
  homepage=_HOMEPAGE,
173
  citation=_CITATION,
 
 
 
 
174
  )
175
 
176
  def _split_generators(self, dl_manager: datasets.DownloadManager) -> list[datasets.SplitGenerator]: