Datasets:

Modalities:
Geospatial
Languages:
English
DOI:
Libraries:
License:
File size: 1,713 Bytes
a248601
73c6f98
 
7dcdc23
b7d4966
73c6f98
 
 
b7d4966
 
 
73c6f98
 
 
 
b7d4966
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73c6f98
 
b7d4966
 
73c6f98
b7d4966
7dcdc23
a248601
b7d4966
 
 
 
7dcdc23
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

import os
import datasets

class MyDataset(datasets.GeneratorBasedBuilder):
    def _info(self):
        return datasets.DatasetInfo(
            features=datasets.Features({
                "sample_id": datasets.Value("string"),
                "image": datasets.Image(),  # or datasets.Value("string") if you want paths
                "mask": datasets.Image(),
            }),
        )

    def _split_generators(self, dl_manager):
        # Streaming mode: use iter_files to avoid downloading everything
        image_paths = dl_manager.iter_files("images")
        mask_paths = dl_manager.iter_files("masks")

        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "image_paths": image_paths,
                    "mask_paths": mask_paths,
                }
            )
        ]

    def _generate_examples(self, image_paths, mask_paths):
        # Build a lookup for masks
        mask_lookup = {}
        for mask_path in mask_paths:
            sample_id = os.path.basename(os.path.dirname(mask_path))
            mask_lookup[sample_id] = mask_path

        # Iterate over image folders
        for image_path in image_paths:
            if not image_path.endswith("all_bands.tif"):
                continue

            parts = image_path.split("/")
            sample_id = parts[-3]  # e.g., "0000005"

            if sample_id not in mask_lookup:
                continue

            yield self.generate_index(), {
                "sample_id": sample_id,
                "image": image_path,
                "mask": mask_lookup[sample_id],
            }