ArielleE commited on
Commit
e05b334
1 Parent(s): 9b2cae2

Update Superimposed-Masked-Dataset.py

Browse files
Files changed (1) hide show
  1. Superimposed-Masked-Dataset.py +14 -13
Superimposed-Masked-Dataset.py CHANGED
@@ -57,33 +57,34 @@ class SMD(datasets.GeneratorBasedBuilder):
57
 
58
  def _split_generators(self, dl_manager):
59
  """Returns SplitGenerators."""
60
- archives = dl_manager.download(_DATA_URL)
61
- mask_archives = dl_manager.download(_MASK_DATA_URL)
62
-
63
  return [
64
  datasets.SplitGenerator(
65
  name="SMD",
66
  gen_kwargs={
67
- "archives": [dl_manager.iter_archive(archive) for archive in archives["smd"]],
68
- "mask_archives": [dl_manager.iter_archive(archive) for archive in mask_archives["smd_masks"]],
69
  },
70
  ),
71
  ]
72
-
73
  def _generate_examples(self, archives, mask_archives):
74
  """Yields examples."""
75
  idx = 0
76
- for archive, mask_archive in zip(archives, mask_archives):
77
- mask_files = {}
78
- for path, file in mask_archive:
79
  if path.endswith(".npy"):
80
  mask_files[path] = np.load(BytesIO(file.read()))
81
-
82
- for path, file in archive:
 
83
  if path.endswith(".png"):
84
  synset_id = os.path.basename(os.path.dirname(path))
85
  label = IMAGENET2012_CLASSES[synset_id]
86
-
87
  mask_file_path = path.replace("_occluded.png", "_mask.npy")
88
  segmentation_mask = mask_files.get(mask_file_path, None)
89
  if segmentation_mask is not None:
@@ -93,4 +94,4 @@ class SMD(datasets.GeneratorBasedBuilder):
93
  "segmentation": segmentation_mask.tolist() # Convert numpy array to list
94
  }
95
  yield idx, ex
96
- idx += 1
 
57
 
58
  def _split_generators(self, dl_manager):
59
  """Returns SplitGenerators."""
60
+ archives = dl_manager.download_and_extract(_DATA_URL)
61
+ mask_archives = dl_manager.download_and_extract(_MASK_DATA_URL)
62
+
63
  return [
64
  datasets.SplitGenerator(
65
  name="SMD",
66
  gen_kwargs={
67
+ "archives": archives["smd"],
68
+ "mask_archives": mask_archives["smd_masks"],
69
  },
70
  ),
71
  ]
72
+
73
  def _generate_examples(self, archives, mask_archives):
74
  """Yields examples."""
75
  idx = 0
76
+ mask_files = {}
77
+ for mask_archive in mask_archives:
78
+ for path, file in dl_manager.iter_archive(mask_archive):
79
  if path.endswith(".npy"):
80
  mask_files[path] = np.load(BytesIO(file.read()))
81
+
82
+ for archive in archives:
83
+ for path, file in dl_manager.iter_archive(archive):
84
  if path.endswith(".png"):
85
  synset_id = os.path.basename(os.path.dirname(path))
86
  label = IMAGENET2012_CLASSES[synset_id]
87
+
88
  mask_file_path = path.replace("_occluded.png", "_mask.npy")
89
  segmentation_mask = mask_files.get(mask_file_path, None)
90
  if segmentation_mask is not None:
 
94
  "segmentation": segmentation_mask.tolist() # Convert numpy array to list
95
  }
96
  yield idx, ex
97
+ idx += 1