NimaBoscarino commited on
Commit
ac9a2bd
1 Parent(s): ba39dc9

Update LILA.py

Browse files
Files changed (1) hide show
  1. LILA.py +209 -26
LILA.py CHANGED
@@ -53,31 +53,30 @@ _LICENSE = ""
53
  _LILA_SAS_URLS = pd.read_csv("https://lila.science/wp-content/uploads/2020/03/lila_sas_urls.txt")
54
  _LILA_SAS_URLS.rename(columns={"# name": "name"}, inplace=True)
55
 
 
 
56
  # How do I make these point to the particular commit ID?
57
  _LILA_URLS = {
58
- "Caltech Camera Traps": "https://huggingface.co/datasets/NimaBoscarino/LILA/resolve/main/data/Caltech_Camera_Traps.jsonl",
59
- "ENA24": "https://huggingface.co/datasets/NimaBoscarino/LILA/resolve/main/data/ENA24.jsonl",
60
- "Missouri Camera Traps": "",
61
- "NACTI": "",
62
- "WCS Camera Traps": "",
63
- "Wellington Camera Traps": "",
64
- "Island Conservation Camera Traps": "",
65
- "Channel Islands Camera Traps": "",
66
- "Idaho Camera Traps": "",
67
- "Snapshot Serengeti": "",
68
- "Snapshot Karoo": "",
69
- "Snapshot Kgalagadi": "",
70
- "Snapshot Enonkishu": "",
71
- "Snapshot Camdeboo": "",
72
- "Snapshot Mountain Zebra": "",
73
- "Snapshot Kruger": "",
74
- "SWG Camera Traps": "",
75
- "Orinoquia Camera Traps": "",
76
  }
77
 
78
- # TODO: Just to make the Dataset viewer on the Hub work
79
- DEFAULT_CONFIG_NAME = "Caltech Camera Traps"
80
-
81
  class LILAConfig(datasets.BuilderConfig):
82
  """Builder Config for LILA"""
83
 
@@ -101,7 +100,7 @@ class LILA(datasets.GeneratorBasedBuilder):
101
  name=row.name,
102
  # description="TODO: Description",
103
  image_base_url=row.image_base_url,
104
- metadata_url=_LILA_URLS[row.name]
105
  ) for row in _LILA_SAS_URLS.itertuples()
106
  ]
107
 
@@ -119,19 +118,15 @@ class LILA(datasets.GeneratorBasedBuilder):
119
  "location": datasets.Value("string"),
120
  "rights_holder": datasets.Value("string"),
121
  "frame_num": datasets.Value("int32"),
122
-
123
-
124
  "annotations": datasets.Sequence({
125
  "id": datasets.Value("string"),
126
  "category_id": datasets.Value("int32"),
127
  }),
128
-
129
  "bboxes": datasets.Sequence({
130
  "id": datasets.Value("string"),
131
  "category_id": datasets.Value("int32"),
132
  "bbox": datasets.Sequence(datasets.Value("float32"), length=4),
133
  }),
134
-
135
  "image": datasets.Image(decode=False),
136
  })
137
  elif self.config.name == 'ENA24':
@@ -145,6 +140,192 @@ class LILA(datasets.GeneratorBasedBuilder):
145
  }),
146
  "image": datasets.Image(decode=False),
147
  })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
 
149
  def _info(self):
150
  features = self._get_features()
@@ -167,6 +348,8 @@ class LILA(datasets.GeneratorBasedBuilder):
167
 
168
  def _split_generators(self, dl_manager):
169
  archive_path = dl_manager.download_and_extract(self.config.metadata_url)
 
 
170
 
