holylovenia
commited on
Commit
•
cabfa8d
1
Parent(s):
0279a9c
Upload cub_bahasa.py with huggingface_hub
Browse files- cub_bahasa.py +386 -0
cub_bahasa.py
ADDED
@@ -0,0 +1,386 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
from pathlib import Path
|
3 |
+
from typing import Dict, List, Tuple
|
4 |
+
|
5 |
+
import datasets
|
6 |
+
import pandas as pd
|
7 |
+
|
8 |
+
from seacrowd.utils import schemas
|
9 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
10 |
+
from seacrowd.utils.constants import Tasks, Licenses
|
11 |
+
|
12 |
+
_CITATION = """\
|
13 |
+
@article{mahadi2023indonesian,
|
14 |
+
author = {Made Raharja Surya Mahadi and Nugraha Priya Utama},
|
15 |
+
title = {Indonesian Text-to-Image Synthesis with Sentence-BERT and FastGAN},
|
16 |
+
journal = {arXiv preprint arXiv:2303.14517},
|
17 |
+
year = {2023},
|
18 |
+
url = {https://arxiv.org/abs/2303.14517},
|
19 |
+
}
|
20 |
+
"""
|
21 |
+
|
22 |
+
_DATASETNAME = "cub_bahasa"
|
23 |
+
_DESCRIPTION = """\
|
24 |
+
Semi-translated dataset of CUB-200-2011 into Indonesian. This dataset contains thousands
|
25 |
+
of image-text annotation pairs of 200 subcategories belonging to birds. The natural
|
26 |
+
language descriptions are collected through the Amazon Mechanical Turk (AMT) platform and
|
27 |
+
are required at least 10 words, without any information on subcategories and actions.
|
28 |
+
"""
|
29 |
+
|
30 |
+
_LOCAL=False
|
31 |
+
_LANGUAGES = ["ind"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
|
32 |
+
|
33 |
+
_HOMEPAGE = "https://github.com/share424/Indonesian-Text-to-Image-synthesis-with-Sentence-BERT-and-FastGAN"
|
34 |
+
_LICENSE = Licenses.UNKNOWN.value
|
35 |
+
_URLS = {
|
36 |
+
"text": "https://raw.githubusercontent.com/share424/Indonesian-Text-to-Image-synthesis-with-Sentence-BERT-and-FastGAN/master/dataset/indo_cub_200_2011_captions.json",
|
37 |
+
"image": "https://data.caltech.edu/records/65de6-vp158/files/CUB_200_2011.tgz"
|
38 |
+
}
|
39 |
+
|
40 |
+
_SUPPORTED_TASKS = [Tasks.IMAGE_CAPTIONING]
|
41 |
+
_SOURCE_VERSION = "1.0.0"
|
42 |
+
_SEACROWD_VERSION = "2024.06.20"
|
43 |
+
|
44 |
+
|
45 |
+
class CubBahasaDataset(datasets.GeneratorBasedBuilder):
|
46 |
+
"""CUB-200-2011 image-text dataset in Indonesian language for bird domain."""
|
47 |
+
|
48 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
49 |
+
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
|
50 |
+
|
51 |
+
SEACROWD_SCHEMA_NAME = "imtext"
|
52 |
+
IMAGE_CLASS = {
|
53 |
+
1: '001.Black_footed_Albatross',
|
54 |
+
2: '002.Laysan_Albatross',
|
55 |
+
3: '003.Sooty_Albatross',
|
56 |
+
4: '004.Groove_billed_Ani',
|
57 |
+
5: '005.Crested_Auklet',
|
58 |
+
6: '006.Least_Auklet',
|
59 |
+
7: '007.Parakeet_Auklet',
|
60 |
+
8: '008.Rhinoceros_Auklet',
|
61 |
+
9: '009.Brewer_Blackbird',
|
62 |
+
10: '010.Red_winged_Blackbird',
|
63 |
+
11: '011.Rusty_Blackbird',
|
64 |
+
12: '012.Yellow_headed_Blackbird',
|
65 |
+
13: '013.Bobolink',
|
66 |
+
14: '014.Indigo_Bunting',
|
67 |
+
15: '015.Lazuli_Bunting',
|
68 |
+
16: '016.Painted_Bunting',
|
69 |
+
17: '017.Cardinal',
|
70 |
+
18: '018.Spotted_Catbird',
|
71 |
+
19: '019.Gray_Catbird',
|
72 |
+
20: '020.Yellow_breasted_Chat',
|
73 |
+
21: '021.Eastern_Towhee',
|
74 |
+
22: '022.Chuck_will_Widow',
|
75 |
+
23: '023.Brandt_Cormorant',
|
76 |
+
24: '024.Red_faced_Cormorant',
|
77 |
+
25: '025.Pelagic_Cormorant',
|
78 |
+
26: '026.Bronzed_Cowbird',
|
79 |
+
27: '027.Shiny_Cowbird',
|
80 |
+
28: '028.Brown_Creeper',
|
81 |
+
29: '029.American_Crow',
|
82 |
+
30: '030.Fish_Crow',
|
83 |
+
31: '031.Black_billed_Cuckoo',
|
84 |
+
32: '032.Mangrove_Cuckoo',
|
85 |
+
33: '033.Yellow_billed_Cuckoo',
|
86 |
+
34: '034.Gray_crowned_Rosy_Finch',
|
87 |
+
35: '035.Purple_Finch',
|
88 |
+
36: '036.Northern_Flicker',
|
89 |
+
37: '037.Acadian_Flycatcher',
|
90 |
+
38: '038.Great_Crested_Flycatcher',
|
91 |
+
39: '039.Least_Flycatcher',
|
92 |
+
40: '040.Olive_sided_Flycatcher',
|
93 |
+
41: '041.Scissor_tailed_Flycatcher',
|
94 |
+
42: '042.Vermilion_Flycatcher',
|
95 |
+
43: '043.Yellow_bellied_Flycatcher',
|
96 |
+
44: '044.Frigatebird',
|
97 |
+
45: '045.Northern_Fulmar',
|
98 |
+
46: '046.Gadwall',
|
99 |
+
47: '047.American_Goldfinch',
|
100 |
+
48: '048.European_Goldfinch',
|
101 |
+
49: '049.Boat_tailed_Grackle',
|
102 |
+
50: '050.Eared_Grebe',
|
103 |
+
51: '051.Horned_Grebe',
|
104 |
+
52: '052.Pied_billed_Grebe',
|
105 |
+
53: '053.Western_Grebe',
|
106 |
+
54: '054.Blue_Grosbeak',
|
107 |
+
55: '055.Evening_Grosbeak',
|
108 |
+
56: '056.Pine_Grosbeak',
|
109 |
+
57: '057.Rose_breasted_Grosbeak',
|
110 |
+
58: '058.Pigeon_Guillemot',
|
111 |
+
59: '059.California_Gull',
|
112 |
+
60: '060.Glaucous_winged_Gull',
|
113 |
+
61: '061.Heermann_Gull',
|
114 |
+
62: '062.Herring_Gull',
|
115 |
+
63: '063.Ivory_Gull',
|
116 |
+
64: '064.Ring_billed_Gull',
|
117 |
+
65: '065.Slaty_backed_Gull',
|
118 |
+
66: '066.Western_Gull',
|
119 |
+
67: '067.Anna_Hummingbird',
|
120 |
+
68: '068.Ruby_throated_Hummingbird',
|
121 |
+
69: '069.Rufous_Hummingbird',
|
122 |
+
70: '070.Green_Violetear',
|
123 |
+
71: '071.Long_tailed_Jaeger',
|
124 |
+
72: '072.Pomarine_Jaeger',
|
125 |
+
73: '073.Blue_Jay',
|
126 |
+
74: '074.Florida_Jay',
|
127 |
+
75: '075.Green_Jay',
|
128 |
+
76: '076.Dark_eyed_Junco',
|
129 |
+
77: '077.Tropical_Kingbird',
|
130 |
+
78: '078.Gray_Kingbird',
|
131 |
+
79: '079.Belted_Kingfisher',
|
132 |
+
80: '080.Green_Kingfisher',
|
133 |
+
81: '081.Pied_Kingfisher',
|
134 |
+
82: '082.Ringed_Kingfisher',
|
135 |
+
83: '083.White_breasted_Kingfisher',
|
136 |
+
84: '084.Red_legged_Kittiwake',
|
137 |
+
85: '085.Horned_Lark',
|
138 |
+
86: '086.Pacific_Loon',
|
139 |
+
87: '087.Mallard',
|
140 |
+
88: '088.Western_Meadowlark',
|
141 |
+
89: '089.Hooded_Merganser',
|
142 |
+
90: '090.Red_breasted_Merganser',
|
143 |
+
91: '091.Mockingbird',
|
144 |
+
92: '092.Nighthawk',
|
145 |
+
93: '093.Clark_Nutcracker',
|
146 |
+
94: '094.White_breasted_Nuthatch',
|
147 |
+
95: '095.Baltimore_Oriole',
|
148 |
+
96: '096.Hooded_Oriole',
|
149 |
+
97: '097.Orchard_Oriole',
|
150 |
+
98: '098.Scott_Oriole',
|
151 |
+
99: '099.Ovenbird',
|
152 |
+
100: '100.Brown_Pelican',
|
153 |
+
101: '101.White_Pelican',
|
154 |
+
102: '102.Western_Wood_Pewee',
|
155 |
+
103: '103.Sayornis',
|
156 |
+
104: '104.American_Pipit',
|
157 |
+
105: '105.Whip_poor_Will',
|
158 |
+
106: '106.Horned_Puffin',
|
159 |
+
107: '107.Common_Raven',
|
160 |
+
108: '108.White_necked_Raven',
|
161 |
+
109: '109.American_Redstart',
|
162 |
+
110: '110.Geococcyx',
|
163 |
+
111: '111.Loggerhead_Shrike',
|
164 |
+
112: '112.Great_Grey_Shrike',
|
165 |
+
113: '113.Baird_Sparrow',
|
166 |
+
114: '114.Black_throated_Sparrow',
|
167 |
+
115: '115.Brewer_Sparrow',
|
168 |
+
116: '116.Chipping_Sparrow',
|
169 |
+
117: '117.Clay_colored_Sparrow',
|
170 |
+
118: '118.House_Sparrow',
|
171 |
+
119: '119.Field_Sparrow',
|
172 |
+
120: '120.Fox_Sparrow',
|
173 |
+
121: '121.Grasshopper_Sparrow',
|
174 |
+
122: '122.Harris_Sparrow',
|
175 |
+
123: '123.Henslow_Sparrow',
|
176 |
+
124: '124.Le_Conte_Sparrow',
|
177 |
+
125: '125.Lincoln_Sparrow',
|
178 |
+
126: '126.Nelson_Sharp_tailed_Sparrow',
|
179 |
+
127: '127.Savannah_Sparrow',
|
180 |
+
128: '128.Seaside_Sparrow',
|
181 |
+
129: '129.Song_Sparrow',
|
182 |
+
130: '130.Tree_Sparrow',
|
183 |
+
131: '131.Vesper_Sparrow',
|
184 |
+
132: '132.White_crowned_Sparrow',
|
185 |
+
133: '133.White_throated_Sparrow',
|
186 |
+
134: '134.Cape_Glossy_Starling',
|
187 |
+
135: '135.Bank_Swallow',
|
188 |
+
136: '136.Barn_Swallow',
|
189 |
+
137: '137.Cliff_Swallow',
|
190 |
+
138: '138.Tree_Swallow',
|
191 |
+
139: '139.Scarlet_Tanager',
|
192 |
+
140: '140.Summer_Tanager',
|
193 |
+
141: '141.Artic_Tern',
|
194 |
+
142: '142.Black_Tern',
|
195 |
+
143: '143.Caspian_Tern',
|
196 |
+
144: '144.Common_Tern',
|
197 |
+
145: '145.Elegant_Tern',
|
198 |
+
146: '146.Forsters_Tern',
|
199 |
+
147: '147.Least_Tern',
|
200 |
+
148: '148.Green_tailed_Towhee',
|
201 |
+
149: '149.Brown_Thrasher',
|
202 |
+
150: '150.Sage_Thrasher',
|
203 |
+
151: '151.Black_capped_Vireo',
|
204 |
+
152: '152.Blue_headed_Vireo',
|
205 |
+
153: '153.Philadelphia_Vireo',
|
206 |
+
154: '154.Red_eyed_Vireo',
|
207 |
+
155: '155.Warbling_Vireo',
|
208 |
+
156: '156.White_eyed_Vireo',
|
209 |
+
157: '157.Yellow_throated_Vireo',
|
210 |
+
158: '158.Bay_breasted_Warbler',
|
211 |
+
159: '159.Black_and_white_Warbler',
|
212 |
+
160: '160.Black_throated_Blue_Warbler',
|
213 |
+
161: '161.Blue_winged_Warbler',
|
214 |
+
162: '162.Canada_Warbler',
|
215 |
+
163: '163.Cape_May_Warbler',
|
216 |
+
164: '164.Cerulean_Warbler',
|
217 |
+
165: '165.Chestnut_sided_Warbler',
|
218 |
+
166: '166.Golden_winged_Warbler',
|
219 |
+
167: '167.Hooded_Warbler',
|
220 |
+
168: '168.Kentucky_Warbler',
|
221 |
+
169: '169.Magnolia_Warbler',
|
222 |
+
170: '170.Mourning_Warbler',
|
223 |
+
171: '171.Myrtle_Warbler',
|
224 |
+
172: '172.Nashville_Warbler',
|
225 |
+
173: '173.Orange_crowned_Warbler',
|
226 |
+
174: '174.Palm_Warbler',
|
227 |
+
175: '175.Pine_Warbler',
|
228 |
+
176: '176.Prairie_Warbler',
|
229 |
+
177: '177.Prothonotary_Warbler',
|
230 |
+
178: '178.Swainson_Warbler',
|
231 |
+
179: '179.Tennessee_Warbler',
|
232 |
+
180: '180.Wilson_Warbler',
|
233 |
+
181: '181.Worm_eating_Warbler',
|
234 |
+
182: '182.Yellow_Warbler',
|
235 |
+
183: '183.Northern_Waterthrush',
|
236 |
+
184: '184.Louisiana_Waterthrush',
|
237 |
+
185: '185.Bohemian_Waxwing',
|
238 |
+
186: '186.Cedar_Waxwing',
|
239 |
+
187: '187.American_Three_toed_Woodpecker',
|
240 |
+
188: '188.Pileated_Woodpecker',
|
241 |
+
189: '189.Red_bellied_Woodpecker',
|
242 |
+
190: '190.Red_cockaded_Woodpecker',
|
243 |
+
191: '191.Red_headed_Woodpecker',
|
244 |
+
192: '192.Downy_Woodpecker',
|
245 |
+
193: '193.Bewick_Wren',
|
246 |
+
194: '194.Cactus_Wren',
|
247 |
+
195: '195.Carolina_Wren',
|
248 |
+
196: '196.House_Wren',
|
249 |
+
197: '197.Marsh_Wren',
|
250 |
+
198: '198.Rock_Wren',
|
251 |
+
199: '199.Winter_Wren',
|
252 |
+
200: '200.Common_Yellowthroat'
|
253 |
+
}
|
254 |
+
|
255 |
+
BUILDER_CONFIGS = [
|
256 |
+
SEACrowdConfig(
|
257 |
+
name=f"{_DATASETNAME}_source",
|
258 |
+
version=SOURCE_VERSION,
|
259 |
+
description=f"{_DATASETNAME} source schema",
|
260 |
+
schema="source",
|
261 |
+
subset_id=f"{_DATASETNAME}",
|
262 |
+
),
|
263 |
+
SEACrowdConfig(
|
264 |
+
name=f"{_DATASETNAME}_seacrowd_{SEACROWD_SCHEMA_NAME}",
|
265 |
+
version=SEACROWD_VERSION,
|
266 |
+
description=f"{_DATASETNAME} SEACrowd schema",
|
267 |
+
schema=f"seacrowd_{SEACROWD_SCHEMA_NAME}",
|
268 |
+
subset_id=f"{_DATASETNAME}",
|
269 |
+
),
|
270 |
+
]
|
271 |
+
|
272 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
|
273 |
+
|
274 |
+
def _info(self) -> datasets.DatasetInfo:
|
275 |
+
if self.config.schema == "source":
|
276 |
+
features = datasets.Features(
|
277 |
+
{
|
278 |
+
"image_id": datasets.Value("int64"),
|
279 |
+
"class_id": datasets.Value("int64"),
|
280 |
+
"image_path": datasets.Value("string"),
|
281 |
+
"class_name": datasets.Value("string"),
|
282 |
+
"captions": [
|
283 |
+
{
|
284 |
+
"caption_eng": datasets.Value("string"),
|
285 |
+
"caption_ind": datasets.Value("string"),
|
286 |
+
}
|
287 |
+
]
|
288 |
+
}
|
289 |
+
)
|
290 |
+
elif self.config.schema == f"seacrowd_{self.SEACROWD_SCHEMA_NAME}":
|
291 |
+
features = schemas.image_text_features(label_names=list(self.IMAGE_CLASS.values()))
|
292 |
+
|
293 |
+
return datasets.DatasetInfo(
|
294 |
+
description=_DESCRIPTION,
|
295 |
+
features=features,
|
296 |
+
homepage=_HOMEPAGE,
|
297 |
+
license=_LICENSE,
|
298 |
+
citation=_CITATION,
|
299 |
+
)
|
300 |
+
|
301 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
302 |
+
# expect several minutes to download image data ~1.2GB
|
303 |
+
data_path = dl_manager.download_and_extract(_URLS)
|
304 |
+
|
305 |
+
# working with image dataset
|
306 |
+
image_meta = Path(data_path["image"]) / "CUB_200_2011" / "images.txt"
|
307 |
+
df_image = pd.read_csv(image_meta, sep=" ", names=["image_id", "image_path"])
|
308 |
+
df_image['image_path'] = df_image['image_path'].apply(lambda x: Path(image_meta.parent, 'images', x))
|
309 |
+
|
310 |
+
label_meta = Path(data_path["image"]) / "CUB_200_2011" / "image_class_labels.txt"
|
311 |
+
df_label = pd.read_csv(label_meta, sep=" ", names=["image_id", "class_id"])
|
312 |
+
|
313 |
+
# working with text dataset
|
314 |
+
text_path = Path(data_path["text"])
|
315 |
+
with open(text_path, "r") as f:
|
316 |
+
text_data = json.load(f)
|
317 |
+
|
318 |
+
df_text = pd.DataFrame([
|
319 |
+
{
|
320 |
+
'image_name': item['filename'],
|
321 |
+
'en_caption': caption['english'],
|
322 |
+
'id_caption': caption['indo']
|
323 |
+
} for item in text_data['dataset'] for caption in item['captions']
|
324 |
+
])
|
325 |
+
grouped_text = df_text.groupby('image_name').agg(list).reset_index()
|
326 |
+
|
327 |
+
# working with split
|
328 |
+
split_dir = Path(data_path["image"]) / "CUB_200_2011" / "train_test_split.txt"
|
329 |
+
df_split = pd.read_csv(split_dir, sep=" ", names=["image_id", "is_train"])
|
330 |
+
|
331 |
+
# merge all data
|
332 |
+
df_image['image_name'] = df_image['image_path'].apply(lambda x: x.name)
|
333 |
+
df = pd.merge(df_image, grouped_text, on="image_name")
|
334 |
+
df.drop(columns=['image_name'], inplace=True)
|
335 |
+
|
336 |
+
df = pd.merge(df, df_label, on="image_id")
|
337 |
+
df = pd.merge(df, df_split, on="image_id")
|
338 |
+
|
339 |
+
return [
|
340 |
+
datasets.SplitGenerator(
|
341 |
+
name=datasets.Split.TRAIN,
|
342 |
+
gen_kwargs={
|
343 |
+
"data": df[df['is_train'] == 1],
|
344 |
+
"split": "train",
|
345 |
+
},
|
346 |
+
),
|
347 |
+
datasets.SplitGenerator(
|
348 |
+
name=datasets.Split.TEST,
|
349 |
+
gen_kwargs={
|
350 |
+
"data": df[df['is_train'] == 0],
|
351 |
+
"split": "test",
|
352 |
+
},
|
353 |
+
),
|
354 |
+
]
|
355 |
+
|
356 |
+
def _generate_examples(self, data: pd.DataFrame, split: str) -> Tuple[int, Dict]:
|
357 |
+
if self.config.schema == "source":
|
358 |
+
for key, row in data.iterrows():
|
359 |
+
example = {
|
360 |
+
"image_id": row["image_id"],
|
361 |
+
"class_id": row["class_id"],
|
362 |
+
"image_path": row["image_path"],
|
363 |
+
"class_name": self.IMAGE_CLASS[row["class_id"]],
|
364 |
+
"captions": [
|
365 |
+
{
|
366 |
+
"caption_eng": row["en_caption"][i],
|
367 |
+
"caption_ind": row["id_caption"][i],
|
368 |
+
} for i in range(len(row["en_caption"]))
|
369 |
+
]
|
370 |
+
}
|
371 |
+
yield key, example
|
372 |
+
elif self.config.schema == f"seacrowd_{self.SEACROWD_SCHEMA_NAME}":
|
373 |
+
key = 0
|
374 |
+
for _, row in data.iterrows():
|
375 |
+
for i in range(len(row["id_caption"])):
|
376 |
+
example = {
|
377 |
+
"id": str(key),
|
378 |
+
"image_paths": [row["image_path"]],
|
379 |
+
"texts": row["id_caption"][i],
|
380 |
+
"metadata": {
|
381 |
+
"context": row["en_caption"][i],
|
382 |
+
"labels": [self.IMAGE_CLASS[row["class_id"]]],
|
383 |
+
}
|
384 |
+
}
|
385 |
+
yield key, example
|
386 |
+
key += 1
|