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|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
import datasets
|
| 4 |
+
import h5py
|
| 5 |
+
import hdf5plugin
|
| 6 |
+
import pandas as pd
|
| 7 |
+
import pyarrow
|
| 8 |
+
|
| 9 |
+
pyarrow.PyExtensionType.set_auto_load(True)
|
| 10 |
+
|
| 11 |
+
_CITATION = """\
|
| 12 |
+
@misc{cambrin2025texttoremotesensingimageretrievalrgbsources,
|
| 13 |
+
title={Text-to-Remote-Sensing-Image Retrieval beyond RGB Sources},
|
| 14 |
+
author={Daniele Rege Cambrin and Lorenzo Vaiani and Giuseppe Gallipoli and Luca Cagliero and Paolo Garza},
|
| 15 |
+
year={2025},
|
| 16 |
+
eprint={2507.10403},
|
| 17 |
+
archivePrefix={arXiv},
|
| 18 |
+
primaryClass={cs.CV},
|
| 19 |
+
url={https://arxiv.org/abs/2507.10403},
|
| 20 |
+
}
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
_DESCRIPTION = """\
|
| 24 |
+
CrisisLandMark is a large-scale, multimodal corpus for Text-to-Remote-Sensing-Image Retrieval (T2RSIR).
|
| 25 |
+
It contains over 647,000 Sentinel-1 (SAR) and Sentinel-2 (multispectral optical) images enriched with
|
| 26 |
+
structured textual and geospatial annotations. The dataset is designed to move beyond standard RGB imagery,
|
| 27 |
+
enabling the development of retrieval systems that can leverage the rich physical information from different
|
| 28 |
+
satellite sensors for applications in Land Use/Land Cover (LULC) mapping and crisis management.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
_HOMEPAGE = "https://github.com/DarthReca/closp" # Replace with your actual project page if different
|
| 32 |
+
|
| 33 |
+
_LICENSE = "Creative Commons Attribution Non Commercial 4.0"
|
| 34 |
+
|
| 35 |
+
# Define the satellite data sources as in the original script
|
| 36 |
+
_SATELLITE_DATASETS = {
|
| 37 |
+
"s2": ["benv2s2", "cabuar", "sen2flood"],
|
| 38 |
+
"s1": ["benv2s1", "mmflood", "sen1flood", "quakeset"],
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
_URLS = {"main": "crisislandmark.h5", "metadata": "metadata.parquet"}
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class CrisisLandMarkConfig(datasets.BuilderConfig):
|
| 45 |
+
"""BuilderConfig for CrisisLandMark."""
|
| 46 |
+
|
| 47 |
+
def __init__(self, satellite_type, **kwargs):
|
| 48 |
+
"""
|
| 49 |
+
Args:
|
| 50 |
+
satellite_type (str): Type of satellite data to load ('s1', 's2', or 'all').
|
| 51 |
+
**kwargs: keyword arguments forwarded to super.
|
| 52 |
+
"""
|
| 53 |
+
super(CrisisLandMarkConfig, self).__init__(**kwargs)
|
| 54 |
+
self.satellite_type = satellite_type
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class CrisisLandMark(datasets.GeneratorBasedBuilder):
|
| 58 |
+
"""CrisisLandMark Dataset."""
|
| 59 |
+
|
| 60 |
+
VERSION = datasets.Version("1.0.0")
|
| 61 |
+
|
| 62 |
+
# Configure for different satellite types
|
| 63 |
+
BUILDER_CONFIGS = [
|
| 64 |
+
CrisisLandMarkConfig(
|
| 65 |
+
name="s1",
|
| 66 |
+
version=VERSION,
|
| 67 |
+
description="Load only Sentinel-1 (SAR) images.",
|
| 68 |
+
satellite_type="s1",
|
| 69 |
+
),
|
| 70 |
+
CrisisLandMarkConfig(
|
| 71 |
+
name="s2",
|
| 72 |
+
version=VERSION,
|
| 73 |
+
description="Load only Sentinel-2 (Optical) images.",
|
| 74 |
+
satellite_type="s2",
|
| 75 |
+
),
|
| 76 |
+
CrisisLandMarkConfig(
|
| 77 |
+
name="all",
|
| 78 |
+
version=VERSION,
|
| 79 |
+
description="Load all images (Sentinel-1 and Sentinel-2).",
|
| 80 |
+
satellite_type="all",
|
| 81 |
+
),
|
| 82 |
+
]
|
| 83 |
+
|
| 84 |
+
DEFAULT_CONFIG_NAME = "s2"
|
| 85 |
+
|
| 86 |
+
def _info(self):
|
| 87 |
+
# Define the features of the dataset
|
| 88 |
+
features = datasets.Features(
|
| 89 |
+
{
|
| 90 |
+
"key": datasets.Value("string"),
|
| 91 |
+
"image": datasets.Array3D(shape=(None, 120, 120), dtype="float32"),
|
| 92 |
+
"coords": datasets.Array3D(shape=(2, 120, 120), dtype="float32"),
|
| 93 |
+
"labels": datasets.Sequence(datasets.Value("string")),
|
| 94 |
+
"crs": datasets.Value("int64"),
|
| 95 |
+
"timestamp": datasets.Value("string"),
|
| 96 |
+
}
|
| 97 |
+
)
|
| 98 |
+
return datasets.DatasetInfo(
|
| 99 |
+
description=_DESCRIPTION,
|
| 100 |
+
features=features,
|
| 101 |
+
homepage=_HOMEPAGE,
|
| 102 |
+
license=_LICENSE,
|
| 103 |
+
citation=_CITATION,
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
def _split_generators(self, dl_manager):
|
| 107 |
+
"""Returns SplitGenerators."""
|
| 108 |
+
files = dl_manager.download(_URLS)
|
| 109 |
+
|
| 110 |
+
return [
|
| 111 |
+
datasets.SplitGenerator(
|
| 112 |
+
name=datasets.Split.TRAIN,
|
| 113 |
+
gen_kwargs={"split": "train"} | files,
|
| 114 |
+
),
|
| 115 |
+
datasets.SplitGenerator(
|
| 116 |
+
name=datasets.Split.TEST,
|
| 117 |
+
gen_kwargs={"split": "corpus"} | files,
|
| 118 |
+
),
|
| 119 |
+
]
|
| 120 |
+
|
| 121 |
+
def _generate_examples(self, split, metadata, main, **kwargs):
|
| 122 |
+
"""Yields examples."""
|
| 123 |
+
|
| 124 |
+
# --- Load and filter metadata ---
|
| 125 |
+
metadata_df = pd.read_parquet(metadata)
|
| 126 |
+
metadata_df = metadata_df[metadata_df["split"] == split]
|
| 127 |
+
|
| 128 |
+
# Filter by satellite type based on the config
|
| 129 |
+
satellite_type = self.config.satellite_type
|
| 130 |
+
if satellite_type != "all":
|
| 131 |
+
satellite_filter = "|".join(_SATELLITE_DATASETS[satellite_type])
|
| 132 |
+
metadata_df = metadata_df[
|
| 133 |
+
metadata_df["key"].str.contains(satellite_filter, regex=True)
|
| 134 |
+
]
|
| 135 |
+
|
| 136 |
+
sample_keys = metadata_df[["key", "labels"]].to_records(index=False)
|
| 137 |
+
# Open the HDF5 file once and yield examples
|
| 138 |
+
with h5py.File(main, "r") as f:
|
| 139 |
+
for key, labels in sample_keys:
|
| 140 |
+
sample_group = f[key]
|
| 141 |
+
|
| 142 |
+
# Read data
|
| 143 |
+
image_np = sample_group["image"][:].astype("float32")
|
| 144 |
+
coords_np = sample_group["coords"][:].astype("float32")
|
| 145 |
+
|
| 146 |
+
# Read attributes
|
| 147 |
+
crs = sample_group.attrs["crs"]
|
| 148 |
+
timestamp = sample_group.attrs["timestamp"]
|
| 149 |
+
|
| 150 |
+
sample = {
|
| 151 |
+
"key": key,
|
| 152 |
+
"image": image_np,
|
| 153 |
+
"coords": coords_np,
|
| 154 |
+
"labels": list(labels), # Ensure it's a list
|
| 155 |
+
"crs": crs,
|
| 156 |
+
"timestamp": timestamp,
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
yield (key, sample)
|