171
  return [
172
  datasets.SplitGenerator(
 
53
  _LILA_SAS_URLS = pd.read_csv("https://lila.science/wp-content/uploads/2020/03/lila_sas_urls.txt")
54
  _LILA_SAS_URLS.rename(columns={"# name": "name"}, inplace=True)
55
 
56
+ _METADATA_BASE_URL = "https://huggingface.co/datasets/NimaBoscarino/LILA/resolve/main/data/"
57
+
58
  # How do I make these point to the particular commit ID?
59
  _LILA_URLS = {
60
+ "Caltech Camera Traps": "Caltech_Camera_Traps.jsonl",
61
+ "ENA24": "ENA24.jsonl",
62
+ "Missouri Camera Traps": "Missouri_Camera_Traps.jsonl",
63
+ "NACTI": "NACTI.jsonl.zip",
64
+ "WCS Camera Traps": "WCS_Camera_Traps.jsonl.zip",
65
+ "Wellington Camera Traps": "Wellington_Camera_Traps.jsonl.zip",
66
+ "Island Conservation Camera Traps": "Island_Conservation_Camera_Traps.jsonl.zip",
67
+ "Channel Islands Camera Traps": "Channel_Islands_Camera_Traps.jsonl.zip",
68
+ "Idaho Camera Traps": "Idaho_Camera_Traps.jsonl.zip",
69
+ "Snapshot Serengeti": "Snapshot_Serengeti.jsonl.zip",
70
+ "Snapshot Karoo": "Snapshot_Karoo.jsonl.zip",
71
+ "Snapshot Kgalagadi": "Snapshot_Kgalagadi.jsonl",
72
+ "Snapshot Enonkishu": "Snapshot_Enonkishu.jsonl.zip",
73
+ "Snapshot Camdeboo": "Snapshot_Camdeboo.jsonl.zip",
74
+ "Snapshot Mountain Zebra": "Snapshot_Mountain_Zebra.jsonl.zip",
75
+ "Snapshot Kruger": "Snapshot_Kruger.jsonl",
76
+ "SWG Camera Traps": "SWG_Camera_Traps.jsonl.zip",
77
+ "Orinoquia Camera Traps": "Orinoquia_Camera_Traps.jsonl.zip",
78
  }
79
 
 
 
 
80
  class LILAConfig(datasets.BuilderConfig):
81
  """Builder Config for LILA"""
82
 
 
100
  name=row.name,
101
  # description="TODO: Description",
102
  image_base_url=row.image_base_url,
103
+ metadata_url=_METADATA_BASE_URL + _LILA_URLS[row.name]
104
  ) for row in _LILA_SAS_URLS.itertuples()
105
  ]
106
 
 
118
  "location": datasets.Value("string"),
119
  "rights_holder": datasets.Value("string"),
120
  "frame_num": datasets.Value("int32"),
 
 
121
  "annotations": datasets.Sequence({
122
  "id": datasets.Value("string"),
123
  "category_id": datasets.Value("int32"),
124
  }),
 
125
  "bboxes": datasets.Sequence({
126
  "id": datasets.Value("string"),
127
  "category_id": datasets.Value("int32"),
128
  "bbox": datasets.Sequence(datasets.Value("float32"), length=4),
129
  }),
 
130
  "image": datasets.Image(decode=False),
131
  })
132
  elif self.config.name == 'ENA24':
 
140
  }),
141
  "image": datasets.Image(decode=False),
142
  })
