Datasets:
Tasks:
Image Classification
Sub-tasks:
multi-class-image-classification
Languages:
English
Size:
1K<n<10K
License:
Add _generate_example for image-segmentation
Browse files- rock-glacier-dataset.py +50 -17
rock-glacier-dataset.py
CHANGED
@@ -14,6 +14,7 @@
|
|
14 |
"""Rock Glacier dataset with images of the chilean andes."""
|
15 |
|
16 |
import os
|
|
|
17 |
|
18 |
import datasets
|
19 |
from datasets.tasks import ImageClassification
|
@@ -35,11 +36,11 @@ _DESCRIPTION = """\
|
|
35 |
TODO: Add a description...
|
36 |
"""
|
37 |
|
38 |
-
_MASKS_URLS = ["https://huggingface.co/datasets/alkzar90/rock-glacier-dataset/resolve/main/data/glaciar_masks_trainset.zip"]
|
39 |
|
40 |
_URLS = {
|
41 |
"train": "https://huggingface.co/datasets/alkzar90/rock-glacier-dataset/resolve/main/data/train.zip",
|
42 |
-
"validation": "https://huggingface.co/datasets/alkzar90/rock-glacier-dataset/resolve/main/data/validation.zip"
|
|
|
43 |
}
|
44 |
|
45 |
_NAMES = ["glaciar", "cordillera"]
|
@@ -90,22 +91,38 @@ class RockGlacierDataset(datasets.GeneratorBasedBuilder):
|
|
90 |
|
91 |
def _split_generators(self, dl_manager):
|
92 |
data_files = dl_manager.download_and_extract(_URLS)
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
-
def _generate_examples(self, files):
|
109 |
|
110 |
if self.config.name == "image-classification":
|
111 |
for i, path in enumerate(files):
|
@@ -115,4 +132,20 @@ class RockGlacierDataset(datasets.GeneratorBasedBuilder):
|
|
115 |
"image": path,
|
116 |
"labels": os.path.basename(os.path.dirname(path)).lower(),
|
117 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
|
|
14 |
"""Rock Glacier dataset with images of the chilean andes."""
|
15 |
|
16 |
import os
|
17 |
+
import re
|
18 |
|
19 |
import datasets
|
20 |
from datasets.tasks import ImageClassification
|
|
|
36 |
TODO: Add a description...
|
37 |
"""
|
38 |
|
|
|
39 |
|
40 |
_URLS = {
|
41 |
"train": "https://huggingface.co/datasets/alkzar90/rock-glacier-dataset/resolve/main/data/train.zip",
|
42 |
+
"validation": "https://huggingface.co/datasets/alkzar90/rock-glacier-dataset/resolve/main/data/validation.zip",
|
43 |
+
"train_mask": "https://huggingface.co/datasets/alkzar90/rock-glacier-dataset/resolve/main/data/glaciar_masks_trainset.zip",
|
44 |
}
|
45 |
|
46 |
_NAMES = ["glaciar", "cordillera"]
|
|
|
91 |
|
92 |
def _split_generators(self, dl_manager):
|
93 |
data_files = dl_manager.download_and_extract(_URLS)
|
94 |
+
|
95 |
+
if self.config.name == "image-classification":
|
96 |
+
return [
|
97 |
+
datasets.SplitGenerator(
|
98 |
+
name=datasets.Split.TRAIN,
|
99 |
+
gen_kwargs={
|
100 |
+
"files": dl_manager.iter_files([data_files["train"]]),
|
101 |
+
"split": "training",
|
102 |
+
},
|
103 |
+
),
|
104 |
+
datasets.SplitGenerator(
|
105 |
+
name=datasets.Split.VALIDATION,
|
106 |
+
gen_kwargs={
|
107 |
+
"files": dl_manager.iter_files([data_files["validation"]]),
|
108 |
+
"split": "validation",
|
109 |
+
},
|
110 |
+
),
|
111 |
+
]
|
112 |
+
|
113 |
+
if self.config.name == "image-segmentation":
|
114 |
+
train_data = dl_manager.iter_files(data_files["train"]), dl_manager.iter_files(data_files["train_mask"])
|
115 |
+
return [
|
116 |
+
datasets.SplitGenerator(
|
117 |
+
name=datasets.Split.TRAIN,
|
118 |
+
gen_kwargs={
|
119 |
+
"files": train_data,
|
120 |
+
"split": "training",
|
121 |
+
},
|
122 |
+
)]
|
123 |
+
|
124 |
|
125 |
+
def _generate_examples(self, files, split):
|
126 |
|
127 |
if self.config.name == "image-classification":
|
128 |
for i, path in enumerate(files):
|
|
|
132 |
"image": path,
|
133 |
"labels": os.path.basename(os.path.dirname(path)).lower(),
|
134 |
}
|
135 |
+
|
136 |
+
if self.config.name == "image-segmentation":
|
137 |
+
if split == "training":
|
138 |
+
images, masks = files
|
139 |
+
imageId2mask = {}
|
140 |
+
# iterate trought masks
|
141 |
+
for mask_path in masks:
|
142 |
+
mask_id = re.search('\d+', mask_path).group(0)
|
143 |
+
imageId2mask[mask_id] = mask_path
|
144 |
+
for i, path in enumerate(files):
|
145 |
+
file_name = os.path.basename(path)
|
146 |
+
if file_name.endswith(".png"):
|
147 |
+
yield i, {
|
148 |
+
"image": path,
|
149 |
+
"labels": imageId2mask[re.search('\d+', file_name).group(0)]
|
150 |
+
}
|
151 |
|