Update Superimposed-Masked-Dataset.py
Browse files- 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.
|
61 |
-
mask_archives = dl_manager.
|
62 |
-
|
63 |
return [
|
64 |
datasets.SplitGenerator(
|
65 |
name="SMD",
|
66 |
gen_kwargs={
|
67 |
-
"archives":
|
68 |
-
"mask_archives":
|
69 |
},
|
70 |
),
|
71 |
]
|
72 |
-
|
73 |
def _generate_examples(self, archives, mask_archives):
|
74 |
"""Yields examples."""
|
75 |
idx = 0
|
76 |
-
|
77 |
-
|
78 |
-
for path, file in mask_archive:
|
79 |
if path.endswith(".npy"):
|
80 |
mask_files[path] = np.load(BytesIO(file.read()))
|
81 |
-
|
82 |
-
|
|
|
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
|