143
+ elif self.config.name == 'Missouri Camera Traps':
144
+ return datasets.Features({
145
+ "id": datasets.Value("string"), "file_name": datasets.Value("string"),
146
+ "width": datasets.Value("int32"), "height": datasets.Value("int32"),
147
+ "seq_id": datasets.Value("string"), "seq_num_frames": datasets.Value("int32"),
148
+ "frame_num": datasets.Value("int32"),
149
+ "annotations": datasets.Sequence({
150
+ "id": datasets.Value("string"),
151
+ "category_id": datasets.Value("int32"),
152
+ "sequence_level_annotation": datasets.Value("bool"),
153
+ "bbox": datasets.Sequence(datasets.Value("float32"), length=4),
154
+ }),
155
+ "image": datasets.Image(decode=False),
156
+ })
157
+ elif self.config.name == 'NACTI':
158
+ return datasets.Features({
159
+ "id": datasets.Value("string"), "file_name": datasets.Value("string"),
160
+ "width": datasets.Value("int32"), "height": datasets.Value("int32"),
161
+ "study": datasets.Value("string"), "location": datasets.Value("string"),
162
+ "annotations": datasets.Sequence({
163
+ "id": datasets.Value("string"),
164
+ "category_id": datasets.Value("int32"),
165
+ }),
166
+ "bboxes": datasets.Sequence({
167
+ "id": datasets.Value("string"),
168
+ "category_id": datasets.Value("int32"),
169
+ "bbox": datasets.Sequence(datasets.Value("float32"), length=4),
170
+ }),
171
+ "image": datasets.Image(decode=False),
172
+ })
173
+ elif self.config.name == 'WCS Camera Traps':
174
+ return datasets.Features({
175
+ "id": datasets.Value("string"), "file_name": datasets.Value("string"),
176
+ "width": datasets.Value("int32"), "height": datasets.Value("int32"),
177
+ "wcs_id": datasets.Value("string"), "location": datasets.Value("string"),
178
+ "frame_num": datasets.Value("int32"), "match_level": datasets.Value("int32"),
179
+ "seq_id": datasets.Value("string"), "country_code": datasets.Value("string"),
180
+ "seq_num_frames": datasets.Value("int32"),
181
+ "status": datasets.Value("string"),
182
+ "datetime": datasets.Value("date32"),
183
+ "corrupt": datasets.Value("bool"),
184
+ "annotations": datasets.Sequence({
185
+ "id": datasets.Value("string"),
186
+ "category_id": datasets.Value("int32"),
187
+ "count": datasets.Value("int32"),
188
+ "sex": datasets.Value("string"),
189
+ "age": datasets.Value("string"),
190
+ }),
191
+ "bboxes": datasets.Sequence({
192
+ "id": datasets.Value("string"),
193
+ "category_id": datasets.Value("int32"),
194
+ "bbox": datasets.Sequence(datasets.Value("float32"), length=4),
195
+ }),
196
+ "image": datasets.Image(decode=False),
197
+ })
198
+ elif self.config.name == 'Wellington Camera Traps':
199
+ return datasets.Features({
200
+ "id": datasets.Value("string"), "file_name": datasets.Value("string"),
201
+ "width": datasets.Value("int32"), "height": datasets.Value("int32"),
202
+ "frame_num": datasets.Value("int32"), "seq_id": datasets.Value("string"),
203
+ "site": datasets.Value("string"), "camera": datasets.Value("string"),
204
+ "datetime": datasets.Value("date32"),
205
+ "annotations": datasets.Sequence({
206
+ "id": datasets.Value("string"),
207
+ "category_id": datasets.Value("int32"),
208
+ }),
209
+ "image": datasets.Image(decode=False),
210
+ })
211
+ elif self.config.name == 'Island Conservation Camera Traps':
212
+ return datasets.Features({
213
+ "id": datasets.Value("string"), "file_name": datasets.Value("string"),
214
+ "width": datasets.Value("int32"), "height": datasets.Value("int32"),
215
+ "annotations": datasets.Sequence({
216
+ "id": datasets.Value("string"),
217
+ "category_id": datasets.Value("int32"),
218
+ "bbox": datasets.Sequence(datasets.Value("float32"), length=4),
219
+ }),
220
+ "image": datasets.Image(decode=False),
221
+ })
222
+ elif self.config.name == 'Channel Islands Camera Traps':
223
+ return datasets.Features({
224
+ "id": datasets.Value("string"), "file_name": datasets.Value("string"),
225
+ "width": datasets.Value("int32"), "height": datasets.Value("int32"),
226
+ "frame_num": datasets.Value("int32"), "seq_id": datasets.Value("string"),
227
+ "seq_num_frames": datasets.Value("int32"),
228
+ "original_relative_path": datasets.Value("string"),
229
+ "location": datasets.Value("string"),
230
+ "temperature": datasets.Value("string"),
231
+ "annotations": datasets.Sequence({
232
+ "id": datasets.Value("string"),
233
+ "category_id": datasets.Value("int32"),
234
+ "sequence_level_annotation": datasets.Value("bool"),
235
+ "bbox": datasets.Sequence(datasets.Value("float32"), length=4),
236
+ }),
237
+ "image": datasets.Image(decode=False),
238
+ })
239
+ elif self.config.name == 'Idaho Camera Traps':
240
+ return datasets.Features({
241
+ "id": datasets.Value("string"), "file_name": datasets.Value("string"),
242
+ "frame_num": datasets.Value("int32"), "seq_id": datasets.Value("string"),
243
+ "seq_num_frames": datasets.Value("int32"),
244
+ "original_relative_path": datasets.Value("string"),
245
+ "datetime": datasets.Value("date32"),
246
+ "location": datasets.Value("string"),
247
+ "annotations": datasets.Sequence({
248
+ "id": datasets.Value("string"),
249
+ "category_id": datasets.Value("int32"),
250
+ "sequence_level_annotation": datasets.Value("bool"),
251
+ }),
252
+ "image": datasets.Image(decode=False),
253
+ })
254
+ elif self.config.name == 'Snapshot Serengeti':
255
+ return datasets.Features({
256
+ "id": datasets.Value("string"), "file_name": datasets.Value("string"),
257
+ "frame_num": datasets.Value("int32"), "seq_id": datasets.Value("string"),
258
+ "width": datasets.Value("int32"), "height": datasets.Value("int32"),
259
+ "seq_num_frames": datasets.Value("int32"),
260
+ "datetime": datasets.Value("date32"),
261
+ "corrupt": datasets.Value("bool"),
262
+ "location": datasets.Value("string"),
263
+ "annotations": datasets.Sequence({
264
+ "id": datasets.Value("string"),
265
+ "category_id": datasets.Value("int32"),
266
+ "sequence_level_annotation": datasets.Value("bool"),
267
+ "seq_id": datasets.Value("string"),
268
+ "season": datasets.Value("string"),
269
+ "datetime": datasets.Value("date32"),
270
+ "subject_id": datasets.Value("string"),
271
+ "count": datasets.Value("string"),
272
+ "standing": datasets.Value("float32"),
273
+ "resting": datasets.Value("float32"),
274
+ "moving": datasets.Value("float32"),
275
+ "interacting": datasets.Value("float32"),
276
+ "young_present": datasets.Value("float32"),
277
+ "location": datasets.Value("string"),
278
+ }),
279
+ "bboxes": datasets.Sequence({
280
+ "id": datasets.Value("string"),
281
+ "category_id": datasets.Value("int32"),
282
+ "bbox": datasets.Sequence(datasets.Value("float32"), length=4),
283
+ }),
284
+ "image": datasets.Image(decode=False),
285
+ })
286
+ elif self.config.name in [
287
+ 'Snapshot Karoo', 'Snapshot Kgalagadi', 'Snapshot Enonkishu', 'Snapshot Camdeboo',
288
+ 'Snapshot Mountain Zebra', 'Snapshot Kruger'
289
+ ]:
290
+ return datasets.Features({
291
+ "id": datasets.Value("string"), "file_name": datasets.Value("string"),
292
+ "frame_num": datasets.Value("int32"), "seq_id": datasets.Value("string"),
293
+ "width": datasets.Value("int32"), "height": datasets.Value("int32"),
294
+ "seq_num_frames": datasets.Value("int32"),
295
+ "datetime": datasets.Value("date32"),
296
+ "corrupt": datasets.Value("bool"),
297
+ "location": datasets.Value("string"),
298
+ "annotations": datasets.Sequence({
299
+ "id": datasets.Value("string"),
300
+ "category_id": datasets.Value("int32"),
301
+ "sequence_level_annotation": datasets.Value("bool"),
302
+ "seq_id": datasets.Value("string"),
303
+ "season": datasets.Value("string"),
304
+ "datetime": datasets.Value("date32"),
305
+ "subject_id": datasets.Value("string"),
306
+ "count": datasets.Value("string"),
307
+ "standing": datasets.Value("float32"),
308
+ "resting": datasets.Value("float32"),
309
+ "moving": datasets.Value("float32"),
310
+ "interacting": datasets.Value("float32"),
311
+ "young_present": datasets.Value("float32"),
312
+ "location": datasets.Value("string"),
313
+ }),
314
+ "image": datasets.Image(decode=False),
315
+ })
316
+ elif self.config.name == 'Orinoquia Camera Traps':
317
+ return datasets.Features({
318
+ "id": datasets.Value("string"), "file_name": datasets.Value("string"),
319
+ "frame_num": datasets.Value("int32"), "seq_id": datasets.Value("string"),
320
+ "seq_num_frames": datasets.Value("int32"), "datetime": datasets.Value("date32"),
321
+ "location": datasets.Value("string"),
322
+ "annotations": datasets.Sequence({
323
+ "id": datasets.Value("string"),
324
+ "sequence_level_annotation": datasets.Value("bool"),
325
+ "category_id": datasets.Value("int32"),
326
+ }),
327
+ "image": datasets.Image(decode=False),
328
+ })
329
 
330
  def _info(self):
331
  features = self._get_features()
 
348
 
349
  def _split_generators(self, dl_manager):
350
  archive_path = dl_manager.download_and_extract(self.config.metadata_url)
351
+ if archive_path.endswith(".zip"):
352
+ archive_path = os.path.join(archive_path, os.listdir(archive_path)[0])
353
 
354
  return [
355
  datasets.SplitGenerator(