Datasets:
Federico Galatolo
commited on
Commit
·
ff20c49
1
Parent(s):
e2b666c
better categories and classes
Browse files- TeTIm-Eval.py +51 -26
TeTIm-Eval.py
CHANGED
@@ -19,7 +19,7 @@ _URLS = {
|
|
19 |
"full": "https://huggingface.co/datasets/galatolo/TeTIm-Eval/resolve/main/data/TeTIm-Eval.zip"
|
20 |
}
|
21 |
|
22 |
-
|
23 |
"digital_art",
|
24 |
"sketch_art",
|
25 |
"traditional_art",
|
@@ -32,31 +32,51 @@ _CATEGORIES = [
|
|
32 |
"person_photo"
|
33 |
]
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
_FOLDERS = {
|
37 |
"mini": {
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
},
|
49 |
"full": {
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
}
|
61 |
}
|
62 |
|
@@ -87,7 +107,8 @@ class TeTIm(datasets.GeneratorBasedBuilder):
|
|
87 |
"id": datasets.Value("int32"),
|
88 |
"image": datasets.Image(),
|
89 |
"caption": datasets.Value("string"),
|
90 |
-
"category": datasets.
|
|
|
91 |
}
|
92 |
),
|
93 |
supervised_keys=None,
|
@@ -106,7 +127,7 @@ class TeTIm(datasets.GeneratorBasedBuilder):
|
|
106 |
|
107 |
def _generate_examples(self, path):
|
108 |
id = 0
|
109 |
-
for
|
110 |
images_folder = os.path.join(path, folder, "images")
|
111 |
annotations_folder = os.path.join(path, folder, "annotations")
|
112 |
|
@@ -120,7 +141,8 @@ class TeTIm(datasets.GeneratorBasedBuilder):
|
|
120 |
"id": id,
|
121 |
"image": os.path.join(images_folder, image),
|
122 |
"caption": annotation["caption"],
|
123 |
-
"category":
|
|
|
124 |
}
|
125 |
id += 1
|
126 |
|
@@ -129,10 +151,13 @@ if __name__ == "__main__":
|
|
129 |
from datasets import load_dataset
|
130 |
dataset_config = {
|
131 |
"LOADING_SCRIPT_FILES": os.path.join(os.getcwd(), "TeTIm-Eval.py"),
|
132 |
-
"CONFIG_NAME": "
|
133 |
}
|
134 |
ds = load_dataset(
|
135 |
dataset_config["LOADING_SCRIPT_FILES"],
|
136 |
dataset_config["CONFIG_NAME"],
|
137 |
)
|
138 |
-
print(ds)
|
|
|
|
|
|
|
|
19 |
"full": "https://huggingface.co/datasets/galatolo/TeTIm-Eval/resolve/main/data/TeTIm-Eval.zip"
|
20 |
}
|
21 |
|
22 |
+
_CLASSES = [
|
23 |
"digital_art",
|
24 |
"sketch_art",
|
25 |
"traditional_art",
|
|
|
32 |
"person_photo"
|
33 |
]
|
34 |
|
35 |
+
_CATEGORIES = [
|
36 |
+
"art",
|
37 |
+
"painting",
|
38 |
+
"photo"
|
39 |
+
]
|
40 |
+
|
41 |
+
_MAP_CATEGORY = {
|
42 |
+
_CLASSES[0]: _CATEGORIES[0],
|
43 |
+
_CLASSES[1]: _CATEGORIES[0],
|
44 |
+
_CLASSES[2]: _CATEGORIES[0],
|
45 |
+
|
46 |
+
_CLASSES[3]: _CATEGORIES[1],
|
47 |
+
_CLASSES[4]: _CATEGORIES[1],
|
48 |
+
_CLASSES[5]: _CATEGORIES[1],
|
49 |
+
|
50 |
+
_CLASSES[6]: _CATEGORIES[2],
|
51 |
+
_CLASSES[7]: _CATEGORIES[2],
|
52 |
+
_CLASSES[8]: _CATEGORIES[2],
|
53 |
+
_CLASSES[9]: _CATEGORIES[2],
|
54 |
+
}
|
55 |
|
56 |
_FOLDERS = {
|
57 |
"mini": {
|
58 |
+
_CLASSES[0]: "TeTIm-Eval-Mini/sampled_art_digital",
|
59 |
+
_CLASSES[1]: "TeTIm-Eval-Mini/sampled_art_sketch",
|
60 |
+
_CLASSES[2]: "TeTIm-Eval-Mini/sampled_art_traditional",
|
61 |
+
_CLASSES[3]: "TeTIm-Eval-Mini/sampled_painting_baroque",
|
62 |
+
_CLASSES[4]: "TeTIm-Eval-Mini/sampled_painting_high-renaissance",
|
63 |
+
_CLASSES[5]: "TeTIm-Eval-Mini/sampled_painting_neoclassicism",
|
64 |
+
_CLASSES[6]: "TeTIm-Eval-Mini/sampled_photo_animal",
|
65 |
+
_CLASSES[7]: "TeTIm-Eval-Mini/sampled_photo_food",
|
66 |
+
_CLASSES[8]: "TeTIm-Eval-Mini/sampled_photo_landscape",
|
67 |
+
_CLASSES[9]: "TeTIm-Eval-Mini/sampled_photo_person",
|
68 |
},
|
69 |
"full": {
|
70 |
+
_CLASSES[0]: "TeTIm-Eval/sampled_art_digital",
|
71 |
+
_CLASSES[1]: "TeTIm-Eval/sampled_art_sketch",
|
72 |
+
_CLASSES[2]: "TeTIm-Eval/sampled_art_traditional",
|
73 |
+
_CLASSES[3]: "TeTIm-Eval/sampled_painting_baroque",
|
74 |
+
_CLASSES[4]: "TeTIm-Eval/sampled_painting_high-renaissance",
|
75 |
+
_CLASSES[5]: "TeTIm-Eval/sampled_painting_neoclassicism",
|
76 |
+
_CLASSES[6]: "TeTIm-Eval/sampled_photo_animal",
|
77 |
+
_CLASSES[7]: "TeTIm-Eval/sampled_photo_food",
|
78 |
+
_CLASSES[8]: "TeTIm-Eval/sampled_photo_landscape",
|
79 |
+
_CLASSES[9]: "TeTIm-Eval/sampled_photo_person",
|
80 |
}
|
81 |
}
|
82 |
|
|
|
107 |
"id": datasets.Value("int32"),
|
108 |
"image": datasets.Image(),
|
109 |
"caption": datasets.Value("string"),
|
110 |
+
"category": datasets.ClassLabel(num_classes=len(_CATEGORIES), names=_CATEGORIES),
|
111 |
+
"class": datasets.ClassLabel(num_classes=len(_CLASSES), names=_CLASSES)
|
112 |
}
|
113 |
),
|
114 |
supervised_keys=None,
|
|
|
127 |
|
128 |
def _generate_examples(self, path):
|
129 |
id = 0
|
130 |
+
for _class, folder in _FOLDERS[self.config.name].items():
|
131 |
images_folder = os.path.join(path, folder, "images")
|
132 |
annotations_folder = os.path.join(path, folder, "annotations")
|
133 |
|
|
|
141 |
"id": id,
|
142 |
"image": os.path.join(images_folder, image),
|
143 |
"caption": annotation["caption"],
|
144 |
+
"category": _CATEGORIES.index(_MAP_CATEGORY[_class]),
|
145 |
+
"class": _CLASSES.index(_class)
|
146 |
}
|
147 |
id += 1
|
148 |
|
|
|
151 |
from datasets import load_dataset
|
152 |
dataset_config = {
|
153 |
"LOADING_SCRIPT_FILES": os.path.join(os.getcwd(), "TeTIm-Eval.py"),
|
154 |
+
"CONFIG_NAME": "mini",
|
155 |
}
|
156 |
ds = load_dataset(
|
157 |
dataset_config["LOADING_SCRIPT_FILES"],
|
158 |
dataset_config["CONFIG_NAME"],
|
159 |
)
|
160 |
+
print(ds)
|
161 |
+
|
162 |
+
for i, e in zip(range(0, 10), ds["test"]):
|
163 |
+
print(i, e)
|