alkzar90 commited on
Commit
77f342e
1 Parent(s): 0404e4c

Create custom dataloader script

Browse files
Files changed (1) hide show
  1. rock-glacier-dataset.py +79 -0
rock-glacier-dataset.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Rock Glacier dataset with images of the chilean andes"""
2
+
3
+ import os
4
+
5
+ import datasets
6
+ from datasets.tasks import ImageClassification
7
+
8
+ _HOMEPAGE = "https://github.com/alcazar90/rock-glacier-detection"
9
+
10
+
11
+ _CITATION = """\
12
+ @ONLINE {rock-glacier-dataset,
13
+ author="CMM-Glaciares",
14
+ title="Rock Glacier Dataset",
15
+ month="October",
16
+ year="2022",
17
+ url="https://github.com/alcazar90/rock-glacier-detection"
18
+ }
19
+ """
20
+
21
+ _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.tar.gz",
28
+ "validation": "https://huggingface.co/datasets/alkzar90/rock-glacier-dataset/resolve/main/data/val.tar.gz"
29
+ }
30
+
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):
54
+ data_files = dl_manager.download_and_extract(_URLS)
55
+ return [
56
+ datasets.SplitGenerator(
57
+ name=datasets.Split.TRAIN,
58
+ gen_kwargs={
59
+ "files": dl_manager.iter_files([data_files["train"]]),
60
+ }
61
+ ),
62
+ datasets.SplitGenerator(
63
+ name=datasets.Split.VALIDATION,
64
+ gen_kwargs={
65
+ "files": dl_manager.iter_files([data_files["validation"]]),
66
+ }
67
+ ),
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
+