yw26342 commited on
Commit
adbe691
·
1 Parent(s): bc13f99

Upload food500.py

Browse files
Files changed (1) hide show
  1. food500.py +607 -0
food500.py ADDED
@@ -0,0 +1,607 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2021 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """Dataset class for ISIA Food-500 dataset."""
16
+
17
+ import datasets
18
+ from datasets.tasks import ImageClassification
19
+
20
+
21
+ _BASE_URL = "http://123.57.42.89/Dataset_ict/ISIA_Food500_Dir/dataset/ISIA_Food500.zip"
22
+
23
+ _METADATA_URL = "http://123.57.42.89/Dataset_ict/ISIA_Food500_Dir/dataset/metadata_ISIAFood_500.zip"
24
+
25
+ _HOMEPAGE = "http://123.57.42.89/FoodComputing-Dataset/ISIA-Food500.html"
26
+
27
+ _DESCRIPTION = "ABCDescription"
28
+
29
+ _CITATION = "ABCCitation"
30
+
31
+ _LICENSE = "ABCLicense"
32
+
33
+ _NAMES = [
34
+ 'Abalone',
35
+ 'Aburaage',
36
+ 'Æbleflæsk',
37
+ 'Agedashi_tofu',
38
+ 'Aligot',
39
+ 'Almond_biscuit',
40
+ 'Aloo_gobi',
41
+ 'Ambrosia_(fruit_salad)',
42
+ 'Anago',
43
+ 'Andong_jjimdak',
44
+ 'Ants_climbing_a_tree',
45
+ 'Anzac_biscuit',
46
+ 'Apple_cobbler',
47
+ 'Apple_crisp',
48
+ 'Apple_dumpling',
49
+ 'Apple_pie',
50
+ 'Apple_sauce',
51
+ 'Apple_strudel',
52
+ 'Applesauce_cake',
53
+ 'Arab_salad',
54
+ 'Arancini',
55
+ 'Arròs_negre',
56
+ 'Asam_pedas',
57
+ 'Avocado_bread',
58
+ 'Avocado_fries',
59
+ 'Avocado_key_lime_pie',
60
+ 'Avocado_sauce',
61
+ 'Avocado_toast',
62
+ 'Ayam_bakar',
63
+ 'Ayam_betutu',
64
+ 'Ayam_goreng',
65
+ 'Babi_panggang',
66
+ 'Bacon_and_eggs',
67
+ 'Bacon_egg_and_cheese_sandwich',
68
+ 'Bacon_explosion',
69
+ 'Bacon_sandwich',
70
+ 'Baingan_bharta',
71
+ 'Baked_beans',
72
+ 'Banana_bread',
73
+ 'Banana_pancakes',
74
+ 'Banana_pudding',
75
+ 'Banana_salad',
76
+ 'Banana_split',
77
+ 'Bandeja_paisa',
78
+ 'Bangers_and_mash',
79
+ 'Banh_bo',
80
+ 'Bánh_canh',
81
+ 'Bánh_chuối',
82
+ 'Bean_pie',
83
+ 'Bean_salad',
84
+ 'Beef_bun',
85
+ 'Beef_chow_fun',
86
+ 'Beef_noodle_soup',
87
+ 'Beef_Wellington',
88
+ 'Beignet',
89
+ 'Bibimbap',
90
+ 'Bibingka',
91
+ 'Biryani',
92
+ 'Bisque_food',
93
+ 'Bistek',
94
+ 'Black_Forest_gateau',
95
+ 'Black_pepper_crab',
96
+ 'Blackberry_pie',
97
+ 'Blancmange',
98
+ 'BLT_sandwich',
99
+ 'Blueberry_pie',
100
+ 'Boiled_beef',
101
+ 'Boiled_peanuts',
102
+ 'Bon_bon_chicken',
103
+ 'Borscht',
104
+ 'Botan-ebi',
105
+ 'Botifarra',
106
+ 'Bouillabaisse',
107
+ 'Bourbon_chicken',
108
+ 'Bread_roll',
109
+ 'Broccoli_slaw',
110
+ 'Brown_stew_chicken',
111
+ 'Bruschetta',
112
+ 'Bubur_ayam',
113
+ 'Bubur_kacang_hijau',
114
+ 'Bugnes',
115
+ 'Bun_bo_hue',
116
+ 'Bún_ốc',
117
+ 'Bún_riêu',
118
+ 'Burrito',
119
+ 'Butadon',
120
+ 'Butter_cake',
121
+ 'Butter_pecan',
122
+ 'Butter_pie',
123
+ 'Buttercream',
124
+ 'Buttery_bread',
125
+ 'Cabbage_soup',
126
+ 'Caesar_salad',
127
+ 'Café_liégeois',
128
+ 'Calamari',
129
+ 'Caldo_verde',
130
+ 'Caprese_salad',
131
+ 'Carpaccio',
132
+ 'Carrot_bread',
133
+ 'Carrot_cake',
134
+ 'Carrot_cake_cookie',
135
+ 'Carrot_chips',
136
+ 'Carrot_juice',
137
+ 'Carrot_salad',
138
+ 'Carrot_soup',
139
+ 'Cassoulet',
140
+ 'Cebolada',
141
+ 'Ceviche',
142
+ 'Chakli',
143
+ 'Champurrado',
144
+ 'Char_kway_teow',
145
+ 'Charqui',
146
+ 'Chazuke',
147
+ 'Cheese_and_tomato_sandwich',
148
+ 'Cheese_bun',
149
+ 'Cheese_fries',
150
+ 'Cheese_maki',
151
+ 'Cheese_pudding',
152
+ 'Cheese_roll',
153
+ 'Cheesecake',
154
+ 'Cherry_cake',
155
+ 'Cherry_ice_cream',
156
+ 'Cherry_pie',
157
+ 'Chicken_and_waffles',
158
+ 'Chicken_cacciatore',
159
+ 'Chicken_curry',
160
+ 'Chicken_fingers',
161
+ 'Chicken_Kiev',
162
+ 'Chicken_marsala',
163
+ 'Chicken_noodle_soup',
164
+ 'Chicken_nugget',
165
+ 'Chicken_parmigiana',
166
+ 'Chicken_salad',
167
+ 'Chicken_soup',
168
+ 'Chiles_en_nogada',
169
+ 'Chili_con_carne',
170
+ 'Chilli_crab',
171
+ 'Chinese_chicken_salad',
172
+ 'Chocolate_covered_strawberries',
173
+ 'Chocolate_marshmallow_pie',
174
+ 'Chow_mein',
175
+ 'Chowder',
176
+ 'Christmas_cake',
177
+ 'Churro',
178
+ 'Ciambelle',
179
+ 'Çiğ_köfte',
180
+ 'Clam_chowder',
181
+ 'Claypot_chicken_rice',
182
+ 'Club_sandwich',
183
+ 'Cobbler_food',
184
+ 'Coconut_cake',
185
+ 'Coconut_cream',
186
+ 'Coconut_shrimp',
187
+ 'Coda_alla_vaccinara',
188
+ 'Coffee_jelly',
189
+ 'Colcannon',
190
+ 'Coleslaw',
191
+ 'Congee',
192
+ 'Corn_chip',
193
+ 'Corn_crab_soup',
194
+ 'Corn_dog',
195
+ 'Corn_soup',
196
+ 'Corn_stew',
197
+ 'Corn_tortilla',
198
+ 'Corned_beef_sandwich',
199
+ 'Cotoletta',
200
+ 'Crab_cake',
201
+ 'Crab_dip',
202
+ 'Crab_in_Padang_sauce',
203
+ 'Crab_puff',
204
+ 'Crab_rangoon',
205
+ 'Cream_of_broccoli_soup',
206
+ 'Cream_of_mushroom_soup',
207
+ 'Cream_pie',
208
+ 'Creamed_eggs_on_toast',
209
+ 'Croissant',
210
+ 'Crudo',
211
+ 'Crumble',
212
+ 'Cucumber_soup',
213
+ 'Cured_salmon',
214
+ 'Curry_goat',
215
+ 'Curry_Mee',
216
+ 'Curry_rice',
217
+ 'Currywurst',
218
+ 'Dandan_noodles',
219
+ 'Deep-fried_peanuts',
220
+ 'Denver_omelette',
221
+ 'Denver_sandwich',
222
+ 'Dhokla',
223
+ 'Di_san_xian',
224
+ 'Dinuguan',
225
+ 'Dirty_Rice',
226
+ 'Dong\'an_chicken',
227
+ 'Doufunao',
228
+ 'Doughnut',
229
+ 'Drunken_chicken',
230
+ 'Drunken_shrimp',
231
+ 'Duck_soup_noodles',
232
+ 'Edamame',
233
+ 'Eggplant_omelette',
234
+ 'Eisbein',
235
+ 'Es_campur',
236
+ 'Es_pisang_ijo',
237
+ 'Filet_mignon',
238
+ 'Fish_ball',
239
+ 'Fish_chowder',
240
+ 'Fish_head_casserole',
241
+ 'Fish_head_curry',
242
+ 'Fish_soup',
243
+ 'Fish_steak',
244
+ 'Fishcake',
245
+ 'Fondue',
246
+ 'Francesinha',
247
+ 'Frappe',
248
+ 'French_onion_soup',
249
+ 'French_toast',
250
+ 'Fricassee',
251
+ 'Fried_aubergine',
252
+ 'Fried_cheese',
253
+ 'Fried_chicken',
254
+ 'Fried_noodles',
255
+ 'Fried_onion',
256
+ 'Fried_rice',
257
+ 'Fried_Tofu',
258
+ 'Fruit_curd',
259
+ 'Fuqi_feipian',
260
+ 'Galbi',
261
+ 'Garlic_bread',
262
+ 'Gejang',
263
+ 'Ginger_beef',
264
+ 'Gołąbki',
265
+ 'Goulash',
266
+ 'Gravlax',
267
+ 'Greek_salad',
268
+ 'Green_bean_casserole',
269
+ 'Green_papaya_salad',
270
+ 'Grits',
271
+ 'Gulai_Ayam',
272
+ 'Gyutan',
273
+ 'Hae_mee',
274
+ 'Hainanese_chicken_rice',
275
+ 'Ham_and_cheese_sandwich',
276
+ 'Ham_salad',
277
+ 'Ham_sandwich',
278
+ 'hamburgers',
279
+ 'Har_gow',
280
+ 'Hiyayakko',
281
+ 'Hokkien_mee',
282
+ 'Hongshao_rou',
283
+ 'Hoppin\'_John',
284
+ 'Hot_and_sour_soup',
285
+ 'Huangqiao_sesame_cake',
286
+ 'Huevos_rancheros',
287
+ 'Hummus',
288
+ 'Ikan_bakar',
289
+ 'Ikan_goreng',
290
+ 'Israeli_salad',
291
+ 'Italian_tomato_pie',
292
+ 'Jajangmyeon',
293
+ 'Jambalaya',
294
+ 'Jambonneau',
295
+ 'Japchae',
296
+ 'Jewish_apple_cake',
297
+ 'Jiuniang',
298
+ 'Kachori',
299
+ 'Kadhi',
300
+ 'Kakuni',
301
+ 'Katsudon',
302
+ 'kebab',
303
+ 'Kedgeree',
304
+ 'Key_lime_pie',
305
+ 'Konnyaku',
306
+ 'Korean_fried_chicken',
307
+ 'Kung_Pao_chicken',
308
+ 'Kwetiau_goreng',
309
+ 'Laddu',
310
+ 'Laksa',
311
+ 'Lamb_chop',
312
+ 'Lasagna',
313
+ 'Lebkuchen',
314
+ 'Leek_soup',
315
+ 'Lemon_chicken',
316
+ 'Lemon_ice_box_pie',
317
+ 'Lemon_meringue_pie',
318
+ 'Lemon_tart',
319
+ 'Lemonade',
320
+ 'Lentil_soup',
321
+ 'Lettuce_soup',
322
+ 'Lo_mein',
323
+ 'Lobster_bisque',
324
+ 'Lohikeitto',
325
+ 'Macaron',
326
+ 'Mango_pomelo_sago',
327
+ 'Mango_pudding',
328
+ 'Mapo_doufu',
329
+ 'Meatloaf',
330
+ 'Mee_pok',
331
+ 'Mee_siam',
332
+ 'Melt_sandwich',
333
+ 'Menudo',
334
+ 'Mì_Quảng',
335
+ 'Michigan_hot_dog',
336
+ 'Mie_goreng',
337
+ 'Milk_Shake',
338
+ 'Minestrone',
339
+ 'Mirchi_ka_salan',
340
+ 'Mission_burrito',
341
+ 'Mongolian_beef',
342
+ 'Mousse',
343
+ 'Mozzarella_sticks',
344
+ 'Mushroom_gravy',
345
+ 'Mushy_peas',
346
+ 'Mutton_handi',
347
+ 'Mutton_korma',
348
+ 'Nachos',
349
+ 'Naengmyeon',
350
+ 'Nasi_goreng',
351
+ 'Nasi_kuning',
352
+ 'Nasi_liwet',
353
+ 'Nattō',
354
+ 'Noodle_soup',
355
+ 'Nuomici',
356
+ 'Okinawa_soba',
357
+ 'Olivier_salad',
358
+ 'Onigiri',
359
+ 'Onion_ring',
360
+ 'Orange_chicken',
361
+ 'Oyster_omelette',
362
+ 'Oysters_Rockefeller',
363
+ 'Pączki',
364
+ 'Paella',
365
+ 'Pakora',
366
+ 'Panzanella',
367
+ 'Pappa_al_pomodoro',
368
+ 'Parmigiana',
369
+ 'Pasta',
370
+ 'Pasta_al_pomodoro',
371
+ 'Pasta_alla_Norma',
372
+ 'Pasteis_de_Bacalhau',
373
+ 'Paupiette',
374
+ 'Payasam',
375
+ 'Pea_soup',
376
+ 'Peanut_butter_cookie',
377
+ 'Peanut_soup',
378
+ 'Pho',
379
+ 'Pickled_cucumber',
380
+ 'Pig\'s_ear',
381
+ 'Pig\'s_organ_soup',
382
+ 'Pig\'s_trotters',
383
+ 'Pineapple_tart',
384
+ 'Pipikaula',
385
+ 'Pizza_carbonara',
386
+ 'Pizza_pugliese',
387
+ 'Plateau_de_fruits_de_mer',
388
+ 'Plum_cake',
389
+ 'Pommes_dauphine',
390
+ 'Poori',
391
+ 'Porchetta',
392
+ 'Pork_ball',
393
+ 'Pork_blood_soup',
394
+ 'Pork_knuckle',
395
+ 'Pork_Knuckles_and_Ginger_Stew',
396
+ 'Pork_ribs',
397
+ 'Pork_tenderloin',
398
+ 'Pork_tenderloin_sandwich',
399
+ 'Pot_roast',
400
+ 'Potato_salad',
401
+ 'Poutine',
402
+ 'Prawn_cocktail',
403
+ 'Prawn_soup',
404
+ 'Princess_cake',
405
+ 'Profiterole',
406
+ 'Pudding_corn',
407
+ 'Pulled_pork',
408
+ 'Pumpkin_bread',
409
+ 'Pumpkin_pie',
410
+ 'Quesadilla',
411
+ 'Queso_flameado',
412
+ 'Quiche_Lorraine',
413
+ 'Rack_of_lamb',
414
+ 'Raita',
415
+ 'Ramen',
416
+ 'Red_bean_cake',
417
+ 'Red_bean_ice',
418
+ 'Red_beans_and_rice',
419
+ 'Red_slaw',
420
+ 'Refried_beans',
421
+ 'Rendang',
422
+ 'Rice_and_peas',
423
+ 'Rice_ball',
424
+ 'Rice_cakes',
425
+ 'Rice_pudding',
426
+ 'Rogan_josh',
427
+ 'Rou_jia_mo',
428
+ 'Rouladen',
429
+ 'Salmon_pie',
430
+ 'Sambar',
431
+ 'Samgyetang',
432
+ 'Samosa',
433
+ 'Sapo_tahu',
434
+ 'Sardine',
435
+ 'Sashimi',
436
+ 'Sauerbraten',
437
+ 'Sausage_and_peppers',
438
+ 'Sausage_bun',
439
+ 'Sausage_roll',
440
+ 'Sausage_sandwich',
441
+ 'Sauteed_mushrooms',
442
+ 'Scampi',
443
+ 'Schweinshaxe',
444
+ 'Seafood_boil',
445
+ 'Seafood_pizza',
446
+ 'Sesame_chicken',
447
+ 'Shaker_Lemon_Pie',
448
+ 'Shanghai_fried_noodles',
449
+ 'She-crab_soup',
450
+ 'Sheep\'s_trotters',
451
+ 'Shrimp_ball',
452
+ 'Shrimp_toast',
453
+ 'Shuizhu',
454
+ 'Sicilian_orange_salad',
455
+ 'Sliced_fish_soup',
456
+ 'Smoked_salmon',
457
+ 'Soba',
458
+ 'Soft-shell_crab',
459
+ 'Sopa_de_Mandioca',
460
+ 'Soused_herring',
461
+ 'Spanish_rice',
462
+ 'Spatzle',
463
+ 'Spiced_beef',
464
+ 'Spinach_salad',
465
+ 'Spinach_soup',
466
+ 'Squash_soup',
467
+ 'Steak_tartare',
468
+ 'Steamed_clams',
469
+ 'Steamed_meatball',
470
+ 'Steamed_rice',
471
+ 'Stew_peas',
472
+ 'Stinky_tofu',
473
+ 'Stir-fried_tomato_and_scrambled_eggs',
474
+ 'Strawberry_cake',
475
+ 'Strawberry_cheesecake',
476
+ 'Strawberry_ice_cream',
477
+ 'Strawberry_jam',
478
+ 'Strawberry_pie',
479
+ 'Strawberry_sundae',
480
+ 'Strawberry_tart',
481
+ 'Stuffed_avocado',
482
+ 'Stuffed_eggplant',
483
+ 'Stuffed_mushrooms',
484
+ 'Stuffed_peppers',
485
+ 'Stuffed_tomatoes',
486
+ 'Suanmeitang',
487
+ 'Succotash',
488
+ 'Suckling_pig',
489
+ 'Svíčková',
490
+ 'Sweet_potato_pie',
491
+ 'Sweet_saffron_rice',
492
+ 'Syrniki',
493
+ 'Tabbouleh',
494
+ 'Tacos',
495
+ 'Tafelspitz',
496
+ 'Takoyaki',
497
+ 'Taro_dumpling',
498
+ 'Tinga_dish',
499
+ 'Tiramisu',
500
+ 'Toad_in_the_hole',
501
+ 'Tobiko',
502
+ 'Tomato_and_egg_soup',
503
+ 'Tomato_bredie',
504
+ 'Tomato_omelette',
505
+ 'Tomato_soup',
506
+ 'Tonkatsu',
507
+ 'Tonkotsu_ramen',
508
+ 'Torta_caprese',
509
+ 'Tostada',
510
+ 'Tourtière',
511
+ 'Tsukemono',
512
+ 'Tuna_fish_sandwich',
513
+ 'Tuna_salad',
514
+ 'Turnip_cake',
515
+ 'Twix',
516
+ 'Unagi',
517
+ 'Vegetarian_chili',
518
+ 'Vichyssoise',
519
+ 'Vindaloo',
520
+ 'Vitello_tonnato',
521
+ 'Wakame',
522
+ 'Wenchang_chicken',
523
+ 'White_boiled_shrimp',
524
+ 'White_cut_chicken',
525
+ 'Whitebait',
526
+ 'Wonton_noodles',
527
+ 'Wotou',
528
+ 'Yeung_Chow_fried_rice',
529
+ 'Youtiao',
530
+ 'Yuxiangrousi',
531
+ 'Zhajiangmian',
532
+ 'Zongzi',
533
+ 'Zurcher_Geschnetzeltes',
534
+ ]
535
+
536
+ _IMAGES_DIR = "ISIA_Food500/images"
537
+
538
+ _TRAIN_TXT = "metadata_ISIAFood_500/train_feature.txt"
539
+
540
+ _VALID_TXT = "metadata_ISIAFood_500/val_feature.txt"
541
+
542
+ _TEST_TXT = "metadata_ISIAFood_500/test_feature.txt"
543
+
544
+
545
+ class Food500(datasets.GeneratorBasedBuilder):
546
+ """Food-500 Images dataset."""
547
+
548
+ def _info(self):
549
+
550
+ return datasets.DatasetInfo(
551
+ description=_DESCRIPTION,
552
+ features=datasets.Features(
553
+ {
554
+ "image": datasets.Image(),
555
+ "label": datasets.ClassLabel(names=_NAMES),
556
+ }
557
+ ),
558
+ supervised_keys=("image", "label"),
559
+ homepage=_HOMEPAGE,
560
+ citation=_CITATION,
561
+ license=_LICENSE,
562
+ task_templates=[ImageClassification(image_column="image", label_column="label")],
563
+ )
564
+
565
+ def _split_generators(self, dl_manager):
566
+ archive_path = dl_manager.download(_BASE_URL)
567
+ split_metadata_path = dl_manager.download(_METADATA_URL)
568
+ metadata = dl_manager.iter_archive(split_metadata_path)
569
+ for file_path, file_obj in metadata:
570
+ if file_path == _TRAIN_TXT: train_file = file_obj
571
+ if file_path == _VALID_TXT: valid_file = file_obj
572
+ if file_path == _TEST_TXT: test_file = file_obj
573
+ return [
574
+ datasets.SplitGenerator(
575
+ name=datasets.Split.TRAIN,
576
+ gen_kwargs={
577
+ "images": dl_manager.iter_archive(archive_path),
578
+ "metadata_file": train_file,
579
+ },
580
+ ),
581
+ datasets.SplitGenerator(
582
+ name=datasets.Split.VALIDATION,
583
+ gen_kwargs={
584
+ "images": dl_manager.iter_archive(archive_path),
585
+ "metadata_file": valid_file,
586
+ },
587
+ ),
588
+ datasets.SplitGenerator(
589
+ name=datasets.Split.TEST,
590
+ gen_kwargs={
591
+ "images": dl_manager.iter_archive(archive_path),
592
+ "metadata_file": split_metadata_path + test_file,
593
+ },
594
+ ),
595
+ ]
596
+
597
+ def _generate_examples(self, images, metadata_file):
598
+ """Generate images and labels for splits."""
599
+ files_to_keep = set(metadata_file.read().split("\n"))
600
+ for file_path, file_obj in images:
601
+ if file_path.startswith(_IMAGES_DIR):
602
+ if file_path[len(_IMAGES_DIR) : -len(".jpg")] in files_to_keep:
603
+ label = file_path.split("/")[2]
604
+ yield file_path, {
605
+ "image": {"path": file_path, "bytes": file_obj.read()},
606
+ "label": label,
607
+ }