alkzar90 commited on
Commit
dbf9eb9
1 Parent(s): e6aaf6e

add mask config

Browse files
Files changed (1) hide show
  1. rock-glacier-dataset.py +14 -19
rock-glacier-dataset.py CHANGED
@@ -90,9 +90,10 @@ class RockGlacierDataset(datasets.GeneratorBasedBuilder):
90
  if self.config.name == "image-segmentation":
91
  features = datasets.Features({
92
  "image": datasets.Image(),
93
- "labels": datasets.Image(),
 
94
  })
95
- keys = ("image", "labels")
96
 
97
 
98
  return datasets.DatasetInfo(
@@ -149,28 +150,22 @@ class RockGlacierDataset(datasets.GeneratorBasedBuilder):
149
  if self.config.name == "image-classification":
150
  for i, path in enumerate(files):
151
  file_name = os.path.basename(path)
152
- dir_name = os.path.basename(os.path.dirname(path))
153
  if dir_name != "masks" and file_name.endswith(".png"):
154
  yield i, {
155
  "image": path,
156
- "labels": os.path.basename(os.path.dirname(path)).lower(),
157
  "path": "/".join(path.split("/")[-3:]),
158
  }
159
 
160
  if self.config.name == "image-segmentation":
161
- if split == "training":
162
- images, masks = files
163
- imageId2mask = {}
164
- # iterate trought masks
165
- for mask_path in masks:
166
- mask_id = re.search('\d+', mask_path).group(0)
167
- imageId2mask[mask_id] = mask_path
168
- logger.info(f"imageId2mask check paths: {imageId2mask}")
169
- for i, path in enumerate(files):
170
- file_name = os.path.basename(path)
171
- if file_name.endswith(".png"):
172
- yield i, {
173
- "image": path,
174
- "labels": imageId2mask[re.search('\d+', file_name).group(0)]
175
  }
176
-
 
90
  if self.config.name == "image-segmentation":
91
  features = datasets.Features({
92
  "image": datasets.Image(),
93
+ "masks": datasets.Image(),
94
+ "path": datasets.features.Value("string"),
95
  })
96
+ keys = ("image", "masks")
97
 
98
 
99
  return datasets.DatasetInfo(
 
150
  if self.config.name == "image-classification":
151
  for i, path in enumerate(files):
152
  file_name = os.path.basename(path)
153
+ dir_name = os.path.basename(os.path.dirname(path)).lower()
154
  if dir_name != "masks" and file_name.endswith(".png"):
155
  yield i, {
156
  "image": path,
157
+ "labels": dir_name,
158
  "path": "/".join(path.split("/")[-3:]),
159
  }
160
 
161
  if self.config.name == "image-segmentation":
162
+ for i, path in enumerate(files):
163
+ file_name = os.path.basename(path)
164
+ dir_name = os.path.basename(os.path.dirname(path)).lower()
165
+ if dir_name == "glaciar" and file_name.endswith(".png"):
166
+ yield i, {
167
+ "image": path,
168
+ "masks": path.replace(dir_name, "masks"),,
169
+ "path": "/".join(path.split("/")[-3:]),
 
 
 
 
 
 
170
  }
171
+