File size: 2,437 Bytes
6555ae7 ae7fae6 6555ae7 ae7fae6 6555ae7 4d7ff1e 1ee6507 6555ae7 4d7ff1e 1ee6507 6555ae7 1ee6507 e75c387 6555ae7 1ee6507 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# Copyright (C) 2022, Pyronear.
# This program is licensed under the Apache License 2.0.
# See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0> for full license details.
"""OpenFire dataset."""
import os
import json
import datasets
_HOMEPAGE = "https://pyronear.org/pyro-vision/datasets.html#openfire"
_LICENSE = "Apache License 2.0"
_CITATION = """\
@software{Pyronear_PyroVision_2019,
title={Pyrovision: wildfire early detection},
author={Pyronear contributors},
year={2019},
month={October},
publisher = {GitHub},
url = {https://github.com/pyronear/pyro-vision}
}
"""
_DESCRIPTION = """\
OpenFire is an image classification dataset for wildfire detection, collected
from web searches.
"""
_REPO = "https://huggingface.co/datasets/pyronear/openfire/resolve/main/data"
_URLS = {
"train": f"{_REPO}/openfire_train.json",
"validation": f"{_REPO}/openfire_val.json",
}
class OpenFire(datasets.GeneratorBasedBuilder):
"""OpenFire dataset."""
VERSION = datasets.Version("1.0.0")
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"image_url": datasets.Value("string", id=None),
"is_wildfire": datasets.Value("bool"),
}
),
supervised_keys=None,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
data_dir = dl_manager.download_and_extract(_URLS)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": data_dir["train"],
"split": "train",
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"filepath": data_dir["validation"],
"split": "validation",
},
),
]
def _generate_examples(self, filepath, split):
with open(filepath, "rb") as f:
urls = json.load(f)
idx = 0
for label in range(2):
for url in urls[str(label)]:
yield idx, {"image_url": url, "is_wildfire": bool(label)}
idx += 1
|