Datasets:
Upload 2 files
Browse filesadd custom dataset loading script and corresponding meta data
Files changed (2)
- dataset.pyAdded+95
- dataset_info.jsonAdded+1
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495import os
import datasets
import rasterio
import tqdm
class SSL4EOEUForest(datasets.GeneratorBasedBuilder):
def _info(self):
return datasets.DatasetInfo(
description="SSL4EO-EU Forest dataset with four-season of Sentinel-2 timestamps and bounding box metadata extracted from image folders.",
features=datasets.Features({
"image_path": datasets.Value("string"),
"mask_path": datasets.Value("string"),
"start_timestamp": datasets.Value("string"),
"end_timestamp": datasets.Value("string"),
"sentinel_tile_id": datasets.Value("string"),
"bbox": {
"minx": datasets.Value("float32"),
"maxx": datasets.Value("float32"),
"miny": datasets.Value("float32"),
"maxy": datasets.Value("float32"),
}
}),
citation="""@misc{ssl4eo_eu_forest,
author = {Nassim Ait Ali Braham and Conrad M Albrecht},
title = {SSL4EO-EU Forest Dataset},
year = {2025},
howpublished = {https://huggingface.co/datasets/dm4eo/ssl4eo-eu-forest},
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.}
}""",
homepage="https://www.evo-land.eu",
license="CC-BY-4.0",
)
def _split_generators(self, dl_manager):
use_local = os.environ.get("HF_DATASET_LOCAL", "false").lower() == "true"
if use_local:
root = os.path.abspath(".")
else:
root = dl_manager.download_and_extract(".")
images_dir = os.path.join(root, "images")
masks_dir = os.path.join(root, "masks")
return [
datasets.SplitGenerator(name=datasets.Split("all"), gen_kwargs={
"images_dir": images_dir,
"masks_dir": masks_dir
})
]
def _generate_examples(self, images_dir, masks_dir):
sample_id_list = sorted(os.listdir(images_dir))
key = 0
for sample_id in tqdm.tqdm(sample_id_list, desc="Indexing samples", unit="sample"):
sample_path = os.path.join(images_dir, sample_id)
if not os.path.isdir(sample_path):
continue
timestamp_dirs = sorted(os.listdir(sample_path))
mask_path = os.path.join(masks_dir, sample_id, "mask.tif")
if not os.path.exists(mask_path):
continue
for ts in timestamp_dirs:
parts = ts.split("_")
if len(parts) != 3:
continue
start_ts, end_ts, tile_id = parts
image_path = os.path.join(sample_path, ts, "all_bands.tif")
if not os.path.exists(image_path):
continue
try:
with rasterio.open(image_path) as src:
bounds = src.bounds
except Exception:
continue
yield key, {
"image_path": image_path,
"mask_path": mask_path,
"start_timestamp": start_ts,
"end_timestamp": end_ts,
"sentinel_tile_id": tile_id,
"bbox": {
"minx": bounds.left,
"maxx": bounds.right,
"miny": bounds.bottom,
"maxy": bounds.top
}
}
key += 11{"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"}}}}dataset.pyAdded+95
dataset_info.jsonAdded+1