alkzar90 commited on
Commit
bd366ff
1 Parent(s): 9bef118

Add a builder configuration: image-classification + image-segmentation

Browse files
Files changed (1) hide show
  1. rock-glacier-dataset.py +57 -21
rock-glacier-dataset.py CHANGED
@@ -1,3 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  """Rock Glacier dataset with images of the chilean andes."""
2
 
3
  import os
@@ -22,6 +35,7 @@ _DESCRIPTION = """\
22
  TODO: Add a description...
23
  """
24
 
 
25
 
26
  _URLS = {
27
  "train": "https://huggingface.co/datasets/alkzar90/rock-glacier-dataset/resolve/main/data/train.zip",
@@ -31,23 +45,45 @@ _URLS = {
31
  _NAMES = ["glaciar", "cordillera"]
32
 
33
 
 
 
 
 
 
 
 
 
 
 
 
34
  class RockGlacierDataset(datasets.GeneratorBasedBuilder):
35
  """Rock Glacier images dataset."""
 
 
 
 
 
36
 
37
  def _info(self):
 
 
 
 
 
 
 
 
 
 
 
38
  return datasets.DatasetInfo(
39
- description=_DESCRIPTION,
40
- features=datasets.Features(
41
- {
42
- "image": datasets.Image(),
43
- "labels": datasets.features.ClassLabel(names=_NAMES),
44
- }
45
- ),
46
- supervised_keys=("image", "labels"),
47
- homepage=_HOMEPAGE,
48
- citation=_CITATION,
49
- task_templates=[ImageClassification(image_column="image", label_column="labels")],
50
- )
51
 
52
 
53
  def _split_generators(self, dl_manager):
@@ -68,12 +104,12 @@ class RockGlacierDataset(datasets.GeneratorBasedBuilder):
68
  ]
69
 
70
  def _generate_examples(self, files):
71
- for i, path in enumerate(files):
72
- file_name = os.path.basename(path)
73
- if file_name.endswith(".png"):
74
- yield i, {
75
- "image": path,
76
- "labels": os.path.basename(os.path.dirname(path)).lower(),
77
- }
78
-
79
-
 
1
+ # Copyright 2022 Cristóbal Alcázar
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
  """Rock Glacier dataset with images of the chilean andes."""
15
 
16
  import os
 
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",
 
45
  _NAMES = ["glaciar", "cordillera"]
46
 
47
 
48
+ class RockGlacierConfig(datasets.BuilderConfig):
49
+ """Rock Glacier dataset configuration"""
50
+ def __init__(self, name, **kwargs):
51
+ super(RockGlacierConfig).__init__(
52
+ version=datasets.Version("1.0.0"),
53
+ name=name,
54
+ description="Rock Glacier Dataset",
55
+ **kwargs,
56
+ )
57
+
58
+
59
  class RockGlacierDataset(datasets.GeneratorBasedBuilder):
60
  """Rock Glacier images dataset."""
61
+
62
+ BUILDER_CONFIGS = [
63
+ RockGlacierConfig("image-classification"),
64
+ RockGlacierConfig("image-segmentation"),
65
+ ]
66
 
67
  def _info(self):
68
+ if self.config.name == "image-classification":
69
+ features = dataset.Features({
70
+ "image": datasets.Image(),
71
+ "labels": datasets.features.ClassLabel(names=_NAMES),
72
+ })
73
+ keys = ("image", "labels")
74
+ task = [ImageClassification(image_column="image", label_column="labels")]
75
+
76
+ if self.config.name == "image-segmentation":
77
+ pass
78
+
79
  return datasets.DatasetInfo(
80
+ description=_DESCRIPTION,
81
+ features=features,
82
+ supervised_keys=("image", "labels"),
83
+ homepage=_HOMEPAGE,
84
+ citation=_CITATION,
85
+ task_templates=task,
86
+ )
 
 
 
 
 
87
 
88
 
89
  def _split_generators(self, dl_manager):
 
104
  ]
105
 
106
  def _generate_examples(self, files):
107
+
108
+ if selg.config.name == "image-classification":
109
+ for i, path in enumerate(files):
110
+ file_name = os.path.basename(path)
111
+ if file_name.endswith(".png"):
112
+ yield i, {
113
+ "image": path,
114
+ "labels": os.path.basename(os.path.dirname(path)).lower(),
115
+ }