Datasets:

Modalities:
Geospatial
Languages:
English
DOI:
Libraries:
License:
cmalbrec commited on
Commit
80c0b47
·
verified ·
1 Parent(s): 9f44445

bug fix dataset.py

Browse files
Files changed (1) hide show
  1. dataset.py +13 -23
dataset.py CHANGED
@@ -2,51 +2,41 @@
2
  import os
3
  import datasets
4
 
5
- class MyDataset(datasets.GeneratorBasedBuilder):
6
  def _info(self):
7
  return datasets.DatasetInfo(
8
  features=datasets.Features({
9
  "sample_id": datasets.Value("string"),
10
- "image": datasets.Image(), # or datasets.Value("string") if you want paths
11
- "mask": datasets.Image(),
12
  }),
13
  )
14
 
15
  def _split_generators(self, dl_manager):
16
- # Streaming mode: use iter_files to avoid downloading everything
17
  image_paths = dl_manager.iter_files("images")
18
- mask_paths = dl_manager.iter_files("masks")
19
-
20
  return [
21
  datasets.SplitGenerator(
22
  name=datasets.Split.TRAIN,
23
- gen_kwargs={
24
- "image_paths": image_paths,
25
- "mask_paths": mask_paths,
26
- }
27
  )
28
  ]
29
 
30
- def _generate_examples(self, image_paths, mask_paths):
31
- # Build a lookup for masks
32
- mask_lookup = {}
33
- for mask_path in mask_paths:
34
- sample_id = os.path.basename(os.path.dirname(mask_path))
35
- mask_lookup[sample_id] = mask_path
36
-
37
- # Iterate over image folders
38
  for image_path in image_paths:
39
  if not image_path.endswith("all_bands.tif"):
40
  continue
41
 
 
42
  parts = image_path.split("/")
43
- sample_id = parts[-3] # e.g., "0000005"
 
44
 
45
- if sample_id not in mask_lookup:
46
- continue
47
 
48
- yield self.generate_index(), {
49
  "sample_id": sample_id,
50
  "image": image_path,
51
- "mask": mask_lookup[sample_id],
52
  }
 
2
  import os
3
  import datasets
4
 
5
+ class ForestSegmentationDataset(datasets.GeneratorBasedBuilder):
6
  def _info(self):
7
  return datasets.DatasetInfo(
8
  features=datasets.Features({
9
  "sample_id": datasets.Value("string"),
10
+ "image": datasets.Image(), # Path to all_bands.tif
11
+ "mask": datasets.Image(), # Path to mask.tif
12
  }),
13
  )
14
 
15
  def _split_generators(self, dl_manager):
16
+ # Streaming mode: use iter_files to lazily iterate over image files
17
  image_paths = dl_manager.iter_files("images")
 
 
18
  return [
19
  datasets.SplitGenerator(
20
  name=datasets.Split.TRAIN,
21
+ gen_kwargs={"image_paths": image_paths}
 
 
 
22
  )
23
  ]
24
 
25
+ def _generate_examples(self, image_paths):
 
 
 
 
 
 
 
26
  for image_path in image_paths:
27
  if not image_path.endswith("all_bands.tif"):
28
  continue
29
 
30
+ # Extract sample_id from path: images/0000005/<timestamp>/all_bands.tif
31
  parts = image_path.split("/")
32
+ if len(parts) < 3:
33
+ continue # Skip malformed paths
34
 
35
+ sample_id = parts[-3] # "0000005"
36
+ mask_path = f"masks/{sample_id}/mask.tif"
37
 
38
+ yield sample_id, {
39
  "sample_id": sample_id,
40
  "image": image_path,
41
+ "mask": mask_path,
42
  }