|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""TODO: Add a description here.""" |
|
|
|
|
|
import csv |
|
import json |
|
import os |
|
import math |
|
import requests |
|
from io import BytesIO |
|
from zipfile import ZipFile |
|
from urllib.request import urlopen |
|
import pandas as pd |
|
|
|
import datasets |
|
|
|
|
|
|
|
_CITATION = """\ |
|
@InProceedings{huggingface:dataset, |
|
title = {A great new dataset}, |
|
author={huggingface, Inc. |
|
}, |
|
year={2020} |
|
} |
|
""" |
|
|
|
|
|
|
|
_DESCRIPTION = """\ |
|
This new dataset is designed to solve this great NLP task and is crafted with a lot of care. |
|
""" |
|
|
|
|
|
_HOMEPAGE = "" |
|
|
|
|
|
_LICENSE = "" |
|
|
|
_LILA_SAS_URLS = pd.read_csv("https://lila.science/wp-content/uploads/2020/03/lila_sas_urls.txt") |
|
_LILA_SAS_URLS.rename(columns={"# name": "name"}, inplace=True) |
|
|
|
|
|
_LILA_URLS = { |
|
"Caltech Camera Traps": "https://huggingface.co/datasets/NimaBoscarino/LILA/resolve/main/data/Caltech_Camera_Traps.jsonl", |
|
"ENA24": "https://huggingface.co/datasets/NimaBoscarino/LILA/resolve/main/data/ENA24.jsonl", |
|
"Missouri Camera Traps": "", |
|
"NACTI": "", |
|
"WCS Camera Traps": "", |
|
"Wellington Camera Traps": "", |
|
"Island Conservation Camera Traps": "", |
|
"Channel Islands Camera Traps": "", |
|
"Idaho Camera Traps": "", |
|
"Snapshot Serengeti": "", |
|
"Snapshot Karoo": "", |
|
"Snapshot Kgalagadi": "", |
|
"Snapshot Enonkishu": "", |
|
"Snapshot Camdeboo": "", |
|
"Snapshot Mountain Zebra": "", |
|
"Snapshot Kruger": "", |
|
"SWG Camera Traps": "", |
|
"Orinoquia Camera Traps": "", |
|
} |
|
|
|
|
|
DEFAULT_CONFIG_NAME = "Caltech Camera Traps" |
|
|
|
class LILAConfig(datasets.BuilderConfig): |
|
"""Builder Config for LILA""" |
|
|
|
def __init__(self, image_base_url, metadata_url, **kwargs): |
|
"""BuilderConfig for LILA. |
|
Args: |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super(LILAConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs) |
|
self.image_base_url = image_base_url |
|
self.metadata_url = metadata_url |
|
|
|
|
|
class LILA(datasets.GeneratorBasedBuilder): |
|
"""TODO: Short description of my dataset.""" |
|
|
|
VERSION = datasets.Version("1.1.0") |
|
|
|
BUILDER_CONFIGS = [ |
|
LILAConfig( |
|
name=row.name, |
|
|
|
image_base_url=row.image_base_url, |
|
metadata_url=_LILA_URLS[row.name] |
|
) for row in _LILA_SAS_URLS.itertuples() |
|
] |
|
|
|
def _get_features(self) -> datasets.Features: |
|
|
|
|
|
|
|
if self.config.name == 'Caltech Camera Traps': |
|
return datasets.Features({ |
|
"id": datasets.Value("string"), "file_name": datasets.Value("string"), |
|
"width": datasets.Value("int32"), "height": datasets.Value("int32"), |
|
"seq_num_frames": datasets.Value("int32"), |
|
"date_captured": datasets.Value("date32"), |
|
"seq_id": datasets.Value("string"), |
|
"location": datasets.Value("string"), |
|
"rights_holder": datasets.Value("string"), |
|
"frame_num": datasets.Value("int32"), |
|
|
|
|
|
"annotations": datasets.Sequence({ |
|
"id": datasets.Value("string"), |
|
"category_id": datasets.Value("int32"), |
|
}), |
|
|
|
"bboxes": datasets.Sequence({ |
|
"id": datasets.Value("string"), |
|
"category_id": datasets.Value("int32"), |
|
"bbox": datasets.Sequence(datasets.Value("float32"), length=4), |
|
}), |
|
|
|
"image": datasets.Image(decode=False), |
|
}) |
|
elif self.config.name == 'ENA24': |
|
return datasets.Features({ |
|
"id": datasets.Value("string"), "file_name": datasets.Value("string"), |
|
"width": datasets.Value("int32"), "height": datasets.Value("int32"), |
|
"annotations": datasets.Sequence({ |
|
"id": datasets.Value("string"), |
|
"category_id": datasets.Value("int32"), |
|
"bbox": datasets.Sequence(datasets.Value("float32"), length=4), |
|
}), |
|
"image": datasets.Image(decode=False), |
|
}) |
|
|
|
def _info(self): |
|
features = self._get_features() |
|
|
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
|
|
|
|
|
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
archive_path = dl_manager.download_and_extract(self.config.metadata_url) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"filepath": archive_path, |
|
"split": "train", |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath, split): |
|
with open(filepath) as f: |
|
for line in f: |
|
example = json.loads(line) |
|
image_url = f"{self.config.image_base_url}/{example['file_name']}" |
|
yield example["id"], { |
|
**example, |
|
"image": image_url |
|
} |