test / test.py
yw26342's picture
Update test.py
e6c4143
# coding=utf-8
# Copyright 2021 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Dataset class for ISIA Food-500 dataset."""
import datasets
from datasets.tasks import ImageClassification
_BASE_URL = "http://123.57.42.89/Dataset_ict/ISIA_Food500_Dir/dataset/ISIA_Food500.zip"
_METADATA_URL = "http://123.57.42.89/Dataset_ict/ISIA_Food500_Dir/dataset/metadata_ISIAFood_500.zip"
_HOMEPAGE = "http://123.57.42.89/FoodComputing-Dataset/ISIA-Food500.html"
_DESCRIPTION = "ABCDescription"
_CITATION = "ABCCitation"
_LICENSE = "ABCLicense"
_NAMES = [
'Abalone',
'Aburaage',
'Æbleflæsk',
'Agedashi_tofu',
'Aligot',
'Almond_biscuit',
'Aloo_gobi',
'Ambrosia_(fruit_salad)',
'Anago',
'Andong_jjimdak',
'Ants_climbing_a_tree',
'Anzac_biscuit',
'Apple_cobbler',
'Apple_crisp',
'Apple_dumpling',
'Apple_pie',
'Apple_sauce',
'Apple_strudel',
'Applesauce_cake',
'Arab_salad',
'Arancini',
'Arròs_negre',
'Asam_pedas',
'Avocado_bread',
'Avocado_fries',
'Avocado_key_lime_pie',
'Avocado_sauce',
'Avocado_toast',
'Ayam_bakar',
'Ayam_betutu',
'Ayam_goreng',
'Babi_panggang',
'Bacon_and_eggs',
'Bacon_egg_and_cheese_sandwich',
'Bacon_explosion',
'Bacon_sandwich',
'Baingan_bharta',
'Baked_beans',
'Banana_bread',
'Banana_pancakes',
'Banana_pudding',
'Banana_salad',
'Banana_split',
'Bandeja_paisa',
'Bangers_and_mash',
'Banh_bo',
'Bánh_canh',
'Bánh_chuối',
'Bean_pie',
'Bean_salad',
'Beef_bun',
'Beef_chow_fun',
'Beef_noodle_soup',
'Beef_Wellington',
'Beignet',
'Bibimbap',
'Bibingka',
'Biryani',
'Bisque_food',
'Bistek',
'Black_Forest_gateau',
'Black_pepper_crab',
'Blackberry_pie',
'Blancmange',
'BLT_sandwich',
'Blueberry_pie',
'Boiled_beef',
'Boiled_peanuts',
'Bon_bon_chicken',
'Borscht',
'Botan-ebi',
'Botifarra',
'Bouillabaisse',
'Bourbon_chicken',
'Bread_roll',
'Broccoli_slaw',
'Brown_stew_chicken',
'Bruschetta',
'Bubur_ayam',
'Bubur_kacang_hijau',
'Bugnes',
'Bun_bo_hue',
'Bún_ốc',
'Bún_riêu',
'Burrito',
'Butadon',
'Butter_cake',
'Butter_pecan',
'Butter_pie',
'Buttercream',
'Buttery_bread',
'Cabbage_soup',
'Caesar_salad',
'Café_liégeois',
'Calamari',
'Caldo_verde',
'Caprese_salad',
'Carpaccio',
'Carrot_bread',
'Carrot_cake',
'Carrot_cake_cookie',
'Carrot_chips',
'Carrot_juice',
'Carrot_salad',
'Carrot_soup',
'Cassoulet',
'Cebolada',
'Ceviche',
'Chakli',
'Champurrado',
'Char_kway_teow',
'Charqui',
'Chazuke',
'Cheese_and_tomato_sandwich',
'Cheese_bun',
'Cheese_fries',
'Cheese_maki',
'Cheese_pudding',
'Cheese_roll',
'Cheesecake',
'Cherry_cake',
'Cherry_ice_cream',
'Cherry_pie',
'Chicken_and_waffles',
'Chicken_cacciatore',
'Chicken_curry',
'Chicken_fingers',
'Chicken_Kiev',
'Chicken_marsala',
'Chicken_noodle_soup',
'Chicken_nugget',
'Chicken_parmigiana',
'Chicken_salad',
'Chicken_soup',
'Chiles_en_nogada',
'Chili_con_carne',
'Chilli_crab',
'Chinese_chicken_salad',
'Chocolate_covered_strawberries',
'Chocolate_marshmallow_pie',
'Chow_mein',
'Chowder',
'Christmas_cake',
'Churro',
'Ciambelle',
'Çiğ_köfte',
'Clam_chowder',
'Claypot_chicken_rice',
'Club_sandwich',
'Cobbler_food',
'Coconut_cake',
'Coconut_cream',
'Coconut_shrimp',
'Coda_alla_vaccinara',
'Coffee_jelly',
'Colcannon',
'Coleslaw',
'Congee',
'Corn_chip',
'Corn_crab_soup',
'Corn_dog',
'Corn_soup',
'Corn_stew',
'Corn_tortilla',
'Corned_beef_sandwich',
'Cotoletta',
'Crab_cake',
'Crab_dip',
'Crab_in_Padang_sauce',
'Crab_puff',
'Crab_rangoon',
'Cream_of_broccoli_soup',
'Cream_of_mushroom_soup',
'Cream_pie',
'Creamed_eggs_on_toast',
'Croissant',
'Crudo',
'Crumble',
'Cucumber_soup',
'Cured_salmon',
'Curry_goat',
'Curry_Mee',
'Curry_rice',
'Currywurst',
'Dandan_noodles',
'Deep-fried_peanuts',
'Denver_omelette',
'Denver_sandwich',
'Dhokla',
'Di_san_xian',
'Dinuguan',
'Dirty_Rice',
'Dong\'an_chicken',
'Doufunao',
'Doughnut',
'Drunken_chicken',
'Drunken_shrimp',
'Duck_soup_noodles',
'Edamame',
'Eggplant_omelette',
'Eisbein',
'Es_campur',
'Es_pisang_ijo',
'Filet_mignon',
'Fish_ball',
'Fish_chowder',
'Fish_head_casserole',
'Fish_head_curry',
'Fish_soup',
'Fish_steak',
'Fishcake',
'Fondue',
'Francesinha',
'Frappe',
'French_onion_soup',
'French_toast',
'Fricassee',
'Fried_aubergine',
'Fried_cheese',
'Fried_chicken',
'Fried_noodles',
'Fried_onion',
'Fried_rice',
'Fried_Tofu',
'Fruit_curd',
'Fuqi_feipian',
'Galbi',
'Garlic_bread',
'Gejang',
'Ginger_beef',
'Gołąbki',
'Goulash',
'Gravlax',
'Greek_salad',
'Green_bean_casserole',
'Green_papaya_salad',
'Grits',
'Gulai_Ayam',
'Gyutan',
'Hae_mee',
'Hainanese_chicken_rice',
'Ham_and_cheese_sandwich',
'Ham_salad',
'Ham_sandwich',
'hamburgers',
'Har_gow',
'Hiyayakko',
'Hokkien_mee',
'Hongshao_rou',
'Hoppin\'_John',
'Hot_and_sour_soup',
'Huangqiao_sesame_cake',
'Huevos_rancheros',
'Hummus',
'Ikan_bakar',
'Ikan_goreng',
'Israeli_salad',
'Italian_tomato_pie',
'Jajangmyeon',
'Jambalaya',
'Jambonneau',
'Japchae',
'Jewish_apple_cake',
'Jiuniang',
'Kachori',
'Kadhi',
'Kakuni',
'Katsudon',
'kebab',
'Kedgeree',
'Key_lime_pie',
'Konnyaku',
'Korean_fried_chicken',
'Kung_Pao_chicken',
'Kwetiau_goreng',
'Laddu',
'Laksa',
'Lamb_chop',
'Lasagna',
'Lebkuchen',
'Leek_soup',
'Lemon_chicken',
'Lemon_ice_box_pie',
'Lemon_meringue_pie',
'Lemon_tart',
'Lemonade',
'Lentil_soup',
'Lettuce_soup',
'Lo_mein',
'Lobster_bisque',
'Lohikeitto',
'Macaron',
'Mango_pomelo_sago',
'Mango_pudding',
'Mapo_doufu',
'Meatloaf',
'Mee_pok',
'Mee_siam',
'Melt_sandwich',
'Menudo',
'Mì_Quảng',
'Michigan_hot_dog',
'Mie_goreng',
'Milk_Shake',
'Minestrone',
'Mirchi_ka_salan',
'Mission_burrito',
'Mongolian_beef',
'Mousse',
'Mozzarella_sticks',
'Mushroom_gravy',
'Mushy_peas',
'Mutton_handi',
'Mutton_korma',
'Nachos',
'Naengmyeon',
'Nasi_goreng',
'Nasi_kuning',
'Nasi_liwet',
'Nattō',
'Noodle_soup',
'Nuomici',
'Okinawa_soba',
'Olivier_salad',
'Onigiri',
'Onion_ring',
'Orange_chicken',
'Oyster_omelette',
'Oysters_Rockefeller',
'Pączki',
'Paella',
'Pakora',
'Panzanella',
'Pappa_al_pomodoro',
'Parmigiana',
'Pasta',
'Pasta_al_pomodoro',
'Pasta_alla_Norma',
'Pasteis_de_Bacalhau',
'Paupiette',
'Payasam',
'Pea_soup',
'Peanut_butter_cookie',
'Peanut_soup',
'Pho',
'Pickled_cucumber',
'Pig\'s_ear',
'Pig\'s_organ_soup',
'Pig\'s_trotters',
'Pineapple_tart',
'Pipikaula',
'Pizza_carbonara',
'Pizza_pugliese',
'Plateau_de_fruits_de_mer',
'Plum_cake',
'Pommes_dauphine',
'Poori',
'Porchetta',
'Pork_ball',
'Pork_blood_soup',
'Pork_knuckle',
'Pork_Knuckles_and_Ginger_Stew',
'Pork_ribs',
'Pork_tenderloin',
'Pork_tenderloin_sandwich',
'Pot_roast',
'Potato_salad',
'Poutine',
'Prawn_cocktail',
'Prawn_soup',
'Princess_cake',
'Profiterole',
'Pudding_corn',
'Pulled_pork',
'Pumpkin_bread',
'Pumpkin_pie',
'Quesadilla',
'Queso_flameado',
'Quiche_Lorraine',
'Rack_of_lamb',
'Raita',
'Ramen',
'Red_bean_cake',
'Red_bean_ice',
'Red_beans_and_rice',
'Red_slaw',
'Refried_beans',
'Rendang',
'Rice_and_peas',
'Rice_ball',
'Rice_cakes',
'Rice_pudding',
'Rogan_josh',
'Rou_jia_mo',
'Rouladen',
'Salmon_pie',
'Sambar',
'Samgyetang',
'Samosa',
'Sapo_tahu',
'Sardine',
'Sashimi',
'Sauerbraten',
'Sausage_and_peppers',
'Sausage_bun',
'Sausage_roll',
'Sausage_sandwich',
'Sauteed_mushrooms',
'Scampi',
'Schweinshaxe',
'Seafood_boil',
'Seafood_pizza',
'Sesame_chicken',
'Shaker_Lemon_Pie',
'Shanghai_fried_noodles',
'She-crab_soup',
'Sheep\'s_trotters',
'Shrimp_ball',
'Shrimp_toast',
'Shuizhu',
'Sicilian_orange_salad',
'Sliced_fish_soup',
'Smoked_salmon',
'Soba',
'Soft-shell_crab',
'Sopa_de_Mandioca',
'Soused_herring',
'Spanish_rice',
'Spatzle',
'Spiced_beef',
'Spinach_salad',
'Spinach_soup',
'Squash_soup',
'Steak_tartare',
'Steamed_clams',
'Steamed_meatball',
'Steamed_rice',
'Stew_peas',
'Stinky_tofu',
'Stir-fried_tomato_and_scrambled_eggs',
'Strawberry_cake',
'Strawberry_cheesecake',
'Strawberry_ice_cream',
'Strawberry_jam',
'Strawberry_pie',
'Strawberry_sundae',
'Strawberry_tart',
'Stuffed_avocado',
'Stuffed_eggplant',
'Stuffed_mushrooms',
'Stuffed_peppers',
'Stuffed_tomatoes',
'Suanmeitang',
'Succotash',
'Suckling_pig',
'Svíčková',
'Sweet_potato_pie',
'Sweet_saffron_rice',
'Syrniki',
'Tabbouleh',
'Tacos',
'Tafelspitz',
'Takoyaki',
'Taro_dumpling',
'Tinga_dish',
'Tiramisu',
'Toad_in_the_hole',
'Tobiko',
'Tomato_and_egg_soup',
'Tomato_bredie',
'Tomato_omelette',
'Tomato_soup',
'Tonkatsu',
'Tonkotsu_ramen',
'Torta_caprese',
'Tostada',
'Tourtière',
'Tsukemono',
'Tuna_fish_sandwich',
'Tuna_salad',
'Turnip_cake',
'Twix',
'Unagi',
'Vegetarian_chili',
'Vichyssoise',
'Vindaloo',
'Vitello_tonnato',
'Wakame',
'Wenchang_chicken',
'White_boiled_shrimp',
'White_cut_chicken',
'Whitebait',
'Wonton_noodles',
'Wotou',
'Yeung_Chow_fried_rice',
'Youtiao',
'Yuxiangrousi',
'Zhajiangmian',
'Zongzi',
'Zurcher_Geschnetzeltes',
]
_IMAGES_DIR = "ISIA_Food500/images"
_TRAIN_TXT = "https://huggingface.co/datasets/yw26342/test/raw/main/train_feature.txt"
_VALID_TXT = "https://huggingface.co/datasets/yw26342/test/raw/main/val_feature.txt"
_TEST_TXT = "https://huggingface.co/datasets/yw26342/test/raw/main/test_feature.txt"
class Food500(datasets.GeneratorBasedBuilder):
"""Food-500 Images dataset."""
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"image": datasets.Image(),
"label": datasets.ClassLabel(names=_NAMES),
}
),
supervised_keys=("image", "label"),
homepage=_HOMEPAGE,
citation=_CITATION,
license=_LICENSE,
task_templates=[ImageClassification(image_column="image", label_column="label")],
)
def _split_generators(self, dl_manager):
archive_path = dl_manager.download(_BASE_URL)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"images": dl_manager.iter_archive(archive_path),
"metadata_path": _TRAIN_TXT,
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"images": dl_manager.iter_archive(archive_path),
"metadata_path": _VALID_TXT,
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"images": dl_manager.iter_archive(archive_path),
"metadata_path": _TEST_TXT,
},
),
]
def _generate_examples(self, images, metadata_path):
"""Generate images and labels for splits."""
with open(metadata_path, encoding="utf-8") as f:
files_to_keep = set(f.read().split("\n"))
for file_path, file_obj in images:
if file_path.startswith(_IMAGES_DIR):
if file_path[len(_IMAGES_DIR) : -len(".jpg")] in files_to_keep:
label = file_path.split("/")[2]
yield file_path, {
"image": {"path": file_path, "bytes": file_obj.read()},
"label": label,
}