Datasets:
Upload 2 files
Browse filesadd custom dataset loading script and corresponding meta data
- dataset.py +95 -0
- dataset_info.json +1 -0
dataset.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import datasets
|
| 3 |
+
import rasterio
|
| 4 |
+
import tqdm
|
| 5 |
+
|
| 6 |
+
class SSL4EOEUForest(datasets.GeneratorBasedBuilder):
|
| 7 |
+
def _info(self):
|
| 8 |
+
return datasets.DatasetInfo(
|
| 9 |
+
description="SSL4EO-EU Forest dataset with four-season of Sentinel-2 timestamps and bounding box metadata extracted from image folders.",
|
| 10 |
+
features=datasets.Features({
|
| 11 |
+
"image_path": datasets.Value("string"),
|
| 12 |
+
"mask_path": datasets.Value("string"),
|
| 13 |
+
"start_timestamp": datasets.Value("string"),
|
| 14 |
+
"end_timestamp": datasets.Value("string"),
|
| 15 |
+
"sentinel_tile_id": datasets.Value("string"),
|
| 16 |
+
"bbox": {
|
| 17 |
+
"minx": datasets.Value("float32"),
|
| 18 |
+
"maxx": datasets.Value("float32"),
|
| 19 |
+
"miny": datasets.Value("float32"),
|
| 20 |
+
"maxy": datasets.Value("float32"),
|
| 21 |
+
}
|
| 22 |
+
}),
|
| 23 |
+
citation="""@misc{ssl4eo_eu_forest,
|
| 24 |
+
author = {Nassim Ait Ali Braham and Conrad M Albrecht},
|
| 25 |
+
title = {SSL4EO-EU Forest Dataset},
|
| 26 |
+
year = {2025},
|
| 27 |
+
howpublished = {https://huggingface.co/datasets/dm4eo/ssl4eo-eu-forest},
|
| 28 |
+
note = {This work was carried under the EvoLand project, cf. https://www.evo-land.eu . This project has received funding from the European Union's Horizon Europe research and innovation programme under grant agreement No. 101082130.}
|
| 29 |
+
}""",
|
| 30 |
+
homepage="https://www.evo-land.eu",
|
| 31 |
+
license="CC-BY-4.0",
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
def _split_generators(self, dl_manager):
|
| 35 |
+
use_local = os.environ.get("HF_DATASET_LOCAL", "false").lower() == "true"
|
| 36 |
+
|
| 37 |
+
if use_local:
|
| 38 |
+
root = os.path.abspath(".")
|
| 39 |
+
else:
|
| 40 |
+
root = dl_manager.download_and_extract(".")
|
| 41 |
+
|
| 42 |
+
images_dir = os.path.join(root, "images")
|
| 43 |
+
masks_dir = os.path.join(root, "masks")
|
| 44 |
+
|
| 45 |
+
return [
|
| 46 |
+
datasets.SplitGenerator(name=datasets.Split("all"), gen_kwargs={
|
| 47 |
+
"images_dir": images_dir,
|
| 48 |
+
"masks_dir": masks_dir
|
| 49 |
+
})
|
| 50 |
+
]
|
| 51 |
+
|
| 52 |
+
def _generate_examples(self, images_dir, masks_dir):
|
| 53 |
+
sample_id_list = sorted(os.listdir(images_dir))
|
| 54 |
+
key = 0
|
| 55 |
+
|
| 56 |
+
for sample_id in tqdm.tqdm(sample_id_list, desc="Indexing samples", unit="sample"):
|
| 57 |
+
sample_path = os.path.join(images_dir, sample_id)
|
| 58 |
+
if not os.path.isdir(sample_path):
|
| 59 |
+
continue
|
| 60 |
+
|
| 61 |
+
timestamp_dirs = sorted(os.listdir(sample_path))
|
| 62 |
+
mask_path = os.path.join(masks_dir, sample_id, "mask.tif")
|
| 63 |
+
if not os.path.exists(mask_path):
|
| 64 |
+
continue
|
| 65 |
+
|
| 66 |
+
for ts in timestamp_dirs:
|
| 67 |
+
parts = ts.split("_")
|
| 68 |
+
if len(parts) != 3:
|
| 69 |
+
continue
|
| 70 |
+
|
| 71 |
+
start_ts, end_ts, tile_id = parts
|
| 72 |
+
image_path = os.path.join(sample_path, ts, "all_bands.tif")
|
| 73 |
+
if not os.path.exists(image_path):
|
| 74 |
+
continue
|
| 75 |
+
|
| 76 |
+
try:
|
| 77 |
+
with rasterio.open(image_path) as src:
|
| 78 |
+
bounds = src.bounds
|
| 79 |
+
except Exception:
|
| 80 |
+
continue
|
| 81 |
+
|
| 82 |
+
yield key, {
|
| 83 |
+
"image_path": image_path,
|
| 84 |
+
"mask_path": mask_path,
|
| 85 |
+
"start_timestamp": start_ts,
|
| 86 |
+
"end_timestamp": end_ts,
|
| 87 |
+
"sentinel_tile_id": tile_id,
|
| 88 |
+
"bbox": {
|
| 89 |
+
"minx": bounds.left,
|
| 90 |
+
"maxx": bounds.right,
|
| 91 |
+
"miny": bounds.bottom,
|
| 92 |
+
"maxy": bounds.top
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
key += 1
|
dataset_info.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"description": "SSL4EO-EU Forest dataset with four-season of Sentinel-2 timestamps and bounding box metadata extracted from image folders.", "citation": "@misc{ssl4eo_eu_forest,\n author = {Nassim Ait Ali Braham and Conrad M Albrecht},\n title = {SSL4EO-EU Forest Dataset},\n year = {2025},\n howpublished = {https://huggingface.co/datasets/dm4eo/ssl4eo-eu-forest},\n note = {This work was carried under the EvoLand project, cf. https://www.evo-land.eu . This project has received funding from the European Union's Horizon Europe research and innovation programme under grant agreement No. 101082130.}\n}", "homepage": "https://www.evo-land.eu", "license": "CC-BY-4.0", "features": {"image_path": {"dtype": "string", "_type": "Value"}, "mask_path": {"dtype": "string", "_type": "Value"}, "start_timestamp": {"dtype": "string", "_type": "Value"}, "end_timestamp": {"dtype": "string", "_type": "Value"}, "sentinel_tile_id": {"dtype": "string", "_type": "Value"}, "bbox": {"minx": {"dtype": "float32", "_type": "Value"}, "maxx": {"dtype": "float32", "_type": "Value"}, "miny": {"dtype": "float32", "_type": "Value"}, "maxy": {"dtype": "float32", "_type": "Value"}}}}
|