|
|
| import os
|
| import datasets
|
|
|
| class ForestSegmentationDataset(datasets.GeneratorBasedBuilder):
|
| def _info(self):
|
| return datasets.DatasetInfo(
|
| features=datasets.Features({
|
| "sample_id": datasets.Value("string"),
|
| "image": datasets.Image(),
|
| "mask": datasets.Image(),
|
| }),
|
| )
|
|
|
| def _split_generators(self, dl_manager):
|
|
|
| image_paths = dl_manager.iter_files("images")
|
| return [
|
| datasets.SplitGenerator(
|
| name=datasets.Split.TRAIN,
|
| gen_kwargs={"image_paths": image_paths}
|
| )
|
| ]
|
|
|
| def _generate_examples(self, image_paths):
|
| for image_path in image_paths:
|
| if not image_path.endswith("all_bands.tif"):
|
| continue
|
|
|
|
|
| parts = image_path.split("/")
|
| if len(parts) < 3:
|
| continue
|
|
|
| sample_id = parts[-3]
|
| mask_path = f"masks/{sample_id}/mask.tif"
|
|
|
| yield sample_id, {
|
| "sample_id": sample_id,
|
| "image": image_path,
|
| "mask": mask_path,
|
| }
|
|
|